Core logic for simulating Clifford+S+T quantum circuits.
Provides functions for constructing polynomial representations of circuits, evaluating polynomials, generating truth tables, and computing statevectors.
- PolyQ.engine.create_poly(qc, n: int)
Create the polynomial array representation of a quantum circuit.
- Parameters:
qc – QuantumCircuit object.
n (int) – Number of qubits.
- Returns:
(terms, wire_array, t) where terms is the polynomial, wire_array tracks variable names, and t is the total number of variables.
- Return type:
tuple
- PolyQ.engine.eval_f(terms, x, n)
Evaluate the polynomial equation.
- Parameters:
terms (list) – Polynomial terms.
x (np.ndarray) – Variable values.
n (int) – Number of qubits.
- Returns:
Evaluation result modulo 8.
- Return type:
np.int8
- PolyQ.engine.eval_f_no_ivs(terms, x, n)
Evaluate the polynomial equation without input variables.
- Parameters:
terms (list) – Polynomial terms.
x (np.ndarray) – Variable values.
n (int) – Number of qubits.
- Returns:
Evaluation result modulo 8.
- Return type:
np.int8
- PolyQ.engine.get_statevector(ttb, n, t, ovs, starting_index=0)
Compute the statevector from the truth table.
- Parameters:
ttb (np.ndarray) – Truth table values.
n (int) – Number of qubits.
t (int) – Total number of variables.
ovs (list) – Output variable indices.
starting_index (int, optional) – Starting index. Defaults to 0.
- Returns:
Statevector as a complex array.
- Return type:
np.ndarray
- PolyQ.engine.get_statevector_file(ttb, n, t, ovs, starting_index=0)
Compute the statevector and write amplitudes to a file.
- Parameters:
ttb (np.ndarray) – Truth table values.
n (int) – Number of qubits.
t (int) – Total number of variables.
ovs (list) – Output variable indices.
starting_index (int, optional) – Starting index. Defaults to 0.
- Returns:
Filename where the statevector is written.
- Return type:
str
- PolyQ.engine.get_truthtable(terms, n, t, initial_state)
Generate the truth table for the polynomial given an initial state.
- Parameters:
terms (list) – Polynomial terms.
n (int) – Number of qubits.
t (int) – Total number of variables.
initial_state (list) – Initial state of the qubits.
- Returns:
Truth table values.
- Return type:
np.ndarray
- PolyQ.engine.get_truthtable_no_ivs(terms, n, t, initial_state)
Generate the truth table, removing input variables from the polynomial.
- Parameters:
terms (list) – Polynomial terms.
n (int) – Number of qubits.
t (int) – Total number of variables.
initial_state (list) – Initial state of the qubits.
- Returns:
Truth table values.
- Return type:
np.ndarray
- PolyQ.simulation.simulate(qc: QuantumCircuit, initial_state: int | str | list[int] = 0)
Simulates a quantum circuit from a given initial state.
- Parameters:
qc (QuantumCircuit) – Quantum circuit to be simulated.
initial_state (int | str | list[int]) – Initial state of the qubits.
- Returns:
The resulting statevector.
- Return type:
list[complex]