# Interfaces¶

Interfaces to external packages all operate under the same overall design strategy. They each define a get_config() function which returns a Config object containing all gates that are compatible with the interface gate definitions.

However, the default Config objects typically have multiple NativeGates that implement the same Gate for different parameters. For example Identity is a special case of both Z(phi) and X(phi) when phi=0. Each interface fixes this degeneracy by maintaining a “priority list” containing the names of the gates found in the external package.

The priority list for an interface can be accessed and altered using the corresponding methods get_priority_list() and set_priority_list().

When an interface is successfully loaded, Circuit gets additional functionality in the form of a Circuit.to_<interface>(), which will convert the True-Q™ circuit representation into the representation of the external package. By altering the priority list for the specified package, the user can select specific gates to build into by default. Additional advanced options can be accessed by passing custom config objects which are compatable with the interface gates, see the corresponding from_trueq_circ() for more information.

class trueq.interface.metadata.Metadata(mapping=None)

Stores data not recorded in Circuit objects to enable lossless conversion.

Parameters

mapping (dict) – A dictionary mapping True-Q™ qubit labels to the indexing of the target framework.

## Cirq¶

trueq.interface.cirq.from_trueq_circ(tq_circ, metadata=None, config='ZXZ', device=None, join_meas=True)

Converts a Circuit into a cirq.Circuit.

import cirq
import trueq as tq

circ = tq.Circuit([{(0, 1): tq.Gate.cx}])

ext_circ = tq.interface.cirq.from_trueq_circ(circ)

ext_circ.to_trueq().draw()


Note

Arbitrary single-qubit operations are decomposed using the ZXZ QubitMode by default.

If an SU(4) gate is provided which is not directly equivalent to a single gate in get_priority_list(), it is decomposed using the Compiler().

Parameters
• circuit (Circuit) – The True-Q™ circuit to be converted into a Cirq circuit.

• metadata (CirqMetadata) – Metadata required to accurately reproduce the original Cirq circuit. If this is not provided, measurements are added at the end of the circuit.

• config (Config | str) – If a Config which contains gates which are directly decomposable into Cirq native gates is provided, then conversion will take place into gates specified by that config. Alternatively, config accepts text strings and uses them as the mode argument for get_config.

• device (None or cirq.Device) – A cirq.Device, if no device is provided, an unconstrained device with cirq.GridQubit is assumed.

• join_meas (bool) – This determines if Meas are joined into single cirq.meas() objects, or single meas object in parallel in the given moment/cycle.

Return type

cirq.Circuit

trueq.interface.cirq.from_trueq_gate(gate)

Converts a Gate into a cirq.ops.GateOperation.

When multiple Cirq gates can represent the True-Q™ gate, a priority list (accessible via get_priority_list() and customizable via set_priority_list()) is used to choose which Cirq gate is used.

Parameters

tq_gate (Gate) – The True-Q™ gate to be converted into a Cirq gate.

Raises

CirqConversionError – If conversion is not possible.

trueq.interface.cirq.get_config(mode='ZXZXZ')

Gets a Config containing all compatible Cirq gates listed in the priority list for the Cirq interface, see get_priority_list().

Parameters

mode (str) – The single-qubit decomposition mode as defined in QubitMode. The default is the ZXZXZ decomposition.

Return type

Config

trueq.interface.cirq.get_priority_list()

Returns the current conversion priority list specifying the order in which cirq.ops.GateOperations should be used by from_trueq_gate() to try to construct a Cirq gate.

The priority list is used by get_config() to build a Config object.

The priority list can be altered using set_priority_list().

Return type

list

trueq.interface.cirq.set_priority_list(priority)

Set the priority list and reset all caching for the Cirq interface.

See get_priority_list() for a full description.

Parameters

priority (list) – The priority list. If None is provided, the priority list is reset to the default.

trueq.interface.cirq.to_trueq_circ(cirq_circ)

Converts a cirq.Circuit into a Circuit.

This returns a tuple of the True-Q™ circuit and a CirqMetadata which contains information present in the Cirq circuit which is not represented in True-Q™ circuits and is required for the reverse conversion (see from_trueq_circ()).

Note

Measurements are always placed at the end of the circuit.

Parameters

cirq_circ – A Cirq representation of a circuit.

Type

cirq.Circuit

Return type

tuple of (Circuit, CirqMetadata)

trueq.interface.cirq.to_trueq_gate(ext_gate)

Converts a cirq.ops.GateOperation into a Gate.

Parameters

ext_gate (cirq.ops.GateOperation) – The Cirq gate to be converted into a True-Q™ gate.

Return type

Gate

Raises

CirqConversionError – If conversion is not possible

class trueq.interface.metadata.CirqMetadata(mapping=None, measure_mapping=None)

Stores data not recorded in Circuit objects to enable lossless conversion.

Note

Measurements recorded in cirq.Circuit objects are always assumed to be placed at the end of the circuit.

If no measurements are provided through measure_mapping, then Measurements are automatically added on all qubits

Parameters
• mapping (dict) – A dictionary mapping True-Q™ qubit labels to cirq.Devices.

• measure_mapping (dict) – A dictionary mapping True-Q™ labels to the name of a measurement name as defined by cirq.measure()

class CirqMeasure(tq_qubits, meas_name, invert)
property invert

Alias for field number 2

property meas_name

Alias for field number 1

property tq_qubits

Alias for field number 0

measure(tq_qubits, meas_name=None, invert=())

Add a record of a measurement on a given qubit.

This assumes that all measurements happen at the end of the circuit.

Parameters
• tq_qubits (list[tuple]) – The True-Q™ label for the qubits.

• meas_name (str) – The name of the measurement in Cirq.

• invert (Iterable[bool]) – bitmask of if the output of the measurement is expected to be inverted, see the Cirq documentation on measurements for more information.

## PyQuil¶

trueq.interface.pyquil.from_trueq_circ(circ, metadata=None, config='ZXZ')

Converts a Circuit into a pyquil.Program.

import pyquil
import trueq as tq

circ = tq.Circuit([{(0, 1): tq.Gate.cx}])

ext_circ = tq.interface.pyquil.from_trueq_circ(circ)

ext_circ.to_trueq().draw()


Note

Measurements are always assumed to be at the end of a circuit.

Arbitrary single-qubit operations are decomposed using the ZXZ QubitMode by default.

If an SU(4) gate is provided which is not directly equivalent to a single gate in get_priority_list(), it is decomposed using the Compiler().

Parameters
• circ (Circuit) – The True-Q™ circuit to be converted into a PyQuil Program.

• metadata (PyquilMetadata) – Metadata required to accurately reproduce the original PyQuil program. By default, measurements are placed at the end of the circuit on all qubits, reading out to a classical register called ‘ro’.

• config (Config | str) – If a Config which contains gates which are directly decomposable into PyQuil native gates is provided, then conversion will take place into gates specified by that config. Alternatively, config accepts text strings and uses them as the mode argument for get_config.

Return type

pyquil.Program

trueq.interface.pyquil.from_trueq_gate(gate)

Converts a Gate into a pyquil.quilbase.Gate.

When multiple PyQuil gates can represent the True-Q™ gate, a priority list (accessible via get_priority_list() and customizable via set_priority_list()) is used to choose which PyQuil gate is used.

Parameters

tq_gate (Gate) – The True-Q™ Gate to be converted into a PyQuil gate.

Raises

PyquilConversionError – If conversion is not possible.

trueq.interface.pyquil.get_config(mode='ZXZXZ')

Gets a Config containing all compatible PyQuil gates listed in the priority list for the PyQuil interface, see get_priority_list().

Parameters

mode (str) – The single-qubit decomposition mode as defined in QubitMode. The default is the ZXZXZ decomposition.

Return type

Config

trueq.interface.pyquil.get_priority_list()

Returns the current conversion priority list specifying the order in which pyquil.quilbase.Gates should be used by from_trueq_gate() to try to construct a PyQuil gate.

The priority list is used by get_config() to build a Config object.

The priority list can be altered using set_priority_list().

Return type

list

trueq.interface.pyquil.set_priority_list(priority)

Set the priority list and reset all caching for the PyQuil interface.

See get_priority_list() for a full description.

Parameters

priority (list) – The priority list. If None is provided, the priority list is reset to the default.

trueq.interface.pyquil.to_trueq_circ(program)

Converts a pyquil.Program into a Circuit.

This returns a tuple of the True-Q™ circuit and a PyquilMetadata which contains information present in the PyQuil program which is not represented in True-Q™ circuits and is required for the reverse conversion (see from_trueq_circ()).

Parameters

program (pyquil.Program) – The pyquil program to be converted into a True-Q™ circuit.

Return type

tuple of (Circuit, PyquilMetadata)

trueq.interface.pyquil.to_trueq_gate(ext_gate)

Converts a pyquil.quilbase.Gate into a Gate.

This only works for gates defined in pyquil.gate_matrices.QUANTUM_GATES.

Parameters

ext_gate (pyquil.quilbase.Gate) – The PyQuil gate to be converted into a True-Q™ gate.

Return type

Gate

Raises

PyquilConversionError – If conversion is not possible.

class trueq.interface.metadata.PyquilMetadata(mapping=None, classical_regs=None, measure_mapping=None)

Stores data not recorded in Circuit objects to enable lossless conversion.

Note

Measurements recorded in pyquil.Program objects are always assumed to be placed at the end of the circuit.

Parameters
• mapping (dict) – A dictionary mapping True-Q™ qubit labels to pyquil.device.Qubits.

• classical_regs (dict of pyquil.quilbase.Declares) – A dictionary containing all of the pyquil.quilbase.Declares, where the keys are the names of the classical registers.

• measure_mapping (dict) – A dictionary mapping True-Q™ labels to the name of a measurement name as defined by pyquil.quilbase.Measurement()

## Qiskit¶

trueq.interface.qiskit.config_from_backend(backend)

Takes an IBM Backend and converts it into a Config object.

The resulting config will contain the chip topology constraints as well as the gates themselves. This works with backends which contain the following gate names, ['u1', 'u2', 'u3', 'cx'].

import qiskit as qk
from trueq.interface import qiskit as tqk

tqk.config_from_backend(qk.providers.aer.QasmSimulator())

# For backends provided by the IBM Quantum Experience, some additional
# authentication code is needed
# provider = qk.IBMQ.get_provider()
# backend = provider.get_backend("ibmqx2")
# config = tq.interface.qiskit.config_from_backend(backend)

Name: qasm_simulator
Mode: ZXZXZ
Dimension: 2
Gate U1Gate:
Matrix:
- ['1', '0']
- ['0', exp(1j*lam)]
Involving: {}
Gate U2Gate:
Matrix:
- ['0.7071067811865475', -exp(1j*lam) / sqrt(2)]
- [exp(1j*phi) / sqrt(2), exp(1j*(phi + lam)) / sqrt(2)]
Involving: {}
Gate U3Gate:
Matrix:
- [cos(theta / 2), -exp(1j*lam) * sin(theta / 2)]
- [exp(1j*phi) * sin(theta / 2), exp(1j*(phi + lam)) * cos(theta / 2)]
Involving: {}
Gate cnotgate:
Matrix:
- [(1+0j), 0j, 0j, 0j]
- [0j, (1+0j), 0j, 0j]
- [0j, 0j, 0j, (1+0j)]
- [0j, 0j, (1+0j), 0j]
Involving: {}

Parameters

backend (qiskit.provider.BaseBackend) – A backend from qiskit.

Returns

A config which contains gates and topology of a given backend.

Return type

Config

class trueq.interface.qiskit.Executor(circuits, backend, filename=None, n_shots=128, max_submissions=5, overwrite=False)

A class to asynchronously submit a CircuitCollection to a qiskit.provider.BaseBackend.

Since current hardware devices have a limit to the number of circuits that can be run at any one time, batching of circuits must be performed. An example of this is the ibmqx2 chip provided by IBM, it has a stated limit of 75 circuits which may be submitted to it at any one time. This means that if a user wishes to submit more than 75 circuits, the total collection of circuits needs to be broken up into groups (or batches) of no more than 75 circuits. True-Q™ circuit collections have native support for batching circuits like this, see batch().

The Executor converts batched circuits into Qiskit formatted objects, and submits them to the provided backend as jobs on the physical devices. The executor then keeps track of the status of each job asynchronously, updating the status periodically as to where the jobs are in the device’s queue.

Since most devices have a limit as to the number of batches that can be submitted by one user at any given time, the executor will only submit up to a max_submissions number of batches at any one time. Once a batch has run on the device, and has been removed from the job queue, the executor will place another batch into the queue until there are a total of max_submissions submitted jobs at any one time.

Here is a worked example, where a simple circuit is submitted to the IBMQ simulator backend:

import trueq as tq
import qiskit as qk

# provider = qk.IBMQ.get_provider()
# backend = provider.get_backend('ibmq_qasm_simulator')
backend = qk.providers.aer.QasmSimulator()

# Generating a simple circuit of only the H gate
circs = tq.Circuit([{0: tq.Gate.h}, {0: tq.Meas()}])

# The handling of the submission of the circuits
ex = tq.interface.qiskit.Executor(circs, backend)

# This is a blocking operation, and will block until all data has been acquired
ex.results().results

# A more complicated example using advanced batching options and saving
# the results

circs2 = tq.make_srb((0, 1), [4, 64, 128])

# Batch the circuits into groups of 75, including readout calibration circuits
# in each batch
ro_circuits = tq.make_rcal([0, 1])
batches = circs2.batch(75, extra_circuits=ro_circuits)

ex2 = tq.interface.qiskit.Executor(batches, backend)
ex2.results().results

Parameters
• circuits (CircuitCollection | Circuit | generator) –

The circuits which are to be submitted to the Qiskit backend. Depending on what is submitted here, there are several possible outcomes:

• Circuit

It will be converted to a CircuitCollection. Results will be placed back inside of the original circuit object itself, and can be viewed as data is retrieved from the backout without having to wait.

• CircuitCollection

It will be batched using the maximum allowed batch size for the given backend. For very long circuits this may result in errors due to limited memory of the classical hardware which control the backend. If errors occur during the submission of a CircuitCollection, it is recommended to resubmit using the third submission type. Results are placed back inside of the original circuits as data is retrieved from the server.

• batch

The circuits will be batched exactly as given by the batch generator. This can be used to submit automatic readout correction circuits, see above example or batch() for more details about possible options. Results are placed inside original circuits as data comes in, note that some batching options may result in additional circuits being added to the collection.

• backend (qiskit.provider.BaseBackend) – The Qiskit backend to which the circuits will be submitted.

• filename (str) – Optional filename where results will be saved. If this is provided the Executor will also be able to partially recover from a crash of the python session, loss of internet, or other interruption in data acquisition.

• n_shots (int) – The number of shots of the circuits to be aquired.

• max_submissions (int) – The maximum number of batches allowed in a backend queue at any one time. This number is set by the backend provider and should be set here accordingly.

• overwrite (bool) – Whether to overwrite the file on disk if it exists before these circuits are executed. Note that regardless of the value of this flag, after this first check, the file on disk will continually be updated as new results come in.

property n_shots

Number of shots to be aquired by the backend.

Return type

int

property backend

Qiskit backend where the circuits will be submitted.

Return type

qiskit.provider.BaseBackend

property filename

Filename where circuits with results will be saved.

Return type

str

property circuits

Batched CircuitCollection, if a single circuit was provided, it will have been converted into a CircuitCollection. See Executor documentation for more details.

Return type

list

results()

Returns the CircuitCollection complete with results.

Note

This is a blocking operation, and once called you will have to wait until all circuits have completed acquisition on the backend.

This is not required to be called in order to get results, as results are automatically placed into the provided circuits when they are retrieved from the backend. This function is simply a means to force code to wait until the backend returns all of the results.

Return type

CircuitCollection

property status

Returns a text representation for the current status of all jobs.

This is a string equivalent of the html output provided in jupyter.

Return type

str

save(overwrite=False)

Saves the current CircuitCollection regardless of status of acquisition.

This is called automatically whenever a new batch is either submitted or retrieved from the backend.

Parameters

overwrite (bool) – Whether to force an overwrite of the existing file.

cancel()

Cancels all currently submitted jobs if possible.

It is recommended that this be run any time a submission mistake is made, as circuits that have been submitted to the backend will stay in queue otherwise.

trueq.interface.qiskit.from_trueq_circ(circuit, metadata=None, config=None)

Converts a Circuit into a qiskit.QuantumCircuit.

import qiskit
import trueq as tq

circ = tq.Circuit([{(0, 1): tq.Gate.cx}])

ext_circ = tq.interface.qiskit.from_trueq_circ(circ)

ext_circ.to_trueq().draw()


Note

Single qubit gates are reduced as much as possible up to numerical precision, e.g., some U3 gates become U2 or U1 gates.

Blocking operations are added at the end of every Cycle to ensure that the physical noise process is consistent.

Parameters
• circuit (Circuit) – The True-Q™ circuit to be converted into a Qiskit QuantumCircuit

• metadata (QiskitMetadata) – Metadata required to accurately reproduce the original Qiskit QuantumCircuit. By default, the returned QuantumCircuit will have one quantum register and one classical register and have measurements at the end of the circuit mapping each quantum bit to each classical bit.

• config (Config) – A given config object which contains gates which can be performed by qiskit, but also has hardware restrictions. For example, a Config object can represent a CNOT gate that is restricted to specific sets of qubits, and a CNOT gate is a known native gate in Qiskit. Providing this config means that not only will the circuit be converted into Qiskit representation, but also that it will satisfy hardware restrictions. If no config is provided, all possible qiskit gates are used in the compilation.

Returns

A Qiskit circuit representation of the Circuit

Return type

qiskit.QuantumCircuit

trueq.interface.qiskit.from_trueq_gate(gate)

Converts a Gate into a qiskit.circuit.Gate.

When multiple Qiskit gates can represent the True-Q™ gate, a priority list (accessible via get_priority_list() and customizable via set_priority_list()) is used to choose which Qiskit gate is used.

Parameters

tq_gate (Gate) – The True-Q™ Gate to be converted into a Qiskit gate.

Raises

QiskitConversionError – If conversion is not possible.

trueq.interface.qiskit.get_config(mode='ZXZXZ')

Get a Config containing all compatible Qiskit gates listed in the priority list for the Qiskit interface, see get_priority_list().

Parameters

mode (str) – The single-qubit decomposition mode as defined in QubitMode. The default is the ZXZXZ decomposition.

Return type

Config

trueq.interface.qiskit.get_priority_list()

Returns the current conversion priority list specifying the order in which qiskit.circuit.Gates should be used by from_trueq_gate() to try to construct a Qiskit gate.

The priority list is used by get_config() to build a Config object.

The priority list can be altered using set_priority_list().

Return type

list

trueq.interface.qiskit.randomly_compile_qiskit(circuit, twirling_group=None, compress=True)

Randomly compiles a given Qiskit QuantumCircuit or DAGCircuit object.

Accepts the same options as randomly_compile()

Parameters
• circuit (QuantumCircuit or DAGCircuit) – A Qiskit circuit object

• twirling_group (dict or None) – A twirling group, see randomized compilation documentation

• compress (bool) – Whether or not mutable gates should be compressed as much as possible.

Returns

A qiskit circuit

Return type

qiskit.QuantumCircuit

class trueq.interface.qiskit.RCPass(*args, **kwargs)

This is a Pass object as used in Qiskit’s transpiler object. This enables use of True-Q™’s randomized compilation tools in the framework of Qiskit.

Randomly compile a given DAG, optionally compress single qubit gates as much as possible after insertion of twirl operations.

Beginner users are recommended to use the defaults.

Parameters
• twirling_group (dict | None) – A twirling group, see randomized compilation documentation

• compress (bool) – Whether or not mutable gates should be compressed as much as possible.

run(dag)

Randomly Compile a DAGCircuit

Return type

DAGCircuit

trueq.interface.qiskit.set_priority_list(priority)

Set the priority list and reset all caching for the Qiskit interface.

See get_priority_list() for a full description.

Parameters

priority (list) – The priority list. If None is provided, the priority list is reset to the default.

trueq.interface.qiskit.to_trueq_circ(qk_circ)

Converts a qiskit.QuantumCircuit into a Circuit.

This returns a tuple of the True-Q™ circuit and a QiskitMetadata which contains information present in the Qiskit circuit which is not represented in True-Q™ circuits and is required for the reverse conversion (see from_trueq_circ()).

Note

Barriers are not preserved, and measurements are always placed at the end of the circuits.

Parameters

dag (qiskit.QuantumCircuit) – A qiskit circuit representation of a circuit.

Return type

tuple of (Circuit, QiskitMetadata)

trueq.interface.qiskit.to_trueq_gate(ext_gate)

Converts a qiskit.circuit.Gate into a Gate.

Parameters

ext_gate (qiskit.circuit.Gate) – The Qiskit gate to be converted into a True-Q™ gate.

Return type

Gate

Raises

QiskitConversionError – If conversion is not possible.

class trueq.interface.metadata.QiskitMetadata(mapping=None, meas_pairs=None)

Stores data not recorded in Circuit objects to enable lossless conversion.

Parameters
• mapping (dict) – A dictionary mapping True-Q™ qubit labels to qiskit.Qubits.

• meas_pairs (list) – A list of pairs, each with type (qiskit.Qubit, qiskit.Bit), whose order matches that of meas_locs. This stores which classical register each quantum measurement is to be stored into.

## QASM¶

class trueq.interface.qasm.QASM

Interface class to convert Circuits into the QASM 2.0 language.

This is the only interface which does not use a priority list.

QASM only defines two possible gate operations natively:

Any other gates used in a QASM file must be defined as a subroutine using these two fundamental gates.

Note

A Config containing only these two gates is defined in QASM_CONFIG().

The QASM conversion class stores a Config which contains any one or two qubit fixed gates, as well as any of the following parameterized single qubit operations:

This config can be altered via set_config() and get_config(), and it will automatically be converted to gate definitions inside of the QASM header and may be used inside of the QASM file itself. If no config is provided, then it is assumed that the qelib1 definition file is available, and this file is included as an import in the output QASM. A config containing the definitions for this library can be accessed through QELIB1().

import trueq as tq
circ = tq.make_xrb([0], [5], 1)[0]
print(circ.to_qasm())

// True-Q Version: 2.7.1
// Circuit Key:
// {'measurement_basis': 'Y', 'n_random_cycles': 5, 'protocol': 'XRB', 'seq_label': 1101, 'twirl': (('C', 0),)}
OPENQASM 2.0;
include "qelib1.inc";
qreg q[1];
creg c[1];
u2(0.0,3.141592653589793) q[0];
barrier q;
u2(-3.141592653589793,0.0) q[0];
barrier q;
u3(3.141592653589793,0.0,1.5707963267948966) q[0];
barrier q;
u2(-3.141592653589793,1.5707963267948966) q[0];
barrier q;
u2(1.5707963267948966,1.5707963267948966) q[0];
barrier q;
measure q[0] -> c[0];


Building into custom defined QASM gates:

import trueq as tq

zz_fact = tq.config.GateFactory("ZZ", matrix=tq.Gate.from_generators("ZZ", 90))
factories = [tq.interface.QASM.QELIB1().u1,
tq.interface.QASM.QELIB1().u2,
tq.interface.QASM.QELIB1().u3,
zz_fact]
config = tq.Config.from_params("ZZ_conf", factories=factories)

tq.interface.QASM.set_config(config)

circ = tq.make_xrb([0], [5], 1)[0]
print(circ.to_qasm())

// True-Q Version: 2.7.1
// Circuit Key:
// {'measurement_basis': 'Z', 'n_random_cycles': 5, 'protocol': 'XRB', 'seq_label': 4694, 'twirl': (('C', 0),)}
OPENQASM 2.0;
gate u1(lambda) q { U(0,0,lambda) q; }
gate u2(phi,lambda) q { U(pi/2,phi,lambda) q; }
gate u3(theta,phi,lambda) q { U(theta,phi,lambda) q; }
gate ZZ q0, q1
{
U(0.0,-4.71238898038469,1.5707963267948966) q0;
U(1.5707963267948966,-3.141592653589793,0.0) q1;
CX q0,q1;
U(0.0,0.0,1.5707963267948966) q0;
U(1.5707963267948966,-1.5707963267948966,0.0) q1;
}
qreg q[1];
creg c[1];
u2(-1.5707963267948966,1.5707963267948966) q[0];
barrier q;
u2(-1.5707963267948966,0.0) q[0];
barrier q;
u2(-3.141592653589793,1.5707963267948966) q[0];
barrier q;
u2(-1.5707963267948966,-1.5707963267948966) q[0];
barrier q;
u2(1.5707963267948966,0.0) q[0];
barrier q;
measure q[0] -> c[0];

classmethod get_config()

The Config used to build the QASM representation.

This config will automatically be converted to gate definitions inside of the QASM header and may be used inside of the QASM file itself. See from_trueq_circ() for details on output.

Type

Config

classmethod set_config(config=None)

Set the Config which contains any one or two qubit fixed gates, as well as any of the following parameterized single qubit operations:

The provided config will automatically be converted to QASM compatible gate definitions inside of the QASM header and may be used inside of the QASM file itself. If no config is provided, then it is assumed that the qelib1 definition file is available, and this file is included as an import in the output QASM. A config containing the definitions for this library can be accessed through QELIB1().

Parameters

config (Config) – The config containing gate definitions that are desired for the QASM representation.

classmethod get_header()

Return the lines of the header currently associated with the currently desired QASM representation as defined by the get_config().

Return type

str

classmethod from_trueq_gate(gate)

Convert a Gate into a QASM gate in the currently specified QASM respresentation as defined by get_config().

Return type

str

Raises

ValueError – If conversion is not possible.

classmethod from_trueq_circ(circuit, custom_header=None, include_auto_header=True)

Converts a Circuit into a QASM 2.0 text string.

Circuits converted to QASM will use the gate definitions found in the get_config(). These definitions will by default be included at the top of the output QASM file (this behavior can be disabled by setting include_auto_header=False). Additional lines in the header can be included by providing a list of strings to custom_header, which will be appended as new lines at the top of the file.

Note

Barriers are added between every Cycle in addition to every location where a Block is present.

Parameters
• circuit (Circuit) – The circuit to be converted to QASM.

• custom_header (list) – A list of strings which will be put at the top of the file, with each string being placed on a seperate line.

• include_auto_header (bool) – If the get_config is not the qelib1 config, then QASM requires all gates present to be written as combinations of U3 and CNOT gates (see the docs for QASM, for more details), this flag determines if these definitions should be included in the header of the QASM file.

Return type

str

classmethod QASM_CONFIG()

A Config containing the two possible gate operations defined by QASM natively:

Any other gates used in a QASM file must be defined by these two fundamental gates.

Return type

Config

classmethod QELIB1()

A Config which contains the one and fixed two qubit gates found in the qelib1 library commonly used in qasm representations.

This config is the default used by the QASM converter unless another is specified.

Return type

Config