Module Qiskit

OCaml 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_histogram

Every value is a thin wrapper around the corresponding qiskit Python object (through pyml), so unwrapped features remain accessible with the Py module.

val np : Py.Object.t
val qk : Py.Object.t
val qk_vis : Py.Object.t
val qk_qinfo : Py.Object.t
val plt : Py.Object.t
type qcircuit = Py.Object.t

A quantum circuit (wraps qiskit QuantumCircuit).

val quantum_circuit : int -> int -> qcircuit

quantum_circuit nq nc creates a new circuit with nq qubits and nc classical bits.

val from_qasm_str : string -> qcircuit

from_qasm_str s creates a circuit from an OpenQASM 2 string.

val from_qasm_file : string -> qcircuit

from_qasm_file f creates a circuit from an OpenQASM 2 file.

val depth : qcircuit -> int

depth qc returns the depth of the circuit.

val size : qcircuit -> int

size qc returns the total number of instructions in the circuit.

val num_clbits : qcircuit -> int

num_clbits qc returns the number of classical bits.

val num_qubits : qcircuit -> int

num_qubits qc returns the number of qubits.

val global_phase : qcircuit -> float

global_phase qc returns the global phase of the circuit in radians.

val copy : qcircuit -> qcircuit

copy qc returns a copy of the circuit.

val reset : int -> qcircuit -> qcircuit

reset q qc resets the qubit q to the |0> state.

val measure : int -> int -> qcircuit -> qcircuit

measure n nto qc measures the qubit n into the classical bit nto.

val measure_all : qcircuit -> qcircuit

measure_all qc measures every qubit into a new classical register.

val measure_many : int list -> int list -> qcircuit -> qcircuit

measure_many nl ntol qc measures the qubits nl into the classical bits ntol.

val initialize_from_int : int -> qcircuit -> qcircuit

initialize_from_int bm qc initializes the circuit state from the bitmap bm (e.g. 2 for |10>).

val initialize_from_str : string -> qcircuit -> qcircuit

initialize_from_str lb qc initializes the circuit state from the label lb (e.g. "10" for |10>).

val qk_aer : Py.Object.t lazy_t
val save_state : qcircuit -> qcircuit

save_state qc saves the simulator state (requires qiskit_aer).

val remove_final_measurements : qcircuit -> qcircuit

remove_final_measurements qc removes the final measurements (and the classical registers left unused) from the circuit.

val barrier : qcircuit -> qcircuit

barrier qc applies a barrier on all qubits.

val barrier_many : int list -> qcircuit -> qcircuit

barrier_many nl qc applies a barrier on the qubits nl.

val draw : qcircuit -> qcircuit

draw qc shows the circuit using the matplotlib drawer.

val ag_p3 : string -> float -> float -> float -> int -> qcircuit -> qcircuit
val ag_p2 : string -> float -> float -> int -> qcircuit -> qcircuit
val ag_p1 : string -> float -> int -> qcircuit -> qcircuit
val ag : string -> int -> qcircuit -> qcircuit
val ag2 : string -> int -> int -> qcircuit -> qcircuit
val ag2_p1 : string -> float -> int -> int -> qcircuit -> qcircuit
val ag2_p2 : string -> float -> float -> int -> int -> qcircuit -> qcircuit
val ag2_p4 : string -> float -> float -> float -> float -> int -> int -> qcircuit -> qcircuit
val ag3 : string -> int -> int -> int -> qcircuit -> qcircuit
val h : int -> qcircuit -> qcircuit

h n qc applies an Hadamard gate on qubit n.

val x : int -> qcircuit -> qcircuit

x n qc applies a Pauli-X (NOT) gate on qubit n.

val y : int -> qcircuit -> qcircuit

y n qc applies a Pauli-Y gate on qubit n.

val z : int -> qcircuit -> qcircuit

z n qc applies a Pauli-Z gate on qubit n.

val s : int -> qcircuit -> qcircuit

s n qc applies an S gate (sqrt(Z)) on qubit n.

val sdg : int -> qcircuit -> qcircuit

sdg n qc applies an S-dagger gate on qubit n.

val t : int -> qcircuit -> qcircuit

t n qc applies a T gate on qubit n.

val tdg : int -> qcircuit -> qcircuit

tdg n qc applies a T-dagger gate on qubit n.

val id : int -> qcircuit -> qcircuit

id n qc applies an identity gate on qubit n.

val p : float -> int -> qcircuit -> qcircuit

p theta n qc applies a phase gate with angle theta on qubit n.

val rx : float -> int -> qcircuit -> qcircuit

rx theta n qc applies a rotation around the X axis on qubit n.

val ry : float -> int -> qcircuit -> qcircuit

ry theta n qc applies a rotation around the Y axis on qubit n.

val rz : float -> int -> qcircuit -> qcircuit

rz theta n qc applies a rotation around the Z axis on qubit n.

val u : float -> float -> float -> int -> qcircuit -> qcircuit

u theta phi lam n qc applies a generic single-qubit rotation.

val u3 : float -> float -> float -> int -> qcircuit -> qcircuit

u3 theta phi lam n qc is u (the u3 gate was removed from qiskit).

val u2 : float -> float -> int -> qcircuit -> qcircuit

u2 phi lam n qc applies u pi/2 phi lam n (the u2 gate was removed from qiskit).

val crx : float -> int -> int -> qcircuit -> qcircuit

crx theta nctl ntgt qc applies a controlled-RX gate.

val cry : float -> int -> int -> qcircuit -> qcircuit

cry theta nctl ntgt qc applies a controlled-RY gate.

val crz : float -> int -> int -> qcircuit -> qcircuit

crz theta nctl ntgt qc applies a controlled-RZ gate.

val cp : float -> int -> int -> qcircuit -> qcircuit

cp theta nctl ntgt qc applies a controlled phase gate.

val cu : float -> float -> float -> float -> int -> int -> qcircuit -> qcircuit

cu theta phi lam gamma nctl ntgt qc applies a controlled-U gate.

val cx : int -> int -> qcircuit -> qcircuit

cx nctl ntgt qc applies a controlled-X (CNOT) gate.

val cy : int -> int -> qcircuit -> qcircuit

cy nctl ntgt qc applies a controlled-Y gate.

val cz : int -> int -> qcircuit -> qcircuit

cz nctl ntgt qc applies a controlled-Z gate.

val ch : int -> int -> qcircuit -> qcircuit

ch nctl ntgt qc applies a controlled-Hadamard gate.

val swap : int -> int -> qcircuit -> qcircuit

swap n1 n2 qc applies a SWAP gate.

val ccx : int -> int -> int -> qcircuit -> qcircuit

ccx nctl1 nctl2 ntgt qc applies a Toffoli (CCX) gate.

val toffoli : int -> int -> int -> qcircuit -> qcircuit

Alias of ccx.

val cswap : int -> int -> int -> qcircuit -> qcircuit

cswap nctl n1 n2 qc applies a controlled-SWAP (Fredkin) gate.

type qjob = Py.Object.t

An execution job.

type qres = Py.Object.t

The result of an execution job.

type qcounts = Py.Object.t

Measurement counts.

type qstatevector = Py.Object.t

A statevector.

type qunitary = Py.Object.t

A unitary matrix.

module Qasm2 : sig ... end

OpenQASM 2 serialization.

module Provider : sig ... end

Provider and backend types.

module BasicProvider : sig ... end

Qiskit built-in, pure python simulator provider.

val aer_simulator : string -> Provider.backend

aer_simulator meth creates an AerSimulator backend using the simulation method meth (e.g. "automatic", "statevector", "unitary").

module IBMProvider : sig ... end

IBM quantum cloud access through the legacy qiskit_ibm_provider package.

module IBMRuntime : sig ... end

IBM quantum cloud access through qiskit-ibm-runtime, the supported package for qiskit >= 1.0.

run qc sim runs the circuit on the backend and returns the job.

val transpile : qcircuit -> Provider.backend -> qjob

transpile qc sim transpiles the circuit for the backend.

val result : qjob -> qres

result j waits for the job to complete and returns its result.

val get_statevector : qres -> qstatevector

get_statevector res returns the final statevector.

val get_counts : qres -> qcounts

get_counts res returns the measurement counts.

val get_unitary : qres -> qcircuit -> qunitary

get_unitary res qc returns the unitary matrix of the circuit.

module Visualization : sig ... end

Matplotlib based visualization helpers; every function opens the plot in a matplotlib window.

module Quantum_info : sig ... end

Quantum information utilities.