Science
vquantum
Simulates one and two qubit states and gates. There’s no hardware backend.
Released v1.0.0 · 2026-09-28use "stdlib/quantum.ven"
Simulates one and two qubit states and gates: zero states, single qubit gates, CNOT and measurement probabilities. There is no hardware backend.
state = apply_single_qubit_gate(zero_state(1), "X", 0)
print probability_of(state, 1)
Reference (12 functions)
API reference
complex_add(a, b)
Adds two complex numbers, given as (real, imag) Tuples.
complex_add((1.0, 2.0), (3.0, 4.0))complex_multiply(a, b)
Multiplies two complex numbers, given as (real, imag) Tuples.
complex_multiply((0.0, 1.0), (0.0, 1.0))complex_magnitude_squared(z)
Gives back the squared magnitude of a complex amplitude, its measurement probability.
complex_magnitude_squared((3.0, 4.0))num_qubits(state)
num_qubits([(1.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0)])zero_state(qubit_count)
zero_state(2)gate_matrix(gate_name)
gate_matrix("X")apply_single_qubit_gate(state, gate_name, target_qubit)
Applies a named single-qubit gate to one qubit of a state, giving back a new state.
apply_single_qubit_gate([(1.0, 0.0), (0.0, 0.0)], "X", 0)apply_cnot(state, control_qubit, target_qubit)
s10 = apply_single_qubit_gate(zero_state(2), "X", 0)
apply_cnot(s10, 0, 1)probability_of(state, basis_state_index)
Gives back the measurement probability of one basis state.
probability_of([(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (1.0, 0.0)], 3)measurement_probabilities(state)
Gives back the measurement probability of every basis state, in order.
measurement_probabilities([(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (1.0, 0.0)])measure(state)
Simulates one measurement of a state, giving back the collapsed basis state's index.
measure([(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (1.0, 0.0)])is_normalized(state, tolerance)
is_normalized([(1.0, 0.0), (0.0, 0.0)], 0.0000001)