Transpilation Functions

Rivet Transpiler functions.

rivet_transpiler.transpiler.get_full_map(transpiled_circuit, verbose=False)

Get the final allocation of virtual qubits in a transpiled quantum circuit.

Parameters:
  • transpiled_circuit (QuantumCircuit) – The transpiled quantum circuit.

  • verbose (bool) – Whether to print the full map calculation stages.

Returns:

The full map of qubits.

Return type:

list

rivet_transpiler.transpiler.transpile(circuit, backend=None, **key_arguments)

Transpile a quantum circuit with optional stack-specific optimizations.

Parameters: - circuit (QuantumCircuit): The quantum circuit to be transpiled. - backend (BaseBackend, optional): The target backend for execution. - key_arguments: Additional key arguments to be passed to qiskit transpilation.

Stack: - stack (str): The selected stack (‘qiskit’, ‘qiskit_qsearch’,

‘qiskit_qfactor_qsearch’, ‘qiskit_pytket’)

Pass Manager: - pass_manager: Custom pass manager for transpilation.

Dynamical Decoupling Arguments: - dd_pulses: Dynamical decoupling pulses. - dd_pulses_count: Number of dynamical decoupling pulses. - dd_pulse_alignment: Alignment of dynamical decoupling pulses. - dynamical_decoupling: Enable or disable dynamical decoupling.

Return Options: - return_options (bool): If True, returns a tuple (transpiled_circuit, options).

If False (default), only the transpiled circuit is returned.

Returns: - QuantumCircuit: Transpiled quantum circuit.

Note: If ‘pass_manager’ is provided, it takes precedence over ‘stack’.

rivet_transpiler.transpiler.transpile_chain(circuits, backend=None, **key_arguments)

Transpile a chain of quantum circuits one-by-one.

Parameters:
  • circuits (list of QuantumCircuit) – List of input quantum circuits.

  • backend – The target backend for transpilation.

  • **key_arguments – Additional keyword arguments for transpilation.

Returns:

The transpiled chain circuit.

Return type:

QuantumCircuit

rivet_transpiler.transpiler.transpile_left(central_circuit, left_circuit, backend=None, **key_arguments)

Transpile a left quantum circuit and combine it with already transpiled central circuit.

Parameters:
  • central_circuit (QuantumCircuit) – The central quantum circuit.

  • left_circuit (QuantumCircuit) – The left quantum circuit to transpile and add.

  • backend – The target backend for transpilation.

  • **key_arguments – Additional keyword arguments for transpilation.

Returns:

The resulting quantum circuit.

Return type:

QuantumCircuit

rivet_transpiler.transpiler.transpile_right(central_circuit, right_circuit, backend=None, **key_arguments)

Transpile a right quantum circuit and combine it with already transpiled central circuit.

Parameters:
  • central_circuit (QuantumCircuit) – The central quantum circuit.

  • right_circuit (QuantumCircuit) – The right quantum circuit to transpile and add.

  • backend – The target backend for transpilation.

  • **key_arguments – Additional keyword arguments for transpilation.

Returns:

The resulting quantum circuit.

Return type:

QuantumCircuit

Dynamical Decoupling Functions

Dynamical Decoupling (DD) is a form of quantum error mitigation that aims to protect quantum information from the influence of external factors such as environmental noise and imperfect control of quantum gates.

The basic idea behind dynamical decoupling is to apply a series of carefully chosen control pulses or gates at specific intervals during the evolution of a quantum system.

These control pulses are designed to reverse or “decouple” the system from the undesired influences of noise and errors, effectively preserving the quantum state over time.

rivet_transpiler.dynamical_decoupling.add_dynamical_decoupling(circuit, backend, dd_pulses=None, dd_pulses_count=None, dd_pulse_alignment=None)

Apply Dynamical Decoupling (DD) to a quantum circuit.

Parameters:
  • circuit (QuantumCircuit) – The input quantum circuit to which DD will be applied.

  • backend (Backend) – The quantum device or simulator to which the circuit is targeted.

  • dd_pulses (list of Gate, optional) – The DD pulse gates to use. Default is a single XGate.

  • dd_pulses_count (int, optional) – The number of times to repeat the DD pulse sequence. Default is 2.

  • dd_pulse_alignment (bool, optional) – Whether to use pulse alignment for DD sequences. If not specified, it will attempt to use the backend’s pulse alignment configuration.

Returns:

The quantum circuit with Dynamical Decoupling applied.

Return type:

QuantumCircuit

Service Functions

Service Functions used for Rivet Transpiler examples and checks.

rivet_transpiler.functions.get_circuit_hash(circuit, decomposition_level=None)

Calculate hash for Qiskit quantum circuit.

This function computes a SHA256 hash value that represents a given quantum circuit. It traverses circuit DAG, iterates over instructions, including the quantum operations and their parameters, and combines them to generate a hash value. Optionally, the traversal can be limited to a specified decomposition level. Hash is calculated only for “leaf” nodes, which can not be decomposed further. The resulting hash can be used to uniquely identify a specific circuit structure.

Following attributes are used to calculate hash for every operation: - qubit and bit indices, - operation name, - operation parameters.

Qiskit ParameterExpression values are skipped - circuits with different Parameters will have identical hash.

Inspired by Qiskit “soft_compare” gate function: https://github.com/Qiskit/qiskit/blob/main/qiskit/circuit/instruction.py#L227

Parameters: - circuit (QuantumCircuit): The quantum circuit for which to compute the hash. - decomposition_level (int, optional): Maximum level of decomposition for circuit instructions.

If “None” (default), the deepest decomposition is done.

Returns: - int: An integer representing the computed hash value.

Example: >>> my_circuit = QuantumCircuit(2) >>> my_circuit.h(0) >>> my_circuit.cx(0, 1) >>> hash_value = get_circuit_hash(my_circuit) >>> print(hash_value) “62559021281660068776592236282478300669138546894602824343710100835365445539986”

rivet_transpiler.functions.get_cnot_circuit(qubits_count, circuit_name=None, cnot_qubits=None, registers_count=1)

Create a CNOT test circuit.

Parameters:
  • qubits_count (int) – The total number of qubits in the circuit.

  • circuit_name (str, optional) – A name for the circuit.

  • cnot_qubits (list of int, optional) – The qubits involved in the CNOT gate.

  • registers_count (int, optional) – The number of quantum registers in the circuit.

Returns:

A CNOT test quantum circuit.

Return type:

QuantumCircuit

rivet_transpiler.functions.get_ibm_cost(qiskit_circuit, depth_penalty_factor=0.995, one_qubit_gate_fidelity=0.9996, two_qubit_gate_fidelity=0.99)

Calculate the IBM Cost for a Qiskit circuit.

IBM Cost definition: https://arxiv.org/abs/2008.08571 (1) Fidelities: https://arxiv.org/abs/2202.14025 (Table I) Fidelity Values: https://github.com/ArlineQ/arline_quantum/blob/master/arline_quantum/hardware/ibm.py

Parameters:
  • qiskit_circuit (QuantumCircuit) – The input Qiskit quantum circuit.

  • depth_penalty_factor (float, optional) – A factor for depth penalty.

  • one_qubit_gate_fidelity (float, optional) – Fidelity of one-qubit gates.

  • two_qubit_gate_fidelity (float, optional) – Fidelity of two-qubit gates.

Returns:

The calculated IBM Cost.

Return type:

float

rivet_transpiler.functions.get_litmus_circuit(qubits_count, circuit_name=None, registers_count=1)

Create a Litmus test circuit.

Parameters:
  • qubits_count (int) – The total number of qubits in the circuit.

  • circuit_name (str, optional) – A name for the circuit.

  • registers_count (int, optional) – The number of quantum registers in the circuit.

Returns:

A Litmus test quantum circuit.

Return type:

QuantumCircuit

rivet_transpiler.functions.get_sinusoids(qubits_count, frequencies_count=None, frequencies=None, amplitudes=None, min_amplitude=1, max_amplitude=3)

Generate sinusoidal waveforms for qubit operations.

Parameters:
  • qubits_count (int) – The total number of qubits.

  • frequencies_count (int, optional) – The number of different frequencies to use.

  • frequencies (array-like, optional) – Specific frequencies to use.

  • amplitudes (array-like, optional) – Specific amplitudes for each frequency.

  • min_amplitude (float, optional) – Minimum amplitude value.

  • max_amplitude (float, optional) – Maximum amplitude value.

Returns:

An array of normalized sinusoidal waveforms.

Return type:

array

Metrics

Functions for calculation of transpilation metrics.

rivet_transpiler.metrics.transpile_and_return_metrics(circuit, backend=None, **key_arguments)

Transpiles a given quantum circuit for a specified backend and collects metrics during the transpilation process.

This function transpiles the input quantum circuit to be optimized for a given backend, if specified, and utilizes a callback function to collect metrics about each pass during the transpilation process. These metrics include pass index, pass name, pass type (Analysis or Transformation), execution time, circuit depth and width, IBM cost estimation, and a gates counter.

Parameters: - circuit (QuantumCircuit): The quantum circuit to transpile. - backend (Backend, optional): The backend for which to optimize the transpilation. If None, a generic

optimization is performed without specific backend optimization.

  • **key_arguments: Additional keyword arguments to be passed to the transpile function.

Returns: - QuantumCircuit: The transpiled quantum circuit. - list: A list of dictionaries, with each dictionary containing metrics for a specific pass during the

transpilation process. Each dictionary includes the following keys: ‘pass_index’, ‘pass_name’, ‘pass_type’, ‘time’, ‘depth’, ‘width’, ‘ibm_cost’, and ‘gates_counter’.

The function internally defines a pass_callback closure that is invoked after each pass during transpilation, where it collects and appends the metrics for each pass to a list. The transpile function from Qiskit is then called with the provided arguments, along with the callback keyword argument set to the pass_callback function. Finally, the transpiled circuit and the list of collected metrics are returned.