tangelo.linq.translator package

Submodules

tangelo.linq.translator.qdk_template module

This python module stores template Q# strings that can be used to have Q# code files ready to be shared with collaborators, submitted to a remote compute backend through Microsoft services or compiled by the local QDK simulator.

tangelo.linq.translator.translate_braket module

Functions helping with quantum circuit format conversion between abstract format and Braket format

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_braket.get_braket_gates()

Map gate name of the abstract format to the equivalent methods of the braket.circuits.Circuit class API and supported gates: https://amazon-braket-sdk-python.readthedocs.io/en/latest/_apidoc/braket.circuits.circuit.html

tangelo.linq.translator.translate_braket.translate_c_from_braket(source_circuit)

Take in a quantum circuit object as defined in the Python Braket SDK, return an abstract circuit.

Parameters:

source_circuit (braket.circuits.Circuit) – quantum circuit in Python Braket SDK format.

Returns:

Circuit – quantum circuit in the abstract format.

tangelo.linq.translator.translate_braket.translate_c_to_braket(source_circuit)

Take in an abstract circuit, return a quantum circuit object as defined in the Python Braket SDK.

Parameters:

source_circuit – quantum circuit in the abstract format.

Returns:

braket.circuits.Circuit – quantum circuit in Python Braket SDK format.

tangelo.linq.translator.translate_circuit module

Module to convert quantum circuits to different formats.

tangelo.linq.translator.translate_circuit.translate_circuit(circuit, target, source='tangelo', output_options=None)

Function to convert a quantum circuit defined within the “source” format to a “target” format.

Parameters:
  • circuit (source format) – Self-explanatory.

  • target (string) – Identifier for the target format.

  • source (string) – Identifier for the source format.

  • output_options (dict) – Backend specific options (e.g. a noise model, number of qubits, etc.).

Returns:

(circuit in target format) – Translated quantum circuit.

tangelo.linq.translator.translate_cirq module

Functions helping with quantum circuit format conversion between abstract format and circ format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_cirq.get_cirq_gates()

Map gate name of the abstract format to the equivalent methods of the cirq class API and supported gates: https://quantumai.google/cirq/gates.

tangelo.linq.translator.translate_cirq.translate_c_to_cirq(source_circuit, noise_model=None, save_measurements=False)

Take in an abstract circuit, return an equivalent cirq QuantumCircuit object.

Parameters:
  • source_circuit (Circuit) – quantum circuit in the abstract format.

  • noise_model (NoiseModel) – The noise model to use

  • save_measurements (bool) – If True, all measurements in the circuit are saved with the key ‘n’ for the nth measurement in the Circuit. If False, no measurements are saved.

Returns:

cirq.Circuit – a corresponding cirq Circuit. Right now, the structure is of LineQubit. It is possible in the future that we may support NamedQubit or GridQubit.

tangelo.linq.translator.translate_cirq.translate_op_from_cirq(qubit_operator)

Helper function to translate a cirq linear combination of Pauli strings to a Tangelo QubitOperator.

Parameters:

qubit_operator (cirq.ops.linear_combinations.PauliSum) – Self-explanatory.

Returns:

(tangelo.toolboxes.operators.QubitOperator) – Tangelo qubit operator.

tangelo.linq.translator.translate_cirq.translate_op_to_cirq(qubit_operator)

Helper function to translate a Tangelo QubitOperator to a cirq linear combination of Pauli strings.

Parameters:

qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

Returns:

(cirq.ops.linear_combinations.PauliSum) – Cirq summation of Pauli strings.

tangelo.linq.translator.translate_json_ionq module

Functions helping with quantum circuit format conversion between abstract format and ionq format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_json_ionq.get_ionq_gates()

Map gate name of the abstract format to the equivalent gate name used in the json IonQ format. For more information: - https://dewdrop.ionq.co/ - https://docs.ionq.co

tangelo.linq.translator.translate_json_ionq.translate_c_from_json_ionq(source_circuit)

Take in a dictionary following the IonQ JSON format as described below, return an equivalent Tangelo Circuit. https://dewdrop.ionq.co/#json-specification

Parameters:

source_circuit (dict) – representation of the quantum circuit following the IonQ JSON format.

Returns:

Circuit – the corresponding quantum Circuit in Tangelo format.

tangelo.linq.translator.translate_json_ionq.translate_c_to_json_ionq(source_circuit)

Take in an abstract circuit, return a dictionary following the IonQ JSON format as described below. https://dewdrop.ionq.co/#json-specification

Parameters:

source_circuit – quantum circuit in the abstract format.

Returns:

dict – representation of the quantum circuit following the IonQ JSON format.

tangelo.linq.translator.translate_openqasm module

Functions helping with quantum circuit format conversion between abstract format and a subset of the openqasm format (the format generated by IBM openqasm functionalities in qiskit).

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_openqasm.get_openqasm_gates()

Map gate name of the abstract format to the equivalent gate name used in OpenQASM. OpenQASM is a general format that allows users to express a quantum program, define conditional operations manipulating quantum and qubit registers, as well as defining new quantum unitaries. We however make the choice here to support well-known gate operations.

tangelo.linq.translator.translate_openqasm.translate_c_from_openqasm(openqasm_str)

Take an OpenQASM 2.0 string as input (as defined by IBM Qiskit), return the equivalent abstract circuit. Only a subset of OpenQASM supported, mostly to be able to go back and forth QASM and abstract representations to leverage tools and innovation implemented to work in the QASM format. Not designed to support elaborate QASM programs defining their own operations. Compatible with qiskit.QuantumCircuit.from_qasm method.

Assumes single-qubit measurement instructions only. Final qubit register measurement is implicit.

Parameters:

openqasm_string (str) – an OpenQASM program, as a string, as defined by IBM Qiskit.

Returns:

Circuit – corresponding quantum circuit in the abstract format.

tangelo.linq.translator.translate_openqasm.translate_c_to_openqasm(source_circuit)

Take in an abstract circuit, return a OpenQASM 2.0 string using IBM Qiskit (they are the reference for OpenQASM).

Parameters:

source_circuit – quantum circuit in the abstract format.

Returns:

str – the corresponding OpenQASM program, as per IBM Qiskit.

tangelo.linq.translator.translate_pennylane module

Functions helping with quantum circuit format conversion between abstract format and pennylane format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_pennylane.get_pennylane_gates()

Map gate name of the abstract format to the equivalent methods of the pennylane class API and supported gates:https://docs.pennylane.ai/en/stable/code/qml.html#classes.

tangelo.linq.translator.translate_pennylane.translate_c_to_pennylane(source_circuit)

Take in an tangelo Circuit, return an equivalent pennylane List[subclass of pennylane.operator.Operation].

Parameters:

source_circuit (Circuit) – quantum circuit in the abstract format.

Returns:

List[Type[pennylane.operator.Operation]] – corresponding list of objects from child classes of pennylane.operator.Operation.

tangelo.linq.translator.translate_pennylane.translate_op_from_pennylane(qubit_operator)

Helper function to translate pennylane Hamiltonian (only real coefficients) to a Tangelo QubitOperator.

Parameters:

qubit_operator (pennylane.ops.qubit.hamiltonian.Hamiltonian) – Self-explanatory.

Returns:

(tangelo.toolboxes.operators.QubitOperator) – Tangelo qubit operator.

tangelo.linq.translator.translate_pennylane.translate_op_to_pennylane(qubit_operator)

Helper function to translate a Tangelo QubitOperator to a pennylane Hamiltonian operator. For the pennylane package, all the coefficients must be real.

Parameters:

qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

Returns:

(pennylane.ops.qubit.hamiltonian.Hamiltonian) – Pennylane Hamiltonian.

tangelo.linq.translator.translate_projectq module

Functions helping with quantum circuit format conversion between abstract format and projectq format

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_projectq.get_projectq_gates()

Map gate name of the abstract format to the equivalent gate name used in projectq API and supported gates: https://projectq.readthedocs.io/en/latest/projectq.ops.html

tangelo.linq.translator.translate_projectq.translate_c_from_projectq(projectq_str)

Convenience function to help people move away from their ProjectQ workflow. Take ProjectQ instructions, expressed as a string, similar to one from the ProjectQ CommandPrinter engine. Will bundle all qubit allocation (resp. deallocation) at the beginning (resp. end) of the circuit. Example available in the examples folder.

Parameters:

projectq_str (str) – ProjectQ program, as a string (Allocate, Deallocate, gate operations…).

Returns:

Circuit – corresponding quantum circuit in the abstract format.

tangelo.linq.translator.translate_projectq.translate_c_to_projectq(source_circuit)

Take in an abstract circuit, return a string containing equivalent projectq instructions.

Parameters:

source_circuit – quantum circuit in the abstract format.

Returns:

str – the corresponding projectq instructions (allocation , gates, deallocation).

tangelo.linq.translator.translate_projectq.translate_op_from_projectq(qubit_operator)

Helper function to translate projectq qubit operator to a Tangelo QubitOperator.

Parameters:

qubit_operator (projectq.ops.QubitOperator) – Self-explanatory.

Returns:

(tangelo.toolboxes.operators.QubitOperator) – Tangelo qubit operator.

tangelo.linq.translator.translate_projectq.translate_op_to_projectq(qubit_operator)

Helper function to translate a Tangelo QubitOperator to a projectq qubit operator.

Parameters:

qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

Returns:

(projectq.ops.QubitOperator) – ProjectQ QubitOperator.

tangelo.linq.translator.translate_qdk module

Functions helping with quantum circuit format conversion between abstract format and qdk/qsharp format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_qdk.get_qdk_gates()

Map gate name of the abstract format to the equivalent gate name used in Q# operations API and supported gates: https://docs.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic

tangelo.linq.translator.translate_qdk.translate_c_to_qsharp(source_circuit, operation='MyQsharpOperation', save_measurements=False)

Take in an abstract circuit, generate the corresponding Q# operation (state prep + measurement) string, in the appropriate Q# template. The Q# output can be written to file and will be compiled at runtime.

Parameters:
  • source_circuit – quantum circuit in the abstract format.

  • operation (str) – name of the Q# operation.

  • save_measurements (bool) – True, return all mid-circuit measurement results. This returns a frequency vector that is of size 2^(n_meas+n_qubits). False, all measurements are overwritten.

Returns:

str – The Q# code (operation + template). This needs to be written into a .qs file, and compiled at runtime.

tangelo.linq.translator.translate_qiskit module

Functions helping with quantum circuit and operator format conversion between Tangelo format and qiskit format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

The module also enables bidirectional conversion between qiskit and Tangelo qubit operators (linear combination of Pauli operators)

tangelo.linq.translator.translate_qiskit.get_qiskit_gates()

Map gate name of the Tangelo format to the equivalent add_gate method of Qiskit’s QuantumCircuit class API and supported gates: https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.html

tangelo.linq.translator.translate_qiskit.translate_c_from_qiskit(source_circuit)

Take in a qiskit.QuantumCircuit, return an equivalent Tangelo Circuit

Parameters:

source_circuit (qiskit.QuantumCircuit) – quantum circuit in the qiskit.QuantumCircuit format.

Returns:

Circuit – the corresponding quantum Circuit in Tangelo format.

tangelo.linq.translator.translate_qiskit.translate_c_to_qiskit(source_circuit: Circuit, save_measurements=False, no_classical_register=False)

Take in a Circuit, return an equivalent qiskit.QuantumCircuit

Parameters:
  • source_circuit (Circuit) – quantum circuit in the abstract format.

  • save_measurements (bool) – Return mid-circuit measurements in the order they appear in the circuit in the classical registers

  • no_classical_register (bool) – do not create classical register in circuit (default: False)

Returns:

qiskit.QuantumCircuit – the corresponding qiskit.QuantumCircuit

tangelo.linq.translator.translate_qiskit.translate_op_from_qiskit(qubit_operator)

Helper function to translate a qiskit SparsePauliOp to a Tangelo QubitOperator.

Parameters:

qubit_operator (qiskit.quantum_info.operators.SparsePauliOp) – Self-explanatory.

Returns:

(tangelo.toolboxes.operators.QubitOperator) – Tangelo qubit operator.

tangelo.linq.translator.translate_qiskit.translate_op_to_qiskit(qubit_operator, n_qubits)

Helper function to translate a Tangelo QubitOperator to a qiskit SparsePauliOp. Qiskit must be installed for the function to work.

Parameters:
  • qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

  • n_qubits (int) – Number of qubits relevant to the operator.

Returns:

(qiskit.quantum_info.operators.SparsePauliOp) – Qiskit qubit operator.

tangelo.linq.translator.translate_qubitop module

Module to convert qubit operators to different formats.

tangelo.linq.translator.translate_qubitop.translate_operator(qubit_operator, source, target, n_qubits=None)

Function to convert a qubit operator defined within the “source” format to a “target” format.

Parameters:
  • qubit_operator (source format) – Self-explanatory.

  • source (string) – Identifier for the source format.

  • target (string) – Identifier for the target format.

  • n_qubits (int) – Number of qubits relevant to the operator. Not used by all format conversion functions, will be computed automatically if not specified.

Returns:

(operator in target format) – Translated qubit operator.

tangelo.linq.translator.translate_qulacs module

Functions helping with quantum circuit format conversion between abstract format and qulacs format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_qulacs.get_qulacs_gates()

Map gate name of the abstract format to the equivalent add_gate method of Qulacs’s QuantumCircuit class API and supported gates: http://qulacs.org/class_quantum_circuit.html

tangelo.linq.translator.translate_qulacs.translate_c_to_qulacs(source_circuit, noise_model=None, save_measurements=False)

Take in an abstract circuit, return an equivalent qulacs QuantumCircuit instance. If provided with a noise model, will add noisy gates at translation. Not very useful to look at, as qulacs does not provide much information about the noisy gates added when printing the “noisy circuit”.

Parameters:
  • source_circuit (Circuit) – quantum circuit in the abstract format.

  • noise_model (NoiseModel) – A NoiseModel object from this package, located in the noisy_simulation subpackage.

  • save_measurements (bool) – If True, each nth measurement in the circuit is saved in the nth classical register. Otherwise, each measurement overwrites the first classical register.

Returns:

qulacs.QuantumCircuit – the corresponding qulacs quantum circuit.

tangelo.linq.translator.translate_qulacs.translate_op_from_qulacs(qubit_operator)

Helper function to translate a qulacs general quantum operator to a Tangelo QubitOperator.

Parameters:

qubit_operator (qulacs_core.GeneralQuantumOperator) – Self-explanatory.

Returns:

(tangelo.toolboxes.operators.QubitOperator) – Tangelo qubit operator.

tangelo.linq.translator.translate_qulacs.translate_op_to_qulacs(qubit_operator)

Helper function to translate a Tangelo QubitOperator to a qulacs general quantum operator.

Parameters:

qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

Returns:

(qulacs_core.GeneralQuantumOperator) – Qulacs quantum operator.

tangelo.linq.translator.translate_stim module

Functions helping with quantum circuit and operator format conversion between Tangelo format and stim format.

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_stim.get_stim_gates()

Map gate name of the Tangelo format to the equivalent add_gate method of Stim’s CircuitInstruction class API and supported gates: https://github.com/quantumlib/Stim/blob/main/doc/gates.md

tangelo.linq.translator.translate_stim.translate_c_to_stim(source_circuit, noise_model=None)

Take in an abstract circuit, return an equivalent stim QuantumCircuit instance. If provided with a noise model, will add noisy gates at translation.

Parameters:
  • source_circuit (Circuit) – quantum circuit in the abstract format.

  • noise_model (NoiseModel) – The noise model to use.

Returns:

stim.Circuit – the corresponding stim quantum circuit.

tangelo.linq.translator.translate_stim.translate_tableau(source_circuit)

Take in an abstract circuit and build it directly into a stim TableauSimulator instance. For noiseless expectations values, this method is faster than translating into a stim circuit object first and then building it into the stim TableauSimulator.

Parameters:

source_circuit (Circuit) – quantum circuit in the abstract format.

Returns:

stim.TableauSimulator – the corresponding Tableau Simulator

tangelo.linq.translator.translate_sympy module

Functions helping with quantum circuit format conversion between abstract format and SYMPY format

In order to produce an equivalent circuit for the target backend, it is necessary to account for: - how the gate names differ between the source backend to the target backend. - how the order and conventions for some of the inputs to the gate operations

may also differ.

tangelo.linq.translator.translate_sympy.controlled_gate(gate_function)

Change a one-qubit gate to a controlled gate.

Parameters:

gate_function (sympy.physics.quantum.gate) – Class for a specific gate.

Returns:

function – Function wrapping a gate with CGate.

tangelo.linq.translator.translate_sympy.get_sympy_gates()

Map gate name of the abstract format to the equivalent methods of the sympy backend (symbolic simulation).

tangelo.linq.translator.translate_sympy.p_gate(target, theta)

Implementation of the PHASE gate with a unitary matrix.

Parameters:
  • target (int) – Target qubit.

  • theta (float) – Phase parameter.

Returns:

sympy.physics.quantum.gate.UGate – Self-explanatory.

tangelo.linq.translator.translate_sympy.rx_gate(target, theta)

Implementation of the RX gate with a unitary matrix.

Parameters:
  • target (int) – Target qubit.

  • theta (float) – Rotation angle.

Returns:

sympy.physics.quantum.gate.UGate – Self-explanatory.

tangelo.linq.translator.translate_sympy.ry_gate(target, theta)

Implementation of the RY gate with a unitary matrix.

Parameters:
  • target (int) – Target qubit.

  • theta (float) – Rotation angle.

Returns:

sympy.physics.quantum.gate.UGate – Self-explanatory.

tangelo.linq.translator.translate_sympy.rz_gate(target, theta)

Implementation of the RZ gate with a unitary matrix.

Parameters:
  • target (int) – Target qubit.

  • theta (float) – Rotation angle.

Returns:

sympy.physics.quantum.gate.UGate – Self-explanatory.

tangelo.linq.translator.translate_sympy.translate_c_to_sympy(source_circuit)

Take in an abstract circuit, return a quantum circuit object as defined in the Python SYMPY SDK.

Parameters:

source_circuit – quantum circuit in the abstract format.

Returns:

SYMPY.circuits.Circuit – quantum circuit in Python SYMPY SDK format.

tangelo.linq.translator.translate_sympy.translate_op_to_sympy(qubit_operator, n_qubits)

Helper function to translate a Tangelo QubitOperator to a sympy linear combination of tensor products.

Parameters:
  • qubit_operator (tangelo.toolboxes.operators.QubitOperator) – Self-explanatory.

  • n_qubits (int) – The number of qubit the operator acts on.

Returns:

sympy.core.add.Add – Summation of sympy.physics.quantum.TensorProduct objects.

Module contents

tangelo.linq.translator.get_supported_gates()

List all supported gates for all backends found