Quantum Circuit JavaScript API
An API for displaying quantum circuits.
Method
|
Description
|
---|---|
.h(...targets) | Put an H gate on each target qubit. |
.x(...targets) | Put an X gate on each target qubit. |
.y(...targets) | Put a Y gate on each target qubit. |
.z(...targets) | Put a Z gate on each target qubit. |
.phase(phi, ...targets) | Put a Phase Shift gate on each target qubit. |
.rnot(...targets) | Put a √X gate on each target qubit. |
.rx(theta, ...targets) | Put an Rx gate on each target qubit. |
.ry(theta, ...targets) | Put an Ry gate on each target qubit. |
.rz(theta, ...targets) | Put an Rz gate on each target qubit. |
.control(...targets) | Put a Control gate on each target qubit. |
.cnot(control, target) | Put a Controlled-X gate. |
.ccnot(controlA, controlB, target) | Put a Controlled-controlled-X (Toffoli) gate. |
.swap(targetA, targetB) | Put Swap gates on targetA and targetB qubit. |
.bloch(...targets) | Put a Bloch Display on each target qubit. |
.write(value, ...targets) | Put a Write gate with value 0 or 1 on each target qubit. |
.measure(...targets) | Put a Measurement gate on each target qubit. |
.block(comment, (block) => { ... }) | Define a commented code block. |
Usage
The <quantum-circuit>
component is a custom web component for displaying a quantum circuit.
The API allows you to place various quantum gates and operations on the circuit.
Quantum Circuit API
<quantum-circuit id="quantum-circuit"></quantum-circuit>
<script>
window.addEventListener('DOMContentLoaded', () => {
circuit = document.getElementById("quantum-circuit")
circuit.write("0", 0, 1)
.h(0)
.cnot(0, 1)
.measure(0)
.measure(1)
})
</script>