QuantumCore
← QuantumCore

Python sandbox

Write and run Python directly in the browser. The interpreter is Pyodide (CPython compiled to WebAssembly), running in a Web Worker so a long computation never freezes the page; the first visit downloads about 9 MB (runtime, NumPy, autograd), later visits come from the browser cache.

Programs use qcore, a PennyLane-compatible shim on NumPy: import qcore as qml, then qml.device, @qml.qnode, gates such as qml.Hadamard and qml.CNOT, measurements qml.expval, qml.probs, qml.state, and gradients qml.grad computed with the exact parameter-shift rule

∂⟨H⟩∂θj=12[⟨H⟩θj+π2−⟨H⟩θj−π2].\frac{\partial\langle H\rangle}{\partial\theta_j}=\frac12\Big[\langle H\rangle_{\theta_j+\frac{\pi}{2}}-\langle H\rangle_{\theta_j-\frac{\pi}{2}}\Big].

A Qiskit-style API is available as from qcore.qiskit import QuantumCircuit, Statevector, execute_counts (Qiskit bit order: qubit 0 is the rightmost bit). qml.show(qnode) draws the circuit below the output. Variables persist between runs until you reset the session; a run is stopped after 15 s.

Loading the editor…