Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do nothing on Init gate instead of warning #166

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions pytket/phir/phirgen_parallel.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth removing the code duplication in the two matches, considering abstracting the match to a function?

Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,31 @@ def format_and_add_primary_commands(
groups2qops(fmt_g2q, ops)


def get_transport_time_for_gate(gate: str, machine: "Machine") -> float:
"""Return the transport time on the machine for the given gate type."""
match gate:
case "RZ" | "R1XY":
return machine.sq_time
case "RZZ":
return machine.tq_time
case "Measure":
return machine.meas_prep_time
case "Init":
return 0
case _:
logger.warning("Gate type %s not assigned a transport duration", gate)
return 0


def adjust_phir_transport_time(ops: list["JsonDict"], machine: "Machine") -> None:
"""Analyze the generated phir and adjust the transport time."""
adjustment = 0.0
for op in ops:
if "qop" in op:
match op["qop"]:
case "RZ" | "R1XY":
adjustment += machine.sq_time
case "RZZ":
adjustment += machine.tq_time
case "Measure":
adjustment += machine.meas_prep_time
case _:
logger.warning(
"Gate type %s not assigned a transport duration", op["qop"]
)
adjustment += get_transport_time_for_gate(op["qop"], machine)
if "block" in op and op["block"] == "qparallel":
first_op = op["ops"][0]["qop"]
match first_op:
case "RZ" | "R1XY":
adjustment += machine.sq_time
case "RZZ":
adjustment += machine.tq_time
case _:
logger.warning(
"Gate type %s not assigned a transport duration", first_op
)
adjustment += get_transport_time_for_gate(first_op, machine)
if "mop" in op and op["mop"] == "Transport":
cost, units = op["duration"]
op["duration"] = cost + adjustment, units
Expand Down