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

feature: device-specific gate validation for autoqasm programs #695

Merged
merged 22 commits into from
Sep 13, 2023

Conversation

rmshaffer
Copy link
Contributor

@rmshaffer rmshaffer commented Sep 8, 2023

Issue #, if available:

Description of changes:

  • Validate that all gates used are in the supportedOperations of the device properties.
  • Validate that verbatim blocks contain only native gates of the target device.
  • Validate that verbatim blocks reference only physical qubits.
  • Validate that verbatim blocks respect the connectivity of the target device.

Testing done:

  • Example notebook added with user scenario of custom native gate definitions and verbatim usage.
  • Tests added to cover new functionality.

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (a69c39b) 100.00% compared to head (b6891a0) 100.00%.

Additional details and impacted files
@@                Coverage Diff                 @@
##           feature/autoqasm      #695   +/-   ##
==================================================
  Coverage            100.00%   100.00%           
==================================================
  Files                   154       154           
  Lines                  9313      9376   +63     
  Branches               2014      2035   +21     
==================================================
+ Hits                   9313      9376   +63     
Files Changed Coverage Δ
src/braket/experimental/autoqasm/api.py 100.00% <100.00%> (ø)
src/braket/experimental/autoqasm/errors.py 100.00% <100.00%> (ø)
...experimental/autoqasm/instructions/instructions.py 100.00% <100.00%> (ø)
...raket/experimental/autoqasm/instructions/qubits.py 100.00% <100.00%> (ø)
...c/braket/experimental/autoqasm/program/__init__.py 100.00% <100.00%> (ø)
...rc/braket/experimental/autoqasm/program/pragmas.py 100.00% <100.00%> (ø)
...rc/braket/experimental/autoqasm/program/program.py 100.00% <100.00%> (ø)
src/braket/experimental/autoqasm/pulse/pulse.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rmshaffer rmshaffer marked this pull request as ready for review September 11, 2023 15:49
src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
valid_target_qubits = connectivity_graph[start_qubit]
for qubit in qubits[1:]:
target_qubit = f"{int(qubit)}"
if target_qubit not in valid_target_qubits:
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding, if the qubit targets are q[0], q[1], q[2], does this only check if q[2] and q[0], q[1] and q[0] are connected? Should it also check whether q[1] and q[2] are connected?

Copy link
Contributor Author

@rmshaffer rmshaffer Sep 11, 2023

Choose a reason for hiding this comment

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

Your understanding is correct. The connectivity graph is directed, so specifically this is checking that the edges q[0]->q[1] and q[0]->q[2] exist.

I actually don't know the desired behavior, because I am not aware of any examples of what the connectivity graph looks like for native 3-qubit gates. For example, imagine a device has a native CCNOT gate - I'm not sure what the connectivity graph should look like for this.

src/braket/experimental/autoqasm/program/program.py Outdated Show resolved Hide resolved
src/braket/experimental/autoqasm/instructions/qubits.py Outdated Show resolved Hide resolved
device = self.get_target_device()
if device:
native_gates = self._normalize_gate_names(device.properties.paradigm.nativeGateSet)
allowed_verbatim_gates = self._gates_defined.union(native_gates)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the validation work for defined gates that does not use native gates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but now I've added tests which verify this - good catch.

@rmshaffer rmshaffer merged commit 202a817 into feature/autoqasm Sep 13, 2023
28 checks passed
@rmshaffer rmshaffer deleted the rmshaffer/autoqasm-device-validation branch September 13, 2023 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants