Skip to main content

State compression

Haiqu.state_compression(circuit: QuantumCircuit | CircuitModel, compression_level: str = ‘balanced’, noise_profile: str = ‘default’, fine_tuning: str = ‘low’, approximation_level: int | None = None) → StateCompressionJobModel

Compress an arbitrary quantum circuit. Haiqu’s state compression is an approximate fixed-input-state compilation method to extend the effective depth of circuits that can be executed on noisy hardware. It features several tunable parameters to adjust the trade-off between compression level and circuit quality, allowing the user to tailor the compression to the circuit and device noise characteristics. Both the input and output circuits are assumed to be applied to the all-zero state (|00⋯0⟩). The action of the circuit on other input states is not preserved by the compression.
  • Parameters:
    • circuit (QuantumCircuit | CircuitModel) — The quantum circuit to be compressed.
    • compression_level (str) — The qualitative compression level. Three options are available:
      • “low”: best used for shallow input circuits or very low noise levels
      • “balanced” (default): gives the best performance for most circuits and noise profiles
      • “high”: may sometimes yield better results for very deep circuits
    • noise_profile (str) — The device noise profile to assume during compression. The currently available options are: “ibm_eagle_r3”, “ibm_heron_r1”, “ibm_heron_r2” (default), “ibm_heron_r3”, “iqm_garnet” and “iqm_emerald”.
    • fine_tuning (str) — The extent to which classical resources should be used to further improve the compressed circuit. Three options are available:
      • “disabled”: no fine-tuning is performed, yielding the lowest latency
      • “low” (default): best balance between speed and accuracy
      • “heavy”: improved circuit accuracy, but time-intensive
    • approximation_level (int | None) — A small integer related to circuit complexity. Larger values improve the noiseless quality metric, but may degrade noisy performance. Defaults to None, which corresponds to auto-selection using the chosen noise_profile.
  • Returns: The State Compression job that will generate the compressed circuit.
  • Return type: StateCompressionJobModel

Examples

Generate a circuit:
>>> from qiskit.circuit.random import random_circuit
>>> c = random_circuit(num_qubits=50, depth=5, max_operands=4, seed=2025, measure=False)
>>> circuit = haiqu.log(c)
>>> circuit.wait_for_analytics()
>>> print(f"{circuit.analytics.gates_2q} two-qubit gates in the original circuit")
296 two-qubit gates in the original circuit
Submit a State Compression job to shrink it:
>>> job = haiqu.state_compression(circuit)
>>> circuit_comp, quality = job.result()
>>> print(f"Circuit is compressed with quality {quality:.6f}")
Circuit is compressed with quality 0.898719
Submit an Analytics job to confirm that the compressed circuit has far fewer two-qubit gates:
>>> circuit_comp.compute_analytics()
>>> circuit_comp.wait_for_analytics()
>>> print(f"{circuit_comp.analytics.gates_2q} two-qubit gates in the compressed circuit")
95 two-qubit gates in the compressed circuit

Observable backpropagation

Haiqu.observable_backpropagation(circuit: QuantumCircuit | CircuitModel, observables: SparsePauliOp | list[SparsePauliOp], max_qwc_groups: int | None = 50, max_error_total: float | None = 0.05, max_error_per_slice: float | None = 0.005, log: bool = True) → tuple[list[QuantumCircuit] | list[CircuitModel], list[SparsePauliOp]]

Optimize the observables for a circuit with observable backpropagation. This method wraps the Qiskit Operator Backpropagation (OBP) functionality to preprocess your circuits and observables for efficient execution.
  • Parameters:
    • circuit (QuantumCircuit | CircuitModel) — The quantum circuit to optimize.
    • observables (SparsePauliOp | list *(*SparsePauliOp )) — The observable(s) to optimize. Can be a single SparsePauliOp or list of SparsePauliOp. The order of Pauli terms follows the Qiskit reversed-order convention.
    • max_qwc_groups (int) — Maximum number of qubit-wise commuting groups to create. Defaults to 50. Treat with caution as increasing this value may lead to SIGNIFICANTLY higher computational costs!
    • max_error_total (float) — Maximum error allowed for the entire circuit. Defaults to 0.05.
    • max_error_per_slice (float) — Maximum error allowed per slice of the circuit. Defaults to 0.005.
    • log (bool) — If True (default), logs the reduced circuits to the Haiqu cloud.
  • Returns: A list of reduced circuits and a list of backpropagated observables.
  • Return type: tuple[list, list]

Examples

>>> from qiskit import QuantumCircuit
>>> from qiskit.quantum_info import SparsePauliOp
>>> qc = QuantumCircuit(2)
>>> qc.h(0)
>>> qc.cx(0, 1)
>>> obs = [SparsePauliOp("ZZ"), SparsePauliOp("XX")]
>>> optimized_circuits, optimized_obs = haiqu.observable_backpropagation(circuit=qc, observables=obs, log=False)
>>> [len(qc) for qc in optimized_circuits]
[0, 0]
>>> optimized_obs
[SparsePauliOp(['ZI'],
               coeffs=[1.+0.j]),
 SparsePauliOp(['IZ'],
               coeffs=[1.+0.j])]