pytket.qasm

Circuit objects can be converted to and from OpenQASM, although we do not support all operations. In particular, we do not currently support:

  1. Importing from libraries other than “qelib1”

  2. Ability to interpret gates acting on a whole register in the OpenQASM style

Any pytket Circuit that is exported to this format should be valid for importing again as a Circuit, making this a convenient file format to save your Circuit objects.

However, we do support symbolic parameters of gates, both on import and export.

Parser from OPENQASM to tket Circuits

pytket.qasm.circuit_from_qasm(input_file: Union[str, os.PathLike[Any]]) pytket.circuit.Circuit

A method to generate a tket Circuit from a qasm file

pytket.qasm.circuit_from_qasm_io(stream_in: TextIO) pytket.circuit.Circuit

A method to generate a tket Circuit from a qasm text stream

pytket.qasm.circuit_from_qasm_str(qasm_str: str) pytket.circuit.Circuit

A method to generate a tket Circuit from a qasm str

pytket.qasm.circuit_to_qasm(circ: pytket.circuit.Circuit, output_file: str, header: str = 'qelib1') None

A method to generate a qasm file from a tket Circuit

pytket.qasm.circuit_to_qasm_io(circ: pytket.circuit.Circuit, stream_out: TextIO, header: str = 'qelib1') None

A method to generate a qasm text stream from a tket Circuit

pytket.qasm.circuit_to_qasm_str(circ: pytket.circuit.Circuit, header: str = 'qelib1') str

A method to generate a qasm str from a tket Circuit