spin_pulse.transpilation.utils¶
Utility functions to interact with circuits.
Functions¶
|
Translate a Qiskit gate (RX, RY, RZ, or RZZ) into hardware-compatible |
|
Compute the total unitary evolution operator for a quantum system governed by |
|
Reverse Qiskit's bit-ordering convention in a matrix representation. |
|
Convert a Qiskit quantum circuit into a Quimb MPS circuit. |
|
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
rzzinteraction 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,rzzanddelay.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:
- Raises:
ValueError – If the gate type is not supported.
Notes
- For
rzzgates: 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
delaygates: A single IdleInstruction is wrapped in a PulseSequence.
- For single-qubit rotations:
The corresponding rotation generator in
hardware_specsis 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 ann-qubit operator.- Returns:
- A matrix of the same shape as
matwith reversed bit-ordering applied to both row and column indices.
- A matrix of the same shape as
- 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
QuantumCircuitis translated into a constant gate applied to aCircuitMPS. For multi-qubit gates, the gate matrix is first reordered usingdeshuffle_qiskitto match Quimb’s qubit ordering convention.- Parameters:
circuit (qiskit.QuantumCircuit) – The input
qiskit.QuantumCircuitto convert.- Returns:
- A
quimb.tensor.circuit.CircuitMPSrepresenting the same sequence of operations as the input circuit.
- A
- Return type:
quimb.tensor.CircuitMPS
Notes
- This function assumes that each instruction in
circuit.dataprovides a matrix representation via
ins.matrixand qubit operands viains.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:
pulse_circuit (spin_pulse.transpilation.pulse_circuit.PulseCircuit) – Pulse-level circuit to evaluate.
quimb_circ_ideal (quimb.tensor.CircuitMPS) – Ideal reference CircuitMPS circuit.
- Returns:
The state fidelity as a float in $[0, 1]$.
- Return type: