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

Bugfix: QPU qubit overflow #108

Merged
merged 14 commits into from
Nov 16, 2022
Merged

Bugfix: QPU qubit overflow #108

merged 14 commits into from
Nov 16, 2022

Conversation

shahidee44
Copy link
Collaborator

@shahidee44 shahidee44 commented Oct 25, 2022

Description

  • Added n_qubits attribute to DeviceQiskit that extracts the maximum number of qubits compatible for the particular IBMQ Backend selected

  • Added qubit number check between CircuitParams Object and DeviceQiskit. An Exception is raised if the number of qubits in the backend is less than the number of qubits required to create the circuit.

  • Updated unittests in test_qiskit_qpu.py

  • Added n_qubits attribute to DeviceAWS that extracts the maximum number of qubits compatible for the particular Braket Backend selected. (Since not all backends may have the total number of qubits available, a function that catches the possibility that the number of qubits is not available is added for this Device object.)

  • Added qubit number check between CircuitParams Object and DeviceAWS. Exception is raised as above.

  • Updated unittests in test_braket_qpu.py

  • Added n_qubits attribute to DevicePyQuil that extracts the maximum number of qubits compatible for the particular PyQuil QPU Backend selected.

  • Added qubit number check between CircuitParams Object and DevicePyquil. Exception is raised as above.

  • The above resolves PR Unintended behaviour/error-catching bug when using workflows with IBM backend #105

  • Updated Exception catching in OptimizeVQA should help prevent silent crashes.

  • Updated unittests to check for silent errors.

  • Minor changes to OptimizeVQAs optimize method. (Return is moved outside of the try/except/finally loop. If it is within the finally tab, the exception we want is not raised.) This resolves PR Optimize function crashes silently #132

  • Renamed test_optimisers.py to test_optimizers.py

Checklist

  • I have performed a self-review of my code.
  • I have commented my code and used numpy-style docstrings
  • My changes generate no new warnings
  • I have added/updated tests to make sure bugfix/feature works.
  • New and existing unit tests pass locally with my changes.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Name the new unit-tests that you have added along with this change.

test_all.py

@shahidee44 shahidee44 linked an issue Oct 25, 2022 that may be closed by this pull request
2 tasks
@codecov
Copy link

codecov bot commented Oct 25, 2022

Codecov Report

Merging #108 (03681c2) into dev (80b0b6b) will decrease coverage by 0.28%.
The diff coverage is 35.55%.

@@            Coverage Diff             @@
##              dev     #108      +/-   ##
==========================================
- Coverage   87.30%   87.01%   -0.29%     
==========================================
  Files          67       67              
  Lines        8924     9006      +82     
==========================================
+ Hits         7791     7837      +46     
- Misses       1133     1169      +36     
Impacted Files Coverage Δ
openqaoa/backends/qpus/qaoa_braket_qpu.py 21.11% <0.00%> (-0.99%) ⬇️
openqaoa/backends/qpus/qaoa_qiskit_qpu.py 21.17% <0.00%> (-0.52%) ⬇️
tests/test_qpu_braket.py 11.28% <11.42%> (+0.46%) ⬆️
openqaoa/devices.py 47.26% <13.33%> (-1.32%) ⬇️
tests/test_qpu_devices.py 33.33% <15.78%> (+2.89%) ⬆️
tests/test_qpu_qiskit.py 11.64% <25.00%> (+0.62%) ⬆️
openqaoa/optimizers/training_vqa.py 80.71% <50.00%> (-0.54%) ⬇️
tests/test_pyquil_qvm.py 99.23% <93.33%> (-0.77%) ⬇️
openqaoa/backends/qpus/qaoa_pyquil_qpu.py 92.85% <100.00%> (+0.17%) ⬆️
openqaoa/workflows/optimizer.py 89.69% <100.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Q-lds Q-lds added the bug Something isn't working label Nov 2, 2022
@shahidee44 shahidee44 changed the title Bugfix: Qiskit QPU qubit overflow Bugfix: QPU qubit overflow Nov 4, 2022
@shahidee44
Copy link
Collaborator Author

Comments on PyQuil Backend:

The backend does not fail silently like the others when a larger circuit is specified than is supported by the actual QPU.
The main reason for this is that within the init function of the PyQuilQPUBackend Class, the paramteric circuit is compiled for the particular QPU selected. This compilation step throws the error. Since the error is not thrown within the get_counts method, the code does not silently fail.
The new addition to the code just makes sure that the failure due to "qubit overflow" has a consistent message throughout all the backends.

Additional Comments:
With the slightly different design of the DevicePyQuil, n_qubits attribute assigned at the initialisation of the class since this information is readily available. This is not True for DeviceQiskit and DeviceAWS where the check_connection() must first be executed before n_qubits becomes available.
There is no direct effect in the code when n_qubits is assigned. Though we may want to consider if it might be appropriate to have similar behaviours for all Device Objects.

@shahidee44 shahidee44 marked this pull request as ready for review November 7, 2022 10:02
@shahidee44 shahidee44 linked an issue Nov 15, 2022 that may be closed by this pull request
@vishal-ph vishal-ph merged commit 0c9eca9 into dev Nov 16, 2022
@vishal-ph vishal-ph deleted the fix_qiskit_qpu_bug branch November 16, 2022 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants