pytket.qasm¶
Circuit
objects can be converted to and from OpenQASM, although we do not support all operations.
However, we do support symbolic parameters of gates, both on import and export.
Any pytket Circuit
that is exported to OpenQASM format with pytket.qasm
should be valid for importing again as a Circuit
, making this a convenient file format
to save your Circuit
objects.
In addition to the default qelib1
qasm header, the hqslib1
header is also supported.
We can set the header
argument in the qasm conversion functions as follows.
from pytket.qasm import circuit_to_qasm_str
qasm_str = circuit_to_qasm_str(circ, header="hqslib1")
Note
Unlike pytket backends, the qasm converters do not handle implicit qubit permutations. In other words if a circuit containing an implicit qubit permutation is converted to a qasm file the implicit permutation will not be accounted for and the circuit will be missing this permutation when reimported.
Parser from OPENQASM to tket Circuits
- pytket.qasm.circuit_from_qasm(input_file, encoding='utf-8', maxwidth=32, use_clexpr=False)[source]¶
A method to generate a tket Circuit from a qasm file.
- Parameters:
- Return type:
- Returns:
pytket circuit
- pytket.qasm.circuit_from_qasm_io(stream_in, maxwidth=32, use_clexpr=False)[source]¶
A method to generate a tket Circuit from a qasm text stream
- Return type:
- pytket.qasm.circuit_from_qasm_str(qasm_str, maxwidth=32, use_clexpr=False)[source]¶
A method to generate a tket Circuit from a qasm string.
- pytket.qasm.circuit_from_qasm_wasm(input_file, wasm_file, encoding='utf-8', maxwidth=32, use_clexpr=False)[source]¶
A method to generate a tket Circuit from a qasm string and external WASM module.
- Parameters:
input_file (
Union
[str
,PathLike
[Any
]]) – path to qasm file; filename must have.qasm
extensionwasm_file (
Union
[str
,PathLike
[Any
]]) – path to WASM file containing functions used in qasmencoding (
str
) – encoding of qasm file (default utf-8)maxwidth (
int
) – maximum allowed width of classical registers (default 32)
- Return type:
- Returns:
pytket circuit
- pytket.qasm.circuit_to_qasm(circ, output_file, header='qelib1', maxwidth=32)[source]¶
Convert a Circuit to QASM and write it to a file.
Classical bits in the pytket circuit must be singly-indexed.
Note that this will not account for implicit qubit permutations in the Circuit.
- pytket.qasm.circuit_to_qasm_io(circ, stream_out, header='qelib1', include_gate_defs=None, maxwidth=32)[source]¶
Convert a Circuit to QASM and write to a text stream.
Classical bits in the pytket circuit must be singly-indexed.
Note that this will not account for implicit qubit permutations in the Circuit.
- Parameters:
- Return type:
- pytket.qasm.circuit_to_qasm_str(circ, header='qelib1', include_gate_defs=None, maxwidth=32)[source]¶
Convert a Circuit to QASM and return the string.
Classical bits in the pytket circuit must be singly-indexed.
Note that this will not account for implicit qubit permutations in the Circuit.
- Parameters:
- Return type:
- Returns:
qasm string