generated from CQCL/pytemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Rebasing initial implementation #7
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e108592
Initial approach outline
nealerickson-qtm 7dc92df
test implementation
nealerickson-qtm 9ffff40
Merge branch 'add-api' into rebase-gates
nealerickson-qtm c1a25ce
ruff cleanup
nealerickson-qtm ebe4c65
adding api
nealerickson-qtm c0565ad
using enum
nealerickson-qtm 46e34af
adding test for h1-1
nealerickson-qtm 2dbb1ea
removing relative imports
nealerickson-qtm b495d87
relative import:
nealerickson-qtm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,6 @@ repos: | |
additional_dependencies: [ | ||
pytest, | ||
pytket==1.20.1, | ||
pytket-quantinuum==0.23.0, | ||
types-setuptools, | ||
] |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pytket.circuit import Circuit | ||
|
||
from .qtm_machine import QtmMachine | ||
from .rebasing.rebaser import rebase_to_qtm_machine | ||
from .sharding.sharder import Sharder | ||
|
||
|
||
def pytket_to_phir( | ||
Jonhas-qtm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
|
||
:param circuit: Circuit object to be converted | ||
:param qtm_machine: (Optional) Quantinuum machine architecture to rebase against | ||
|
||
Returns: | ||
------- | ||
PHIR JSON as a str | ||
""" | ||
if qtm_machine: | ||
circuit = rebase_to_qtm_machine(circuit, qtm_machine.value) | ||
|
||
sharder = Sharder(circuit) | ||
shards = sharder.shard() | ||
|
||
# TODO: Pass shards[] into placement, routing, etc | ||
# TODO: Convert to PHIR JSON spec and return | ||
|
||
return str(shards) # Just returning fake string for now |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from enum import Enum | ||
|
||
|
||
class QtmMachine(Enum): | ||
"""Available machine architectures.""" | ||
|
||
H1_1 = "H1-1" | ||
H1_2 = "H1-2" | ||
H2_1 = "H2-1" |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pytket.circuit import Circuit | ||
from pytket.extensions.quantinuum.backends.api_wrappers import QuantinuumAPIOffline | ||
from pytket.extensions.quantinuum.backends.quantinuum import ( | ||
QuantinuumBackend, | ||
) | ||
|
||
|
||
def rebase_to_qtm_machine(circuit: Circuit, qtm_machine: str) -> Circuit: | ||
"""Rebases a circuit's gate to the gate set appropriate for the given machine.""" | ||
qapi_offline = QuantinuumAPIOffline() | ||
backend = QuantinuumBackend( | ||
device_name=qtm_machine, | ||
machine_debug=False, | ||
api_handler=qapi_offline, # type: ignore [arg-type] | ||
) | ||
# Optimization level 0 includes rebasing and little else | ||
# see: https://cqcl.github.io/pytket-quantinuum/api/#default-compilation | ||
return backend.get_compiled_circuit(circuit, 0) |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ pre-commit==3.4.0 | |
pytest==7.4.2 | ||
ruff==0.0.292 | ||
pytket==1.20.1 | ||
pytket-quantinuum==0.23.0 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pytket.phir.api import pytket_to_phir | ||
from pytket.phir.qtm_machine import QtmMachine | ||
|
||
from .sample_data import QasmFiles, get_qasm_as_circuit | ||
|
||
|
||
class TestApi: | ||
def test_pytket_to_phir_no_machine(self) -> None: | ||
circuit = get_qasm_as_circuit(QasmFiles.baby) | ||
|
||
phir = pytket_to_phir(circuit) | ||
|
||
# TODO: Make this test more valuable once PHIR is actually returned | ||
print(phir) | ||
Jonhas-qtm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert len(phir) > 0 | ||
|
||
def test_pytket_to_phir_h1_1(self) -> None: | ||
circuit = get_qasm_as_circuit(QasmFiles.baby) | ||
|
||
phir = pytket_to_phir(circuit, QtmMachine.H1_1) | ||
|
||
# TODO: Make this test more valuable once PHIR is actually returned | ||
print(phir) | ||
assert len(phir) > 0 |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pytket.circuit import Circuit, OpType | ||
from pytket.phir.rebasing.rebaser import rebase_to_qtm_machine | ||
|
||
from .sample_data import QasmFiles, get_qasm_as_circuit | ||
|
||
EXPECTED_GATES = [ | ||
OpType.Measure, | ||
OpType.Rz, | ||
OpType.PhasedX, | ||
OpType.ZZPhase, | ||
] | ||
|
||
|
||
class TestRebaser: | ||
def test_rebaser_happy_path_arc1a(self) -> None: | ||
circ = get_qasm_as_circuit(QasmFiles.baby) | ||
rebased: Circuit = rebase_to_qtm_machine(circ, "H1-1") | ||
|
||
print(rebased) | ||
for command in rebased.get_commands(): | ||
print(command) | ||
if command.op.is_gate(): | ||
assert command.op.type in EXPECTED_GATES |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than doing this form of relative imports, we should be importing from the actual package