Skip to content

Commit

Permalink
kartik comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Asa-Kosto-QTM committed Oct 17, 2023
1 parent 30a17cc commit bc31b85
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ docs/_build/
.pybuilder/
target/

# vscode
.vscode/

# Jupyter Notebook
.ipynb_checkpoints

Expand Down
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion pytket/phir/pandr.py → pytket/phir/place_and_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@typing.no_type_check
def place_and_route(machine: Machine, qasm: Circuit): # give type hint for return
def place_and_route(machine: Machine, qasm: Circuit):
"""Get all the routing info needed for PHIR generation."""
circuit = get_qasm_as_circuit(qasm)
sharder = Sharder(circuit)
Expand Down
15 changes: 13 additions & 2 deletions pytket/phir/placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def place( # noqa: PLR0912
raise PlacementCheckError


def optimized_place(
def optimized_place( # noqa: PLR0912
ops: list[list[int]],
tq_options: set[int],
sq_options: set[int],
Expand Down Expand Up @@ -209,7 +209,18 @@ def optimized_place(

# place the tq ops
order = place_tq_ops(tq_ops_sorted, placed_qubits, order, tq_zones, sq_zones)

# run a check to avoid unnecessary swaps
for zone in tq_zones:
# this condition will be true if there was a swap due to the order of qubits_used # noqa: E501
# in the shard creating the TQ op, even if those two qubits were already in a TQ zone # noqa: E501
# example: ops = [[0,1]] prev_state = [0,1,2,3] new order = [1,0,2,3]
# this check s to prevent the above situation
if (order[zone] == prev_state[zone + 1]) & (
order[zone + 1] == prev_state[zone]
):
swapped = order[zone + 1]
order[zone + 1] = order[zone]
order[zone] = swapped
# place the sq ops
for op in sq_ops:
q1 = op[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/data/qasm/eztest.qasm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include "hqslib1.inc";
qreg q[3];
creg c[3];

CX q[2], q[0];
CX q[0], q[2];
h q[0];
h q[1];
h q[2];
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pytket.phir.machine_class import Machine
from pytket.phir.pandr import place_and_route
from pytket.phir.place_and_route import place_and_route
from pytket.phir.placement import placement_check
from tests.sample_data import QasmFiles

Expand All @@ -11,10 +11,13 @@
1.0,
2.0,
)
# force machine options for this test, machines normally don't like odd numbers of qubits # noqa: E501
# force machine options for this test
# machines normally don't like odd numbers of qubits
machine.sq_options = {0, 1, 2}
# The type: ignores in this file are because mypy doesn't like the return type of place and route, # noqa: E501
# list[triple(list[int], list[Shard], float)]
output = place_and_route(machine, QasmFiles.eztest) # type: ignore [misc]

# print(output)
ez_ops_0 = [[0, 2], [1]]
ez_ops_1 = [[0], [2]]
state_0 = output[0][0] # type: ignore [misc]
Expand Down

0 comments on commit bc31b85

Please sign in to comment.