generated from CQCL/pytemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into issue-14-nje-phase-gates
- Loading branch information
Showing
10 changed files
with
73 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,48 @@ | ||
from pytket.phir.machine import Machine | ||
from pytket.phir.placement import optimized_place | ||
from pytket.phir.routing import transport_cost | ||
from pytket.phir.sharding.shard import Shard | ||
from pytket.phir.sharding.shard import Cost, Layer, Ordering, Shard | ||
from pytket.phir.sharding.shards2ops import parse_shards_naive | ||
|
||
|
||
def place_and_route( | ||
machine: Machine, | ||
shards: list[Shard], | ||
) -> list[tuple[list[int], list[Shard], float]]: | ||
machine: Machine | None = None, | ||
) -> list[tuple[Ordering, Layer, Cost]]: | ||
"""Get all the routing info needed for PHIR generation.""" | ||
shard_set = set(shards) | ||
circuit_rep, shard_layers = parse_shards_naive(shard_set) | ||
initial_order = list(range(machine.size)) | ||
if machine: | ||
initial_order = list(range(machine.size)) | ||
layer_num = 0 | ||
orders: list[list[int]] = [] | ||
layer_costs: list[float] = [] | ||
orders: list[Ordering] = [] | ||
layer_costs: list[Cost] = [] | ||
net_cost: float = 0.0 | ||
for layer in circuit_rep: | ||
order = optimized_place( | ||
layer, | ||
machine.tq_options, | ||
machine.sq_options, | ||
machine.size, | ||
initial_order, | ||
) | ||
orders.append(order) | ||
cost = transport_cost(initial_order, order, machine.qb_swap_time) | ||
layer_num += 1 | ||
initial_order = order | ||
layer_costs.append(cost) | ||
net_cost += cost | ||
if machine: | ||
for layer in circuit_rep: | ||
order = optimized_place( | ||
layer, | ||
machine.tq_options, | ||
machine.sq_options, | ||
machine.size, | ||
initial_order, | ||
) | ||
orders.append(order) | ||
cost = transport_cost(initial_order, order, machine.qb_swap_time) | ||
layer_num += 1 | ||
initial_order = order | ||
layer_costs.append(cost) | ||
net_cost += cost | ||
else: | ||
# If no machine object specified, | ||
# generic lists of qubits with no placement and no routing costs, | ||
# only the shards | ||
|
||
# If needed later, write a helper to find the number | ||
# of qubits needed in the circuit | ||
n = len(circuit_rep) | ||
orders = [[]] * n | ||
layer_costs = [0] * n | ||
|
||
# don't need a custom error for this, "strict" parameter will throw error if needed | ||
return list(zip(orders, shard_layers, layer_costs, strict=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
black==23.10.0 | ||
build==1.0.3 | ||
mypy==1.6.1 | ||
phir==0.1.3 | ||
phir==0.1.5 | ||
pre-commit==3.5.0 | ||
pytest==7.4.2 | ||
pytket-quantinuum==0.25.0 | ||
pytket==1.21.0 | ||
ruff==0.1.0 | ||
ruff==0.1.1 | ||
wheel==0.41.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters