Quantum Circuit JSON API

A JSON API for displaying quantum circuits.

JSON
Description
"|0>" (Re)set a qubit to state |0⟩
"|1>" (Re)set a qubit to state |1⟩
1 Identity gate
"H" Hadamard gate
"X" Pauli X gate (NOT gate)
"Y" Pauli Y gate
"Z" Pauli Z gate
"P" Phase shift gate
"P(φ)" Phase shift gate rotates by φ
"X^½" Square root of NOT gate
"Rx" Rx gate
"Rx(θ)" Rx gate rotates by θ
"Ry" Ry gate
"Ry(θ)" Ry gate rotates by θ
"Rz" Rz gate
"Rz(θ)" Rz gate rotates by θ
"Swap" Swap gate
"•" Control gate
"Bloch" Bloch sphere display
"Measure" Measurement gate
"{comment" Start a block with comment
"}" Finilize a block

Usage

The quantum circuit displayed by the <quantum-circuit> tag can also be embedded as JSON format data. The Qni quantum circuit JSON format is a representation of each step in the circuit as an array. For example, in a three-qubit circuit, the step to apply Hadamard gates to the first and the second qubit is represented as ["H","H",1]. By concatenating multiple steps defined in this way, an array defining the quantum circuit can be created. The Qni quantum circuit JSON format holds this array as the JSON key "cols" value.

Embedding JSON

<quantum-circuit data-json="{&quot;cols&quot;:[[&quot;|0>&quot;,&quot;|0>&quot;],[&quot;H&quot;,1],[&quot;•&quot;,&quot;X&quot;],[&quot;Measure&quot;,1],[1,&quot;Measure&quot;]]}"></quantum-circuit>

Set JSON with JavaScript

<quantum-circuit id="quantum-circuit"></quantum-circuit>

<script>
  document.getElementById("quantum-circuit")
          .setAttribute("data-json", '{"cols":[["|0>","|0>"],["H",1],["•","X"],["Measure",1],[1,"Measure"]]}')
</script>