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, PathLike[Any]], encoding: str = 'utf-8') Circuit

A method to generate a tket Circuit from a qasm file

pytket.qasm.circuit_from_qasm_io(stream_in: TextIO) Circuit

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

pytket.qasm.circuit_from_qasm_str(qasm_str: str) Circuit

A method to generate a tket Circuit from a qasm str

pytket.qasm.circuit_from_qasm_wasm(input_file: Union[str, PathLike[Any]], wasm_file: Union[str, PathLike[Any]], encoding: str = 'utf-8') Circuit

A method to generate a tket Circuit from a qasm str and external WASM module.

pytket.qasm.circuit_to_qasm(circ: 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: Circuit, stream_out: TextIO, header: str = 'qelib1', include_gate_defs: Optional[Set[str]] = None) None

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

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

A method to generate a qasm str from a tket Circuit