qat.purr.integrations.tket module
- class TketBuilder(*args, **kwargs)
Bases:
object
Builds a Tket circuit using a builder API. No direct relation to our other builders as the API is a little too different.
- ECR(qubit1, qubit2, *args)
- barrier(qubits)
- creg(name, size)
- custom_gate(gate_def, qubits, params=None, conditions=None)
- gate(name, qubits, params=None, conditions=None)
- is_basic_gate(name)
- measure(qubits, bits, conditions=None)
- qreg(name, size)
- class TketQIRParser(hardware)
Bases:
QIRParser
QIR parser than turns circuits into Tket structures.
- assign(name, value)
Assigns are dealt with upon converting back to QatIR.
- property builder
Returns the circuit and variables for where results are stored in Qat IR.
This property overwrites the “builder” in the
QIRParser
so that the circuit and output variables are returned in its place. It also removes unused qubits which can greatly increase the effectiveness of the placement of logical-to-physical qubits.
- ccx(control1, control2, target)
- cx(control, target)
- cz(control, target)
- h(target)
- mz(qubit, target)
- static normalize_parameter(param)
- reset(target)
- returns(result_name=None)
Returns are dealt with upon converting back to QatIR.
- rx(theta, qubit)
- ry(theta, qubit)
- rz(theta, qubit)
- s(qubit)
- s_adj(qubit)
- t(qubit)
- t_adj(qubit)
- x(qubit)
- y(qubit)
- z(qubit)
- class TketQasmParser(order_result_vars=False, raw_results=False)
Bases:
Qasm2Parser
QASM parser that turns QASM into Tket structures. Switch to Tkets QASM parser when it’s more mature.
- process_barrier(node, context, builder, **kwargs)
- process_cnot(node, context, builder, conditions=None, **kwargs)
- process_creg(node, context, builder, **kwargs)
- process_gate(method, context, builder, conditions=None, **kwargs)
Process a gate call.
- process_gate_definition(node, context, _, **kwargs)
- process_if(node, context, builder, *kwargs)
- process_measure(node, context, builder, conditions=None, **kwargs)
- process_program(builder, qasm)
- process_qreg(node, context, builder, **kwargs)
- process_reset(node, context, builder, conditions=None, **kwargs)
- process_unitary(node, context, builder, conditions=None, **kwargs)
Unitary in QASM terms is just
U(...)
.
- class TketToQatIRConverter(model)
Bases:
object
Converts a Tket circuit into Qat IR.
Warning
This converter is only intended to be used to convert a TKET circuit into QAT IR after being parsed from QIR. It does not account for multiple quantum and classical registers, and might give undesired behaviour if used outside of this use case.
- convert(circuit)
Converts a Tket circuit into Qat IR, adding any necesarry assigns and returns.
- static convert_parameter(arg)
A parameter stored in a Tket operation is in units of \(\pi\). Parameters are returned as a string, sometimes in fractional form: we need to convert it to an absolute value.
- get_qubit(index)
Maps a Tket logical qubit index onto a physical qubit.
- apply_default_transforms(circuit, architecture, opts)
- check_validity(circuit, architecture)
- fetch_default_passes(architecture, opts, pass_list=None, add_delay=True)
- get_coupling_subgraphs(couplings)
Given a list of connections which potentially describe a disconnected graph, this returns a list of connected subgraphs
- optimize_circuit(circ, architecture, opts)
Apply all Tket optimizations to the circuit provided as defined in the options flag.
- run_tket_optimizations(circ, opts, hardware)
Runs tket-based optimizations and modifications. Routing will always happen no matter the level.
Will run optimizations in sections if a full suite fails until a minimal subset of passing optimizations is found.
- Parameters:
circ¶ (
Circuit
) – Tket circuit to optimize. The source file must be already parsed to a TKET circuit.opts¶ – Specifies which TKET optimizations to run.
hardware¶ (
QuantumHardwareModel
) – The hardware model is used for routing and placement purposes.
- Return type:
Circuit
- run_tket_optimizations_qasm(qasm_string, opts, hardware)
Runs tket-based optimizations and modifications. Routing will always happen no matter the level.
Will run optimizations in sections if a full suite fails until a minimal subset of passing optimizations is found.
- Parameters:
qasm_string¶ – The circuit as a QASM string.
opts¶ – Specifies which TKET optimizations to run.
hardware¶ (
QuantumHardwareModel
) – The hardware model is used for routing and placement purposes.
- Return type:
str
- run_tket_optimizations_qir(file_or_str, opts, hardware, results_format=None)
Runs tket-based optimizations and modifications. Routing will always happen no matter the level.
Will run optimizations in sections if a full suite fails until a minimal subset of passing optimizations is found.
- Parameters:
file_or_str¶ – The QIR program as a string, or its file path.
opts¶ – Specifies which TKET optimizations to run.
hardware¶ (
QuantumHardwareModel
) – The hardware model is used for routing and placement purposes.
- Return type: