Interfacing with External Software

Our compiler tools include functions that allow the easy conversion of True-Qᵀᴹ circuits to and from the circuit representation of other popular software packages. This translation includes a compilation step that converts gates in a circuit into the gates that are supported by the software package to which it is being converted.

Note

Users can specify a set of supported gates during conversion if they want the output to be compatible with a specific gate set.

Currently, True-Qᵀᴹ supports integration with Qiskit, Cirq, and pyQuil.

Example

#
# Interfacing with software example.
# Copyright 2019 Quantum Benchmark Inc.
#

import trueq as tq

# Define a circuit.
circuit = tq.Circuit(
    [
        tq.Cycle({(0,): tq.Gate.x, (1,): tq.Gate.y}),
        tq.Cycle({(0, 2): tq.Gate.cz, (1,): tq.Gate.x}),
        tq.Cycle({(3,): tq.Gate.h, (5,): tq.Gate.s}),
    ]
)

# Convert the circuit into representations in Qiskit, Cirq, and pyQuil.
qiskit_circuit = circuit.to_qiskit()
cirq_circuit = circuit.to_cirq()
pyquil_circuit = circuit.to_pyquil()

# Print the circuit compiled for each software.
print(qiskit_circuit)
print(cirq_circuit)
print(pyquil_circuit)

# Convert each circuit back to a True-Q circuit object.
qiskit_circuit.to_trueq()
cirq_circuit.to_trueq()
pyquil_circuit.to_trueq()

Note

Because each representation is now an object specific to its respective software package, they print according to that package and can be manipalated using functions from the corresponding package.

The output of the above code snippet is given below.

Warning: Found multiple ways to perform Z on (0,)
         (/home/user/jenkins/workspace/release trueq (centos)/.venv/lib64/python3.6/site-packages/trueq-2.2.2-py3.6.egg/trueq/compilation/transpile.py:65)
Warning: Found multiple ways to perform Z on (1,)
         (/home/user/jenkins/workspace/release trueq (centos)/.venv/lib64/python3.6/site-packages/trueq-2.2.2-py3.6.egg/trueq/compilation/transpile.py:65)
        ┌───┐ ░     ░      
q_0: |0>┤ X ├─░──■──░──────
        ├───┤ ░  │  ░      
q_1: |0>┤ Z ├─░──┼──░──────
        └───┘ ░  │  ░      
q_2: |0>──────░──■──░──────
              ░     ░ ┌───┐
q_3: |0>──────░─────░─┤ H ├
              ░     ░ └───┘
q_4: |0>──────░─────░──────
              ░     ░ ┌───┐
q_5: |0>──────░─────░─┤ S ├
              ░     ░ └───┘
(0, 0): ───X───@───────
               │
(1, 0): ───Z───┼───────
               │
(2, 0): ───────@───────

(3, 0): ───────────H───

(5, 0): ───────────S───
DECLARE ro BIT[5]
X 0
Z 1
CZ 0 2
H 3
S 5