API Reference
Everything below is importable from the top level:
from fqkit import (
QuantumCircuit, Qubit, Parameter, Gate,
Hadamard, RX, RY, RZ, CNOT, CZ, SWAP, Toffoli,
bind_parameters, run, apply_gate, measure_all, to_qasm,
)QuantumCircuit
QuantumCircuit(num_qubits: int).num_qubits: number of qubits.qubits: list ofQubitobjects.operations: ordered list ofOperations.add_gate(gate, target_qubits): append a gate; validates targets.to_qasm(measure=True): export to an OpenQASM 2.0 string
Gates
Factories return a Gate:
| Function | Returns |
|---|---|
Hadamard() | 1-qubit H gate |
RX(theta) / RY(theta) / RZ(theta) | 1-qubit rotation |
CNOT() / CZ() / SWAP() | 2-qubit gate |
Toffoli() | 3-qubit gate |
Gate(name: str, num_qubits: int, matrix=None, params=None)Simulation
run(circuit) -> np.ndarrayReturns the final statevector (length 2**num_qubits, complex).
apply_gate(state, gate_matrix, num_qubits, target_qubits) -> np.ndarrayLow-level helper: applies one gate to a statevector by tensor contraction.
Measurement
measure_all(state_vector, shots=1024) -> dictSamples the statevector and returns a mapping of bitstring to count.
Parameters
Parameter(name: str)
bind_parameters(circuit, param_values: dict)OpenQASM
to_qasm(circuit, measure=True) -> strSerializes a circuit to OpenQASM 2.0. Raises ValueError for unbound
parameters or gates with no QASM equivalent.
Hardware jobs
Imported from fqkit.hardware, not from the top-level fqkit package:
from fqkit.hardware import providers, backends, submit, get_jobproviders(): the machines you can name, and whether that SDK is installedbackends(machine, live=False): the default device, or the live list whenlive=Truesubmit(circuit, machine, shots=1024, backend=None): send a job, return aHardwareJobget_job(machine, job_id): reconnect to a job that is already runningjob.status():QUEUED,RUNNING,COMPLETED,CANCELLED, orFAILEDjob.counts(): wait, then return bitstrings in FQkit orderjob.cancel(): ask the vendor to cancel
The walkthrough is Hardware.
Other classses
Qubit(index): a stateless reference to a qubit by indexOperation(gate, target_qubits): a gate bound to specific qubits
Last updated on