Skip to content

Interop

qsimlab.interop

Conversions to and from Qiskit, Cirq and Stim.

Every converter imports its framework lazily and raises MissingDependencyError with an install hint if it is missing. Qubit i of the source maps to qsimlab qubit i (Qiskit: the circuit's qubit order; Cirq: sorted(circuit.all_qubits()) unless qubit_order is given; Stim: qubit index). Global phases are kept.

Note on Cirq: Cirq's state vectors are big-endian (first qubit most significant) while qsimlab's are little-endian, so the same circuit gives bit-reversed state-vector indices; gates and samples per qubit agree.

from_qasm

from_qasm(source: str) -> Circuit

Same as Circuit.from_qasm (OpenQASM 2.0).

to_qasm

to_qasm(circuit: Circuit) -> str

Same as Circuit.to_qasm (OpenQASM 2.0).

from_qiskit

from_qiskit(qc: Any, *, transpile: bool = True) -> Circuit

Converts a qiskit.QuantumCircuit.

The circuit is first transpiled (optimization_level=0, no coupling map, so no qubit relabelling) to the engine's native basis, then exchanged as OpenQASM 2; the global phase is carried over. Parameters must be bound. Measurements become records in program order (measurement k = column k of SamplesResult, whatever classical bit Qiskit wrote).

to_qiskit

to_qiskit(circuit: Circuit) -> Any

Converts to a qiskit.QuantumCircuit (via OpenQASM 2, global phase kept).

Conditionals and noise channels have no OpenQASM 2 form and raise UnsupportedOperationError.

from_cirq

from_cirq(
    circuit: Any,
    *,
    qubit_order: Optional[Sequence[Any]] = None,
) -> Circuit

Converts a cirq.Circuit exactly (global phase included).

Standard gates map directly; other unitary operations are decomposed by Cirq, with single-qubit pieces synthesised exactly as u gates and the global phase corrected against cirq.unitary. Measurements, resets, bit/phase-flip and depolarizing channels and simple classical controls (one single-qubit measurement key, condition "== 1") are supported. Symbols must be resolved.

to_cirq

to_cirq(circuit: Circuit) -> Any

Converts to a cirq.Circuit on cirq.LineQubit(0..n-1).

Measurement k gets key "m{k}"; c_if=(k, 1) becomes a classical control on "m{k}" (c_if=(k, 0) raises); the global phase becomes a global-phase operation.

from_stim

from_stim(circuit: Any) -> Circuit

Converts a stim.Circuit (or Stim source text): Clifford gates, measurements, resets, Pauli noise, M(p) readout error, detectors and observables; REPEAT blocks are unrolled.

to_stim

to_stim(circuit: Circuit) -> Any

Converts to a stim.Circuit (Clifford + Pauli-noise subset). Use Circuit.to_stim for the text without needing stim installed.