-
Notifications
You must be signed in to change notification settings - Fork 21
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
Cleaning up device interface #241
Open
thierry-martinez
wants to merge
1
commit into
TeamGraphix:master
Choose a base branch
from
thierry-martinez:cleaning_device_interface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ class PatternRunner: | |
Executes the measurement pattern. | ||
""" | ||
|
||
def __init__(self, pattern: Pattern, backend: str = "ibmq", **kwargs) -> None: | ||
def __init__(self, pattern: Pattern, backend: str = "ibmq", instance: str | None = None, resource: str | None = None, save_statevector: bool = False, optimizer_level: int = 1, shots: int = 1024) -> None: | ||
"""Instantiate a pattern runner. | ||
|
||
Parameters | ||
|
@@ -26,35 +26,39 @@ def __init__(self, pattern: Pattern, backend: str = "ibmq", **kwargs) -> None: | |
MBQC pattern to be executed. | ||
backend: str | ||
execution backend (optional, default is 'ibmq') | ||
kwargs: dict | ||
keyword args for specified backend. | ||
instance: str | None | ||
instance name (optional, backend specific) | ||
resource: str | None | ||
resource name (optional, backend specific) | ||
instance: str | None | ||
instance name (optional, backend specific) | ||
save_statevector: bool | ||
whether to save the statevector before the measurements of output qubits (optional, default is 'False', backend specific) | ||
optimizer_level: int | ||
optimizer level (optional, default is '1', backend specific) | ||
shots: int | ||
number of shots (optional, default is '1024', backend specific) | ||
""" | ||
self.pattern = pattern | ||
self.backend_name = backend | ||
|
||
if self.backend_name == "ibmq": | ||
try: | ||
from graphix_ibmq.runner import IBMQBackend | ||
except Exception as e: | ||
except ImportError as e: | ||
raise ImportError( | ||
"Failed to import graphix_ibmq. Please install graphix_ibmq by `pip install graphix-ibmq`." | ||
) from e | ||
self.backend = IBMQBackend(pattern) | ||
try: | ||
instance = kwargs.get("instance", "ibm-q/open/main") | ||
resource = kwargs.get("resource", None) | ||
save_statevector = kwargs.get("save_statevector", False) | ||
optimization_level = kwargs.get("optimizer_level", 1) | ||
|
||
self.backend.get_backend(instance, resource) | ||
self.backend.to_qiskit(save_statevector) | ||
self.backend.transpile(optimization_level) | ||
self.shots = kwargs.get("shots", 1024) | ||
except Exception: | ||
save_statevector = kwargs.get("save_statevector", False) | ||
optimization_level = kwargs.get("optimizer_level", 1) | ||
self.backend.to_qiskit(save_statevector) | ||
self.shots = kwargs.get("shots", 1024) | ||
kwargs_get_backend = {} | ||
if instance is not None: | ||
kwargs_get_backend["instance"] = instance | ||
if resource is not None: | ||
kwargs_get_backend["resource"] = resource | ||
self.backend.get_backend(**kwargs_get_backend) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: interface here is different in the latest commit of |
||
self.backend.to_qiskit(save_statevector) | ||
self.backend.transpile(optimizer_level) | ||
self.shots = shots | ||
else: | ||
raise ValueError("unknown backend") | ||
|
||
|
Oops, something went wrong.
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.
This update sadly does not contribute to type-stable interface (better than
**kwargs
though).My ideas:
= "ibmq"
: we do not need to add information about the name of the class inheritingABC
.