qrunch.quantum.circuits.circuit_helpers

Helper functions for working with quantum circuits.

Functions

dump_circuit_statistics(circuit[, ...])

Compile a circuit and write pre- and post-compilation gate statistics as JSON.

dump_circuit_to_openqasm3(circuit[, output_path])

Compile a circuit to OpenQASM 3 and write it to an available file.

dump_circuit_statistics(circuit: Circuit, output_path: Path = PosixPath('circuit_statistics.json'), small_rotation_threshold: float = 0.3141592653589793) → Path

Compile a circuit and write pre- and post-compilation gate statistics as JSON.

A small rotation has a numeric angle whose absolute value is at most small_rotation_threshold. The Clifford count includes CX gates and rotations by integer multiples of \(\pi/2\). Non-Clifford rotations include all other rotations, including symbolic rotations. A T-equivalent rotation has an angle congruent to an odd multiple of \(\pi/4\) modulo \(\pi/2\).

Parameters:
  • circuit (Circuit) – Circuit to analyze.

  • output_path (Path) – Preferred JSON output path. A numerical suffix is added when the path already exists.

  • small_rotation_threshold (float) – Maximum absolute angle for a rotation to be considered small.

Returns:

Path to the written JSON statistics file.

Raises:

ValueError – If small_rotation_threshold is negative or non-finite.

Return type:

Path

dump_circuit_to_openqasm3(circuit: Circuit, output_path: Path = PosixPath('circuit.qasm')) → Path

Compile a circuit to OpenQASM 3 and write it to an available file.

Parameters:
  • circuit (Circuit) – Fully specified circuit to compile and export.

  • output_path (Path) – Preferred output path. A numerical suffix is added when the path already exists.

Raises:

ValueError – If the circuit is not fully specified.

Return type:

Path