{"id":13776590,"url":"https://github.com/redfx-quantum/strange","last_synced_at":"2025-04-06T02:38:36.102Z","repository":{"id":41541536,"uuid":"126854865","full_name":"redfx-quantum/strange","owner":"redfx-quantum","description":"Quantum Computing API for Java","archived":false,"fork":false,"pushed_at":"2023-10-10T10:54:15.000Z","size":735,"stargazers_count":192,"open_issues_count":7,"forks_count":47,"subscribers_count":27,"default_branch":"main","last_synced_at":"2024-02-15T09:34:40.066Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redfx-quantum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":null,"patreon":null,"open_collective":"johan-vos","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-03-26T16:06:29.000Z","updated_at":"2024-02-15T04:26:50.000Z","dependencies_parsed_at":"2024-01-13T11:57:52.227Z","dependency_job_id":"ed18abf9-47f7-493f-b88e-e228234d4876","html_url":"https://github.com/redfx-quantum/strange","commit_stats":null,"previous_names":["qcjava/strange"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redfx-quantum%2Fstrange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redfx-quantum%2Fstrange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redfx-quantum%2Fstrange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redfx-quantum%2Fstrange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redfx-quantum","download_url":"https://codeload.github.com/redfx-quantum/strange/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247426996,"owners_count":20937197,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:29.726Z","updated_at":"2025-04-06T02:38:36.072Z","avatar_url":"https://github.com/redfx-quantum.png","language":"Java","funding_links":["https://opencollective.com/johan-vos"],"categories":["Quantum simulators"],"sub_categories":[],"readme":"# strange\n[![Build](https://github.com/redfx-quantum/strange/actions/workflows/build.yml/badge.svg)](https://github.com/redfx-quantum/strange/actions/workflows/build.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/org.redfx/strange)](https://search.maven.org/#search|ga|1|org.redfx.strange)\n[![License](https://img.shields.io/github/license/redfx-quantum/strange)](https://opensource.org/licenses/GPL-3.0)\n[![javadoc](https://javadoc.io/badge2/org.redfx/strange/javadoc.svg)](https://javadoc.io/doc/org.redfx/strange)\n\n# Quantum Computing API and simulator for Java\n\nThis project defines a Java API that can be used to create Quantum Programs.\nA Quantum Program, defined by \u003ccode\u003eorg.redfx.strange.Program\u003c/code\u003e can be executed on an implementation of the \n\u003ccode\u003eorg.redfx.strange.QuantumExecutionEnvironment\u003c/code\u003e.\n\nYou can read more about Java and QuantumComputing in [Quantum Computing in Action](https://www.manning.com/books/quantum-computing-in-action?a_aid=quantumjava\u0026a_bid=e5166ab9)\n\u003ca href=\"https://www.manning.com/books/quantum-computing-for-java-developers?a_aid=quantumjava\u0026a_bid=e5166ab9\"\u003e\n![qcj](https://github.com/redfx-quantum/strange/assets/767876/324f682d-eaaf-4829-b411-4ab2abc104cc)\u003c/a\u003e\n\n# Getting Started\n\nStrange is distributed via Maven Central and can thus easily be used leveraging maven or gradle build software.\n\n## Using JBang\n\nJBang makes it easy to run simple Java applications without setup hassle.\n\nYou can download JBang from \u003ca href=\"https://jbang.dev\"\u003ejbang.dev\u003c/a\u003e.\n\nThe following code is a very simple Java application that is using Strange (and StrangeFX). Save this code in a\nfile named ShortStrangeDemo.java and execute it by typing the following command in a terminal:\n`jbang ShortStrangeDemo.java`\n\n```\n//DEPS org.redfx:strangefx:0.1.4\nimport org.redfx.strange.*;\nimport org.redfx.strange.gate.*;\nimport org.redfx.strange.local.SimpleQuantumExecutionEnvironment;\nimport org.redfx.strangefx.render.Renderer;\nimport java.util.Arrays;\n\npublic class ShortStrangeDemo {\n    public static void main(String[] args) {\nProgram p = new Program(2, new Step(new X(0)), new Step(new Hadamard(0), new X(1)));\n        SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment();\n        Qubit[] qubits = sqee.runProgram(p).getQubits();\n        Renderer.renderProgram(p);\n        Arrays.asList(qubits).forEach(q -\u003e System.out.println(\"qubit with probability on 1 = \"+q.getProbability()+\", measured it gives \"+ q.measure()));\n    }\n}\n```\n\nThe result of this is some output to the terminal, and a Window showing the Quantum Circuit you created:\n```\nqubit with probability on 1 = 0.4999999701976776, measured it gives 1\nqubit with probability on 1 = 0.9999999403953552, measured it gives 1\n\n```\n(note that the first qubit can be measured as `0` or as `1`)\n![demo output](assets/shortdemo.png)\n\n## Using maven\n\nA typical `pom.xml` file looks as follows:\n\n```maven\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n  xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\"\u003e\n  \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n  \u003cgroupId\u003eorg.redfx.javaqc\u003c/groupId\u003e\n  \u003cartifactId\u003esimplestrangedemo\u003c/artifactId\u003e\n  \u003cpackaging\u003ejar\u003c/packaging\u003e\n  \u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n  \u003cname\u003eSimpleStrangeDemo\u003c/name\u003e\n  \u003curl\u003ehttp://maven.apache.org\u003c/url\u003e\n\n  \u003cdependencies\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003eorg.redfx\u003c/groupId\u003e\n      \u003cartifactId\u003estrange\u003c/artifactId\u003e\n      \u003cversion\u003e0.1.1\u003c/version\u003e\n    \u003c/dependency\u003e\n  \u003c/dependencies\u003e\n  \u003cbuild\u003e \n    \u003cplugins\u003e\n      \u003cplugin\u003e\n        \u003cgroupId\u003eorg.openjfx\u003c/groupId\u003e\n        \u003cartifactId\u003ejavafx-maven-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e0.0.6\u003c/version\u003e\n        \u003cconfiguration\u003e\n          \u003cmainClass\u003eSimpleStrangeDemo\u003c/mainClass\u003e\n        \u003c/configuration\u003e\n      \u003c/plugin\u003e\n    \u003c/plugins\u003e\n  \u003c/build\u003e\n\u003c/project\u003e\n\n```\n\n## Using gradle\n\nA typical build.gradle file looks as follows:\n```gradle\nplugins {\n    id 'application'\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation 'org.redfx:strange:0.1.1'\n}\n\nmainClassName = 'SimpleStrangeDemo'\n\n```\n\n# About the sample application.\n\nThe code pasted above in the `ShortStrangeDemo` snippet is a short version of the code\nbelow. Both applications are similar, but the code below is more verbose which makes it\neasier to explain what is going on.\n\n```java\nimport org.redfx.strange.*;\nimport org.redfx.strange.gate.*;\nimport org.redfx.strange.local.SimpleQuantumExecutionEnvironment;\nimport java.util.Arrays;\n\npublic class SimpleStrangeDemo {\n\n    public static void main(String[] args) {\n        Program p = new Program(2);\n        Gate xGate1 = new X(0); \n        Step step1 = new Step();\n        step1.addGate(xGate1);\n        p.addStep(step1);\n        Gate hGate2 = new Hadamard(0);\n        Gate xGate2 = new X(1);\n        Step step2 = new Step();\n        step2.addGates(hGate2, xGate2);\n        p.addStep(step2);\n        SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment();\n        Result res = sqee.runProgram(p);\n        Qubit[] qubits = res.getQubits();\n        Arrays.asList(qubits).forEach(q -\u003e System.out.println(\"qubit with probability on 1 = \"+q.getProbability()+\", measured it gives \"+ q.measure()));\n    }\n\n}\n```\n\nThis sample create a \u003ccode\u003eProgram\u003c/code\u003e that requires 2 qubits. It will create 2 steps (\u003ccode\u003es\u003c/code\u003e and \u003ccode\u003et\u003c/code\u003e).\nThe first step adds a Paul-X (NOT) Gate to the first qubit. \nThe second steps adds a Hadamard Gate to the first qubit, and a NOT gate to the second qubit.\nBoth steps are added to the \u003ccode\u003eProgram\u003c/code\u003e.\n\nIn order to \"run\" this program, we need a \u003ccode\u003eQuantumExecutionEnvironment\u003c/code\u003e. Strange comes with a \n\u003ccode\u003eSimpleQuantumExecutionEnvironment\u003c/code\u003e which contains a very simple, non-optimized quantum computer simulator.\n\nAfter running the program on this simulator, we inspect the state of the Qubits. As expected, there is a 50% chance the first qubit (which had an X and an H gate) will be in the \u003ccode\u003e0\u003c/code\u003e state, and a 50% chance it will be in the \u003ccode\u003e1\u003c/code\u003e state. The second qubit will always be in the \u003ccode\u003e1\u003c/code\u003e state.\n\n\nRunning this application a number of times will consistently give the same probabilities, and different measurements.\n\n# Visualization\n\nThe Strange API's allow creating and simulate quantum programs. A companion project, [StrangeFX](https://github.com/redfx-quantum/strangefx) , allows visualising programs, and create them with a simple drag and drop interface. The sample program above rendered via StrangeFX looks as follows:\n![StrangeFX rendering](https://github.com/redfx-quantum/strangefx/blob/master/docs/images/simpleview.png)\n\n# More samples\nYou can find more samples at https://github.com/johanvos/quantumjava\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredfx-quantum%2Fstrange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredfx-quantum%2Fstrange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredfx-quantum%2Fstrange/lists"}