GateCompiler

class GateCompiler(gateset, config=None)

Compile Qiskit circuits into a gate set’s native representation.

GateCompiler is the main user-facing entry point for gate-level compilation. It binds a target GateSet and a CompilerConfig, and compiles circuits with compile(). The configuration selects the compilation path: a SynthesisConfig subclass (AdaptiveConfig, TreeSearchConfig, ErrorAwareAdaptiveConfig, ErrorAwareTreeSearchConfig) synthesizes the circuit’s unitary with the quasarcpp backend, while a QiskitConfig compiles it through the Qiskit transpiler.

Parameters:
  • gateset (GateSet) – Target native gate set.

  • config (CompilerConfig | None) – Compilation configuration, given as a CompilerConfig subclass, or None for the default adaptive configuration. Use from_dict() to build a GateCompiler from a plain configuration dict instead.

Raises:
from qiskit import QuantumCircuit
import quasar

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)

compiler = quasar.GateCompiler(quasar.CROTGateSet(2))
native = compiler.compile(circuit)
error = compiler.compilation_error(circuit, native)

qiskit_compiler = quasar.GateCompiler(quasar.CROTGateSet(2), config=quasar.QiskitConfig())
native_via_qiskit = qiskit_compiler.compile(circuit)

Note

compile() and compilation_error() are the two calls most users need (see the example above). from_dict(), generate_topology(), load_qasm_circuit(), and build_pauli_readout_circuit() are lower-level supporting utilities – construction from a plain config dict, topology introspection, and a readout helper used for characterization rather than the main compile workflow.

Attributes

config

Active compilation configuration.

gateset

Target native gate set bound to this compiler.

Methods

compilation_error(circuit, compiled)

Return a compiled gate-level circuit's error against its source circuit.

compile(circuit[, initial_state])

Compile a Qiskit circuit into the target gate set's native operations.

compile_state(target_state[, initial_state])

Compile the circuit preparing a state on the device.

estimate_errors(target, compiled[, ...])

Estimate how far a compiled circuit sits from its target on hardware.

state_preparation_error(target_state, compiled)

Return the error of a compiled preparation against the state it should produce.

Low-level API methods

build_pauli_readout_circuit(pauli_readout[, ...])

Construct a gate-set-native readout circuit for a requested Pauli string.

from_dict(gateset, config_dict)

Construct a GateCompiler from a plain configuration dictionary.

generate_topology()

Return the connectivity edges of the target gate set.

load_qasm_circuit(source)

Load an OpenQASM 2 circuit with QUASAR native-gate extensions.