pytket.phir package#
Subpackages#
Submodules#
pytket.phir.api module#
- pytket.phir.api.pytket_to_phir(circuit: Circuit, qtm_machine: QtmMachine | None = None) str #
Converts a pytket circuit into its PHIR representation.
This can optionally include rebasing against a Quantinuum machine architecture, and control of the TKET optimization level.
- Parameters:
circuit – Circuit object to be converted
qtm_machine – (Optional) Quantinuum machine architecture to rebase against
- Returns:
PHIR JSON as a str
- pytket.phir.api.qasm_to_phir(qasm: str, qtm_machine: QtmMachine | None = None, wasm_bytes: bytes | None = None) str #
Converts a QASM circuit string into its PHIR representation.
This can optionally include rebasing against a Quantinuum machine architecture, and control of the TKET optimization level.
- Parameters:
qasm – QASM input to be converted
qtm_machine – (Optional) Quantinuum machine architecture to rebase against
wasm_bytes – (Optional) WASM as bytes to include as part of circuit
pytket.phir.cli module#
pytket.phir.machine module#
- class pytket.phir.machine.Machine(size: int, gateset: set[OpType], tq_options: set[int], timings: MachineTimings)#
Bases:
object
A machine info class for testing.
- class pytket.phir.machine.MachineTimings(tq_time: float, sq_time: float, qb_swap_time: float, meas_prep_time: float)#
Bases:
object
Gate times for a machine.
tq_time: time for a two qubit gate sq_time: time for a single qubit gate qb_swap_time: time it takes to swap to qubits meas_prep_time: time to arrange qubits for measurement
- meas_prep_time: float#
- qb_swap_time: float#
- sq_time: float#
- tq_time: float#
pytket.phir.phirgen module#
- pytket.phir.phirgen.append_cmd(cmd: Command, ops: list[dict[str, Any]]) None #
Convert a pytket command to a PHIR command and append to ops.
- Parameters:
cmd – pytket command obtained from pytket-phir
ops – the list of ops to append to
- pytket.phir.phirgen.arg_to_bit(arg: UnitID) list[str | int] #
Convert tket arg to Bit.
- pytket.phir.phirgen.assign_cop(lhs: list[str] | list[list[str | int]], rhs: Sequence[Var | int | JsonDict | Bit]) dict[str, Any] #
PHIR for classical assign operation.
- pytket.phir.phirgen.classical_op(exp: LogicExp, *, bitwise: bool = False) dict[str, Any] | int #
PHIR for classical register operations.
- pytket.phir.phirgen.convert_classicalevalop(op: ClassicalEvalOp, cmd: Command) dict[str, Any] | None #
Return PHIR dict for a pytket ClassicalEvalOp.
- pytket.phir.phirgen.convert_gate(op: Op, cmd: Command) dict[str, Any] | None #
Return PHIR dict for a tket gate op.
- pytket.phir.phirgen.convert_subcmd(op: Op, cmd: Command) dict[str, Any] | None #
Return PHIR dict given a tket op and its arguments.
- pytket.phir.phirgen.cop_from_op_name(op_name: str) str #
Get PHIR classical op name from pytket op name.
- pytket.phir.phirgen.create_wasm_op(cmd: Command, wasm_op: WASMOp) dict[str, Any] #
Creates a PHIR operation for a WASM command.
- pytket.phir.phirgen.dedupe_bits_to_registers(bits: Sequence[UnitID]) list[str] #
Dedupes a list of bits to their registers, keeping order intact.
- pytket.phir.phirgen.extract_wasm_args_and_returns(command: Command, op: WASMOp) tuple[list[str], list[str]] #
Extract the wasm args and return values as whole register names.
- pytket.phir.phirgen.genphir(inp: list[tuple[Ordering, ShardLayer, Cost]], circuit: Circuit, *, machine_ops: bool = True) str #
Convert a list of shards to the equivalent PHIR.
- Parameters:
inp – list of shards
circuit – corresponding tket Circuit
machine_ops – whether to include machine ops
- pytket.phir.phirgen.get_cop_from_op(op: ClOp) str | int #
Get PHIR classical op name from ClOp.
- pytket.phir.phirgen.get_decls(qregs: list[QubitRegister], cregs: list[BitRegister]) list[dict[str, str | int]] #
Get PHIR declarations for qubits and classical variables.
- pytket.phir.phirgen.make_comment_text(cmd: Command, op: Op) str #
Converts a command + op to the PHIR comment spec.
- pytket.phir.phirgen.multi_bit_condition(args: list[UnitID], value: int) dict[str, Any] #
Construct bitwise condition.
- pytket.phir.phirgen.phir_from_clexpr_arg(expr_arg: int | ClBitVar | ClRegVar | ClExpr, bit_posn: dict[int, int], reg_posn: dict[int, list[int]], bits: list[Bit]) int | str | list[str | int] | dict[str, Any] #
Return PHIR dict for a ClExpr.
pytket.phir.phirgen_parallel module#
- pytket.phir.phirgen_parallel.adjust_phir_transport_time(ops: list[JsonDict], machine: Machine) None #
Analyze the generated phir and adjust the transport time.
- pytket.phir.phirgen_parallel.consolidate_sub_commands(groups: dict[int, list[Shard]]) dict[int, list[Shard]] #
Group all the sub_commands into the first shard in the group.
This allows maximum parallelization of sub-commands across shards.
- pytket.phir.phirgen_parallel.exec_order_preserved(group_exec_order: list[int], group_number: int, qubit_last_group: int) bool #
Determine whether order is preserved when adding qubits to groups.
- pytket.phir.phirgen_parallel.format_and_add_primary_commands(group: list[Shard], ops: list[JsonDict]) None #
Create properly formatted PHIR for parallel primary commands.
- pytket.phir.phirgen_parallel.genphir_parallel(inp: list[tuple[Ordering, ShardLayer, Cost]], circuit: Circuit, machine: Machine) str #
Convert a list of shards to the equivalent PHIR with parallel gating.
- Parameters:
inp – list of shards
circuit – corresponding tket Circuit
machine – a QTM machine on which to simulate the circuit
- pytket.phir.phirgen_parallel.get_transport_time_for_gate(gate: str, machine: Machine) float #
Return the transport time on the machine for the given gate type.
- pytket.phir.phirgen_parallel.groups2qops(groups: dict[int, list[Command]], ops: list[JsonDict]) None #
Convert the groups of parallel ops to properly formatted PHIR.
- pytket.phir.phirgen_parallel.process_shards(shard_layer: ShardLayer, max_parallel_tq_gates: int, max_parallel_sq_gates: int) dict[int, list[Shard]] #
Break up the shard layer into parallelizable groups.
- pytket.phir.phirgen_parallel.process_sub_commands(sub_commands: dict[UnitID, list[Command]], max_parallel_sq_gates: int) dict[int, list[Command]] #
Create parallelizable groups of sub-commands.
pytket.phir.place_and_route module#
pytket.phir.placement module#
- exception pytket.phir.placement.GateOpportunitiesError#
Bases:
Exception
Exception raised when gating zones cannot accommodate all operations.
- exception pytket.phir.placement.InvalidParallelOpsError(q: int)#
Bases:
Exception
Raised when a layer tries to gate the same qubit more than once in parallel.
- exception pytket.phir.placement.PlacementCheckError#
Bases:
Exception
Exception raised when placement check fails.
- pytket.phir.placement.nearest(zone: int, options: set[int]) int #
Return the nearest available zone to the given zone.
- pytket.phir.placement.optimized_place(ops: list[list[int]], tq_options: set[int], sq_options: set[int], num_qubits: int, prev_state: list[int]) list[int] #
Place the qubits in the right order.
- pytket.phir.placement.place(ops: list[list[int]], tq_options: set[int], sq_options: set[int], num_qubits: int) list[int] #
Place the qubits in the right order.
- pytket.phir.placement.place_tq_ops(tq_ops: list[list[int]], placed_qubits: set[int], order: list[int], tq_zones: set[int], sq_zones: set[int]) list[int] #
A helper function to place the TQ operations.
- pytket.phir.placement.placement_check(ops: list[list[int]], tq_options: set[int], sq_options: set[int], state: list[int]) bool #
Ensure that the qubits end up in the right gating zones.
pytket.phir.qtm_machine module#
pytket.phir.routing module#
- exception pytket.phir.routing.PermutationError(lst: list[int])#
Bases:
Exception
Error raised by inverse() util function.
- exception pytket.phir.routing.TransportError(a: list[int], b: list[int])#
Bases:
Exception
Error raised by inverse() util function.
- pytket.phir.routing.inverse(lst: list[int]) list[int] #
Inverse of a permutation list.
If a[i] = x, then inverse(a)[x] = i.
- pytket.phir.routing.transport_cost(init: list[int], goal: list[int], swap_cost: float) float #
Cost of transport from init to goal.
This is based on the number of parallel swaps performed by Odd-Even Transposition Sort, which is the maximum distance that any qubit travels.
Module contents#
Init file for pytket-phir.