Here’s your first quantum circuit—a Bell state. It uses superposition and entanglement to calculate. (And here’s how to make one yourself.) Tap and drag the tiles around to get a feel for the Q editor. It’s easy to use on both desktop and mobile devices. Made a mistake? Just tap the Undo button.
Live probability results
Edit the code above and watch the probability results update in realtime.
Free and open-source
What does coding a quantum circuit look like? Let’s recreate the above Bell state using three separate circuit authoring styles to demonstrate Q’s flexibility. For each of the three examples we’ll create a circuit that uses 2 qubit registers for 2 moments of time. We’ll place a Hadamard gate at moment 1 on register 1. Then we’ll place a Controlled-Not gate at moment 2, with its control component on register 1 and its target component on register 2.
1. Text as input
Q’s text-as-input feature directly converts your text into a functioning quantum circuit. Just type your operations out as if creating a text-only circuit diagram (using “I” for identity gates in the spots where no operations occur) and enclose your text block in backticks (instead of quotation marks). Note that parentheses are not required to invoke the function call when using backticks.
Q` H X#0 I X#1 `
Folks coming to Q from Python-based quantum suites
may find this syntax more familiar.
Q function expects
the number of qubit registers to use,
followed by the number of moments to use.
each single-letter quantum gate label is also a function name.
For these functions
the first argument is a moment index
and the second is a qubit register index or array of qubit register indices.
Q( 2, 2 ) .h( 1, 1 ) .x( 2, [ 1, 2 ])
3. Verbose for clarity
Under the hood, Q is making more verbose declarations. You can also make direct declarations like so. (And what are those dollar signs about?)
new Q.Circuit( 2, 2 ) .set$( Q.Gate.HADAMARD, 1, 1 ) .set$( Q.Gate.PAULI_X, 2, [ 1, 2 ])
There are many ways to build a quantum circuit with Q. What feels right for you? To learn more about Q’s text syntax and other convenience tricks, see “Writing quantum circuits.”
Clear, legible output
Whether you use Q’s drag-and-drop circuit editor interface, text syntax, Python-inspired syntax, or prefer to type out every set$ command yourself, Q makes inspecting and evaluating your circuits easy.
Let’s add two commands which could directly follow any of the three examples above. Hey—deciding what to name a circuit can sometimes be difficult, so we’ll let Q choose a random name for us. Then we’ll generate an outcome probabilities report. Just add the following two lines to any of the above examples:
.setName$( Q.getRandomName$ ) .evaluate$()
And that combination will yield something like the following:
Beginning evaluation for “Example” m1 m2 ┌───┐╭─────╮ r1 |0⟩─┤ H ├┤ X#0 │ └───┘╰──┬──╯ ╭──┴──╮ r2 |0⟩───○──┤ X#1 │ ╰─────╯ ██████████░░░░░░░░░░ 50% 1 of 2 ████████████████████ 100% 2 of 2 Evaluation completed for “Example” with these results: 1 |00⟩ ██████████░░░░░░░░░░ 50% chance 2 |01⟩ ░░░░░░░░░░░░░░░░░░░░ 0% chance 3 |10⟩ ░░░░░░░░░░░░░░░░░░░░ 0% chance 4 |11⟩ ██████████░░░░░░░░░░ 50% chance
Option Command K
Control Shift K
Option Command J
Control Shift I
Option Command J
Option Command C
Q`H`.try$() ? 'tails' : 'heads'
Did you try it?
You just performed a quantum coin flip!
Each time you run the above code
there’s a 50% chance of landing on
and a 50% chance of landing on
Try it a few more times to see how random it feels.
to recall the last command you entered without having to type it or paste it again.)
When you’re ready for more,
“Writing quantum circuits”
a quick read.
Import and export
Q plays well with everyone. Export your circuits as plain text, ASCII diagrams, interactive graphic-user-interfaces, LaTeX code, and more! Visit the Q playground to experiment with converting circuits between various formats. As always, new features are in the works. Join our project on GitHub and help us build bridges to everywhere.