spin_pulse.transpilation.utils

Utility functions to interact with circuits.

Functions

gate_to_pulse_sequences(gate, hardware_specs)

Translate a Qiskit gate (RX, RY, RZ, or RZZ) into hardware-compatible

propagate(H, coeff)

Compute the total unitary evolution operator for a quantum system governed by

deshuffle_qiskit(mat)

Reverse Qiskit's bit-ordering convention in a matrix representation.

qiskit_to_quimb(circuit)

Convert a Qiskit quantum circuit into a Quimb MPS circuit.

my_quimb_fidelity(pulse_circuit, quimb_circ_ideal)

Compute the state fidelity against an ideal Quimb reference circuit.

Module Contents

spin_pulse.transpilation.utils.gate_to_pulse_sequences(gate, hardware_specs)[source]

Translate a Qiskit gate (RX, RY, RZ, or RZZ) into hardware-compatible pulse sequences.

This function maps high-level Qiskit rotation gates into low-level pulse instructions that follow the hardware specifications. Single-qubit rotations generate a single PulseSequence, while the rzz interaction generate two qubit sequence followed by a single qubit sequence on each qubit.

Parameters:
  • gate (CircuitInstruction) – The Qiskit instruction to translate. Supported operations are rx, ry, rz, rzz and delay.

  • hardware_specs (HardwareSpecs) – Hardware configuration including available fields, ramp durations, and rotation generation routines.

Returns:

A pair of lists: * one-qubit pulse sequences generated from the gate, * two-qubit pulse sequences (only for rzz).

Return type:

tuple[list[PulseSequence], list[PulseSequence]]

Raises:

ValueError – If the gate type is not supported.

Notes

For rzz gates:
  • A central Heisenberg pulse is generated.

  • Pre/post idle ramps are added to ensure smooth pulse shaping.

  • Each qubit receives a compensating detuned Z rotation of equal duration.

For delay gates:

A single IdleInstruction is wrapped in a PulseSequence.

For single-qubit rotations:

The corresponding rotation generator in hardware_specs is invoked.

spin_pulse.transpilation.utils.propagate(H, coeff)[source]

Compute the total unitary evolution operator for a quantum system governed by a time-dependent Hamiltonian, expressed as a linear combination of basis Hamiltonians.

Parameters:
  • H (np.ndarray) – array containing the Hamiltonian matrices [H1, H2, …, Hn], each of shape (d, d).

  • coeff (np.ndarray) – array of time-dependent coefficients for each Hamiltonian. coeff[j, i] is the coefficient for Hamiltonian H[j, :, :] at time step i.

Returns:

The final unitary matrix U of shape (d, d) representing the total time evolution.

Return type:

np.ndarray

Raises:

ValueError – If the number of Hamiltonians does not coincide with the number of time-dependent coefficient lists given or if the number of coefficients per Hamiltonian is not always the same.

spin_pulse.transpilation.utils.deshuffle_qiskit(mat)[source]

Reverse Qiskit’s bit-ordering convention in a matrix representation.

This function permutes the rows and columns of a square matrix by reversing the binary representation of their indices. It is typically used when converting multi-qubit operators between Qiskit and libraries that follow a different qubit-index (endianness) convention, such as Quimb.

Parameters:

mat (numpy.typing.NDArray[numpy.complexfloating]) – A square matrix of shape (2**n, 2**n) representing an n-qubit operator.

Returns:

A matrix of the same shape as mat with reversed bit-ordering applied

to both row and column indices.

Return type:

numpy.typing.NDArray[numpy.complexfloating]

spin_pulse.transpilation.utils.qiskit_to_quimb(circuit)[source]

Convert a Qiskit quantum circuit into a Quimb MPS circuit.

Each instruction of the input QuantumCircuit is translated into a constant gate applied to a CircuitMPS. For multi-qubit gates, the gate matrix is first reordered using deshuffle_qiskit to match Quimb’s qubit ordering convention.

Parameters:

circuit (qiskit.QuantumCircuit) – The input qiskit.QuantumCircuit to convert.

Returns:

A quimb.tensor.circuit.CircuitMPS representing the same sequence of

operations as the input circuit.

Return type:

quimb.tensor.CircuitMPS

Notes

This function assumes that each instruction in circuit.data provides

a matrix representation via ins.matrix and qubit operands via ins.qubits.

spin_pulse.transpilation.utils.my_quimb_fidelity(pulse_circuit, quimb_circ_ideal)[source]

Compute the state fidelity against an ideal Quimb reference circuit.

The input pulse_circuit is converted to a qiskit.QuantumCircuit via pulse_circuit.to_circuit(), then translated to a CircuitMPS using qiskit_to_quimb. The fidelity is computed as

\[F = \left| \langle \psi_{\mathrm{ideal}} \mid \psi \rangle \right|^2\]
Parameters:
Returns:

The state fidelity as a float in $[0, 1]$.

Return type:

float