Skip to main content

Module resynthesis

Module resynthesis 

Source
Expand description

Numeric block resynthesis transforms.

This module optimizes already-lowered standard-gate circuits by collecting fixed-parameter one- and two-qubit operations over the same qubit pair, rebuilding their exact 4x4 unitary, and resynthesizing that unitary with the configured two-qubit basis. Maximal uninterrupted pair runs are collected in one linear pass without a size budget. A bounded dependency collector then supplements them with candidates that require legal commutation crossing. A candidate is accepted only when its local cost is strictly lower and every crossed operation still commutes with the synthesized replacement.

The pass is intentionally conservative:

  • symbolic parameters, non-standard gates, measurements, resets, delays, labels, directives, and control-flow instructions are collection boundaries;
  • supplemental commutation-aware collection is bounded by max_scan_span, max_block_ops, and max_crossed_ops;
  • control-flow bodies are optimized recursively, with body-local synthesis phase emitted as a leading GPhase.

§Example

use cqlib_core::circuit::{Circuit, Qubit};
use cqlib_core::circuit::{Instruction, StandardGate};
use cqlib_core::compile::transform::{
    ResynthesizeTwoQubitBlocks, TransformOutcome, TwoQubitBlockResynthesisConfig, Transformer,
};
use cqlib_core::compile::transform::decompose::unitary::TwoQubitSynthesisTarget;

let q0 = Qubit::new(0);
let q1 = Qubit::new(1);
let mut circuit = Circuit::new(2);
circuit.cx(q0, q1)?;
circuit.cx(q0, q1)?;

let target = TwoQubitSynthesisTarget::from_instructions(Some(&[
    Instruction::Standard(StandardGate::U),
    Instruction::Standard(StandardGate::CX),
]))?;
let config = TwoQubitBlockResynthesisConfig::normal(target);
let result = ResynthesizeTwoQubitBlocks::new(config).transform(&circuit, None)?;
let TransformOutcome::Changed(resynthesized) = result else {
    panic!("the cancelling block should be resynthesized");
};
assert!(resynthesized.operations().is_empty());

Structs§

ResynthesizeTwoQubitBlocks
Transformer that numerically resynthesizes fixed standard-gate two-qubit blocks.
TwoQubitBlockResynthesisConfig
Configuration for ordinary standard-gate two-qubit block resynthesis.

Enums§

DeviceResynthesisPlacement
Interpretation of circuit qubits for device-aware two-qubit resynthesis.

Functions§

resynthesize_two_qubit_blocks
Runs numeric two-qubit block resynthesis on circuit.
resynthesize_two_qubit_blocks_for_device
Runs one device-aware numeric resynthesis pass on circuit.