QiskitOCaml wrapper for the IBM Qiskit quantum computing toolkit.
Quantum circuits are built by piping a qcircuit through gate and circuit manipulation functions, and then executed on a backend such as aer_simulator or a real IBM quantum computer through IBMRuntime:
let qc = quantum_circuit 2 2 |> h 0 |> cx 0 1 |> measure 0 0 |> measure 1 1 in
aer_simulator "statevector" |> run qc |> result |> get_counts
|> Visualization.plot_histogramEvery value is a thin wrapper around the corresponding qiskit Python object (through pyml), so unwrapped features remain accessible with the Py module.
val quantum_circuit : int -> int -> qcircuitquantum_circuit nq nc creates a new circuit with nq qubits and nc classical bits.
val from_qasm_str : string -> qcircuitfrom_qasm_str s creates a circuit from an OpenQASM 2 string.
val from_qasm_file : string -> qcircuitfrom_qasm_file f creates a circuit from an OpenQASM 2 file.
val depth : qcircuit -> intdepth qc returns the depth of the circuit.
val size : qcircuit -> intsize qc returns the total number of instructions in the circuit.
val num_clbits : qcircuit -> intnum_clbits qc returns the number of classical bits.
val num_qubits : qcircuit -> intnum_qubits qc returns the number of qubits.
val global_phase : qcircuit -> floatglobal_phase qc returns the global phase of the circuit in radians.
measure n nto qc measures the qubit n into the classical bit nto.
measure_all qc measures every qubit into a new classical register.
measure_many nl ntol qc measures the qubits nl into the classical bits ntol.
initialize_from_int bm qc initializes the circuit state from the bitmap bm (e.g. 2 for |10>).
initialize_from_str lb qc initializes the circuit state from the label lb (e.g. "10" for |10>).
remove_final_measurements qc removes the final measurements (and the classical registers left unused) from the circuit.
barrier_many nl qc applies a barrier on the qubits nl.
p theta n qc applies a phase gate with angle theta on qubit n.
rx theta n qc applies a rotation around the X axis on qubit n.
ry theta n qc applies a rotation around the Y axis on qubit n.
rz theta n qc applies a rotation around the Z axis on qubit n.
u theta phi lam n qc applies a generic single-qubit rotation.
u3 theta phi lam n qc is u (the u3 gate was removed from qiskit).
u2 phi lam n qc applies u pi/2 phi lam n (the u2 gate was removed from qiskit).
crx theta nctl ntgt qc applies a controlled-RX gate.
cry theta nctl ntgt qc applies a controlled-RY gate.
crz theta nctl ntgt qc applies a controlled-RZ gate.
cp theta nctl ntgt qc applies a controlled phase gate.
cu theta phi lam gamma nctl ntgt qc applies a controlled-U gate.
ccx nctl1 nctl2 ntgt qc applies a Toffoli (CCX) gate.
cswap nctl n1 n2 qc applies a controlled-SWAP (Fredkin) gate.
module Qasm2 : sig ... endOpenQASM 2 serialization.
module Provider : sig ... endProvider and backend types.
module BasicProvider : sig ... endQiskit built-in, pure python simulator provider.
val aer_simulator : string -> Provider.backendaer_simulator meth creates an AerSimulator backend using the simulation method meth (e.g. "automatic", "statevector", "unitary").
module IBMProvider : sig ... endIBM quantum cloud access through the legacy qiskit_ibm_provider package.
module IBMRuntime : sig ... endIBM quantum cloud access through qiskit-ibm-runtime, the supported package for qiskit >= 1.0.
val run : qcircuit -> Provider.backend -> qjobrun qc sim runs the circuit on the backend and returns the job.
val transpile : qcircuit -> Provider.backend -> qjobtranspile qc sim transpiles the circuit for the backend.
val get_statevector : qres -> qstatevectorget_statevector res returns the final statevector.
get_unitary res qc returns the unitary matrix of the circuit.
module Visualization : sig ... endMatplotlib based visualization helpers; every function opens the plot in a matplotlib window.
module Quantum_info : sig ... endQuantum information utilities.