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

Parallel ops #53

Merged
merged 30 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
27d45b0
parallel operations and cli option
Asa-Kosto-QTM Dec 5, 2023
af0a381
mypy and ruff
Asa-Kosto-QTM Dec 5, 2023
77e0789
parallel execution is default option with a machine object
Asa-Kosto-QTM Dec 6, 2023
fc17b81
removed unused gate angles reference dict
Asa-Kosto-QTM Dec 6, 2023
642bf90
build: update phir version for parallel ops support
qartik Dec 6, 2023
b618646
whitespace cli.py
Asa-Kosto-QTM Dec 6, 2023
fdd1fc3
phirgen whitespace
Asa-Kosto-QTM Dec 6, 2023
85d466c
Merge branch 'parallel-ops' of https://github.com/CQCL/pytket-phir in…
Asa-Kosto-QTM Dec 6, 2023
8cd6f09
removed duplicate code from phirgen.py
Asa-Kosto-QTM Dec 6, 2023
39c499a
remove unused value
Asa-Kosto-QTM Dec 6, 2023
ce3af00
comments
Asa-Kosto-QTM Dec 6, 2023
ddb74b4
conflict
Asa-Kosto-QTM Dec 6, 2023
c92b65f
TYPE_CHECKING
Asa-Kosto-QTM Dec 6, 2023
3283197
test cases for BV and brickwork circuit
Asa-Kosto-QTM Dec 6, 2023
8e9d3f4
made function for decls code to avoid duplication, smaller test case …
Asa-Kosto-QTM Dec 6, 2023
4f839fb
comment formatting
Asa-Kosto-QTM Dec 7, 2023
3277b6d
comment formatting
Asa-Kosto-QTM Dec 7, 2023
14e81c8
fix: better fixes for typing
qartik Dec 7, 2023
1a0b3b3
comments
Asa-Kosto-QTM Dec 7, 2023
0190a6b
Merge branch 'main' into parallel-ops
Asa-Kosto-QTM Dec 8, 2023
62073f3
Merge branch 'main' into parallel-ops
qartik Dec 11, 2023
ab813a6
Merge branch 'main' into parallel-ops
Asa-Kosto-QTM Dec 12, 2023
3b19dc3
pll tk2 and test
Asa-Kosto-QTM Dec 12, 2023
6400704
merge conflicts
Asa-Kosto-QTM Dec 12, 2023
5b6534f
Merge branch 'parallel-ops' of https://github.com/CQCL/pytket-phir in…
Asa-Kosto-QTM Dec 12, 2023
e5f38d1
Merge branch 'main' into parallel-ops
qartik Dec 12, 2023
dfb740e
Merge branch 'main' into parallel-ops
Asa-Kosto-QTM Dec 12, 2023
2ed84d9
fix: resolve name conflict between local Bit and tket Bit
qartik Dec 12, 2023
a35e943
renamed pll_test files
Asa-Kosto-QTM Dec 12, 2023
72c4224
Merge branch 'parallel-ops' of https://github.com/CQCL/pytket-phir in…
Asa-Kosto-QTM Dec 12, 2023
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
4 changes: 0 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@ warn_unused_configs = true

[mypy-tests.*]
disallow_untyped_defs = false

[mypy-pytket.phir.phirgen.*]
disallow_any_expr = false
disallow_any_explicit = false
13 changes: 6 additions & 7 deletions pytket/phir/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pytket.circuit import Circuit

from .phirgen import genphir
from .phirgen_parallel import genphir_parallel
from .place_and_route import place_and_route
from .qtm_machine import QTM_MACHINES_MAP, QtmMachine
from .rebasing.rebaser import rebase_to_qtm_machine
Expand All @@ -26,10 +27,7 @@
logger = logging.getLogger(__name__)


def pytket_to_phir(
circuit: Circuit,
qtm_machine: QtmMachine | None = None,
) -> str:
def pytket_to_phir(circuit: Circuit, qtm_machine: QtmMachine | None = None) -> str:
qciaran marked this conversation as resolved.
Show resolved Hide resolved
"""Converts a pytket circuit into its PHIR representation.

This can optionally include rebasing against a Quantinuum machine architecture.
Expand Down Expand Up @@ -59,9 +57,10 @@ def pytket_to_phir(
# The function is called, but the output is just filled with 0s
logger.debug("Performing placement and routing...")
placed = place_and_route(shards, machine)

phir_json = genphir(placed, machine_ops=bool(machine))

if machine:
phir_json = genphir_parallel(placed, machine)
else:
phir_json = genphir(placed, machine_ops=bool(machine))
if logger.getEffectiveLevel() <= logging.INFO:
print(PHIRModel.model_validate_json(phir_json)) # type: ignore[misc]
return phir_json
75 changes: 42 additions & 33 deletions pytket/phir/phirgen.py
qartik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
##############################################################################

# mypy: disable-error-code="misc"

import json
import logging
from collections.abc import Sequence
Expand All @@ -14,7 +16,8 @@
import pytket.circuit as tk
from phir.model import PHIRModel
from pytket.circuit.logic_exp import RegWiseOp
from pytket.unit_id import UnitID
from pytket.unit_id import Bit as tkBit
from pytket.unit_id import Qubit, UnitID

from .sharding.shard import Cost, Ordering, ShardLayer

Expand Down Expand Up @@ -90,7 +93,6 @@ def convert_subcmd(op: tk.Op, cmd: tk.Command) -> dict[str, Any]:
"returns": [arg_to_bit(cmd.bits[0])],
"args": [arg_to_bit(cmd.args[0])],
}

case (
"CX"
| "CY"
Expand Down Expand Up @@ -235,6 +237,43 @@ def append_cmd(cmd: tk.Command, ops: list[dict[str, Any]]) -> None:
ops.append(op)


def get_decls(qbits: set[Qubit], cbits: set[tkBit]) -> list[dict[str, str | int]]:
"""Format the qvar and cvar define PHIR elements."""
# TODO(kartik): this may not always be accurate
# https://github.com/CQCL/pytket-phir/issues/24
qvar_dim: dict[str, int] = {}
for qbit in qbits:
qvar_dim.setdefault(qbit.reg_name, 0)
qvar_dim[qbit.reg_name] += 1

cvar_dim: dict[str, int] = {}
for cbit in cbits:
cvar_dim.setdefault(cbit.reg_name, 0)
cvar_dim[cbit.reg_name] += 1

decls: list[dict[str, str | int]] = [
{
"data": "qvar_define",
"data_type": "qubits",
"variable": qvar,
"size": dim,
}
for qvar, dim in qvar_dim.items()
]

decls += [
{
"data": "cvar_define",
"data_type": "u32",
"variable": cvar,
"size": dim,
}
for cvar, dim in cvar_dim.items()
]

return decls


def genphir(
inp: list[tuple[Ordering, ShardLayer, Cost]], *, machine_ops: bool = True
) -> str:
Expand Down Expand Up @@ -269,37 +308,7 @@ def genphir(
},
)

# TODO(kartik): this may not always be accurate
# https://github.com/CQCL/pytket-phir/issues/24
qvar_dim: dict[Var, int] = {}
for qbit in qbits:
qvar_dim.setdefault(qbit.reg_name, 0)
qvar_dim[qbit.reg_name] += 1

cvar_dim: dict[Var, int] = {}
for cbit in cbits:
cvar_dim.setdefault(cbit.reg_name, 0)
cvar_dim[cbit.reg_name] += 1

decls: list[dict[str, str | int]] = [
{
"data": "qvar_define",
"data_type": "qubits",
"variable": qvar,
"size": dim,
}
for qvar, dim in qvar_dim.items()
]

decls += [
{
"data": "cvar_define",
"data_type": "u32",
"variable": cvar,
"size": dim,
}
for cvar, dim in cvar_dim.items()
]
decls = get_decls(qbits, cbits)

phir["ops"] = decls + ops
PHIRModel.model_validate(phir)
Expand Down
Loading