Skip to main content

Input Initialization

The input() method prepares the initial quantum state before your algorithm runs. It accepts binary strings, Pauli strings, gate arrays, or a callback — and automatically skips ground states (0 or I) to keep QASM output clean.

Binary String

Each character maps to a qubit by position (big-endian by default):

Q.input("101"); // X on q[0], skip q[1], X on q[2]
Q.input("010"); // skip q[0], X on q[1], skip q[2]

Little-Endian

Q.input("101", { endian: 'little' }); // reversed: X on q[2], skip q[1], X on q[0]

Pauli String

Use Pauli labels directly. I (identity) and 0 are skipped:

Q.input("XXIZI"); // X on q[0], X on q[1], skip q[2], X on q[3], skip q[4]

Gate Array

Pass an explicit array of gate names or values:

Q.input(['X', 'H', 'S']); // X on q[0], H on q[1], S on q[2]
Q.input([1, 0, 1]); // same as binary "101"

Full Symbol Reference

SymbolGate AppliedNotes
1, X, xXBit flip / NOT
0, I, i, =(skip)Ground state, no gate emitted
+H|+⟩ state
-H, Z|-⟩ state
>, r, +iH, S|i⟩ state (right circular)
<, l, -iH, S†|-i⟩ state (left circular)
H, hHHadamard
S, sSPhase gate
Z, zZPauli-Z

Callback Form

For full control, pass a function:

Q.input(q => {
q.bit(0).h().s();
q.bit(1).x();
});

Example: QFT Input Prep

circuit({ qubits: 3 }, Q => {
Q.input([1, 0, 1]); // Initialize |101⟩
Q.barrier();
// ... QFT gates follow
});