Skip to Content
New in v0.1.0 OpenQASM export: run fqkit circuits on real IBM hardware
DocumentationAPI Reference

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 of Qubit objects
  • .operations: ordered list of Operations
  • .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:

FunctionReturns
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.ndarray

Returns the final statevector (length 2**num_qubits, complex).

apply_gate(state, gate_matrix, num_qubits, target_qubits) -> np.ndarray

Low-level helper: applies one gate to a statevector by tensor contraction.

Measurement

measure_all(state_vector, shots=1024) -> dict

Samples 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) -> str

Serializes 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_job
  • providers(): the machines you can name, and whether that SDK is installed
  • backends(machine, live=False): the default device, or the live list when live=True
  • submit(circuit, machine, shots=1024, backend=None): send a job, return a HardwareJob
  • get_job(machine, job_id): reconnect to a job that is already running
  • job.status(): QUEUED, RUNNING, COMPLETED, CANCELLED, or FAILED
  • job.counts(): wait, then return bitstrings in FQkit order
  • job.cancel(): ask the vendor to cancel

The walkthrough is Hardware.

Other classses

  • Qubit(index): a stateless reference to a qubit by index
  • Operation(gate, target_qubits): a gate bound to specific qubits
Last updated on