qdk_chemistry.plugins.qiskit._interop.transpiler module

Utilities for transpiling qiskit quantum circuits.

This module provides various custom transformation passes for optimizing circuits, including merging Z-basis rotations, substituting Clifford Rz gates, and removing Z-basis operations on qubits in the \(\lvert 0 \rangle\) state. It also includes functions to create custom pass managers based on preset configurations and custom passes.

class qdk_chemistry.plugins.qiskit._interop.transpiler.MergeZBasisRotations(*args, **kwargs)[source]

Bases: TransformationPass

Transformation pass to merge consecutive Z-basis rotations into a single Rz gate and remove identity gates.

This pass identifies sequences of single-qubit gates in the Z-basis, specifically Rz(θ), Z, S, and Sdg, and combines them into a single Rz(θ_new) operation whenever possible. These gates all correspond to rotations around the Z-axis of the Bloch sphere and can be represented in a unified form.

Gates:

  • Rz(θ): Arbitrary rotation by angle θ.

  • Z: Equivalent to Rz(π).

  • S: Equivalent to Rz(π/2).

  • Sdg: Equivalent to Rz(-π/2).

  • Id: Equivalent to Rz(0) (no effect, removed).

Behavior:

  • Does not merge across non-Z-basis gates (e.g., X, H, CX).

  • Removes Id gates entirely since they have no effect.

  • Respects circuit boundaries and barriers.

Example

Input sequence:

\(S \rightarrow R_z(π/3) \rightarrow S^\dagger \rightarrow Z\)

Output:

\(R_z(π/2 + π/3 - π/2 + π) = R_z(π + π/3)\)

Note

  • Useful for simplifying circuits before basis gate decomposition.

  • Reduces gate count and improves optimization opportunities downstream.

__init__()[source]

Use Optimize1qGatesDecomposition to handle gate optimization to merge Z basis rotations.

run(dag)[source]

Run the pass on the given DAGCircuit.

Return type:

DAGCircuit

Parameters:

dag (DAGCircuit) – The input DAGCircuit to transform.

Returns:

The transformed DAGCircuit with merged Z-basis rotations.

class qdk_chemistry.plugins.qiskit._interop.transpiler.RemoveZBasisOnZeroState(*args, **kwargs)[source]

Bases: TransformationPass

Transformation pass to remove Z-basis operations on qubits that are in the \(\lvert 0 \rangle\) state.

This optimization eliminates gates that apply only a global phase to the qubit, which has no effect on observable outcomes (measurement probabilities) or downstream quantum operations. Specifically, diagonal gates in the computational basis (e.g., Rz(θ), Z, S, Sdg) act trivially on the \(\lvert 0 \rangle\) state:

  • \(R_z(θ) \lvert 0 \rangle = e^{-iθ/2} \lvert 0 \rangle\)

  • \(Z \lvert 0 \rangle = +1 \lvert 0 \rangle\)

  • \(S \lvert 0 \rangle = +1 \lvert 0 \rangle\)

  • \(S^\dagger \lvert 0 \rangle = +1 \lvert 0 \rangle\)

These gates only introduce a global phase factor, which is physically unobservable.

This transformation must not be applied to qubits in superposition or entangled states, since Z-basis rotations there modify relative phases between basis states.

__init__()[source]

Initialize the RemoveZBasisOnZeroState transformation pass.

run(dag)[source]

Run the pass on the given DAGCircuit.

Return type:

DAGCircuit

Parameters:

dag (DAGCircuit) – The input DAGCircuit to transform.

Returns:

The transformed DAGCircuit with Z-basis gates removed.

class qdk_chemistry.plugins.qiskit._interop.transpiler.SubstituteCliffordRz(equivalent_gate_set=None, tolerance=2.220446049250313e-16)[source]

Bases: TransformationPass

Transformation pass to substitute Rz(θ) gates with equivalent Clifford gates for special angles.

This pass replaces Rz(θ) gates with one of the following Clifford gates:

  • Identity (Id)

  • Phase gate (S)

  • Inverse Phase gate (Sdg)

  • Pauli-Z (Z)

Substitution rules:

Rz angle (θ)

Equivalent Clifford gate

0

Id

π/2

S

π

Z

-π/2 or 3π/2

Sdg

Note

  • Only substitutes gates whose angle is non-parameterized and matches one of the above special Clifford phases within the specified tolerance.

  • Leaves parameterized Rz gates untouched to preserve symbolic expressions.

  • Ignores gates not in the user-specified equivalent_gate_set

__init__(equivalent_gate_set=None, tolerance=float(np.finfo(np.float64).eps))[source]

Initialize the SubstituteCliffordRz transformation pass.

Parameters:
  • equivalent_gate_set (list[str] | None) – List of gates to substitute rz with special angles. Default is None, which means [‘id’, ‘s’, ‘sdg’, ‘z’].

  • tolerance (float) – Angle comparison tolerance. Default is np.finfo(np.float64).eps.

run(dag)[source]

Run the pass on the given DAGCircuit.

Return type:

DAGCircuit

Parameters:

dag (DAGCircuit) – The input DAGCircuit to transform.

Returns:

The transformed DAGCircuit with Rz substitutions.

settings()[source]

Get the settings for SubstituteCliffordRz.

Return type:

Settings

Returns:

The settings object associated with SubstituteCliffordRz.