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

Added support for EstimatorV2 primitives #48

Open
wants to merge 14 commits into
base: update-V2
Choose a base branch
from

Conversation

OkuyanBoga
Copy link
Owner

Added support for V2 primitives for estimator_qnn and gradients.

TO DO:

  • Writing relative tests for V2.
  • Check spelling etc.

Copy link
Owner Author

@OkuyanBoga OkuyanBoga left a comment

Choose a reason for hiding this comment

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

@edoaltamura @oscar-wallis please do corrections according to my reviews.

)
results = job.result()
elif isinstance(self._estimator, BaseEstimatorV2):
job = self._estimator.run(PUBs, precision=0.001, **options)
Copy link
Owner Author

Choose a reason for hiding this comment

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

precision parameter might introduce issues for tests, we need to think about how to make stable tests for V2.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Qiskit uses a default value of 0.0: https://github.com/Qiskit/qiskit/blob/8ccbc8d28f34e3f2e1e0e8cbb66c4da95754b341/qiskit/primitives/statevector_estimator.py#L113
So to make tests reproducible we could fetch

precision=self._default_precision

Since we are already within the BaseEstimatorV2 case, we can assume that _default_precision is defined in the superclass.

Comment on lines 159 to 160
self.num_qubits = circuit.num_qubits
print('Warning: No number of qubits provided, using it from provided circuit, if the circuit is transpiled this can be wrong and cause issues.')
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is required since we might lose information about actual number of qubits of the circuit after the transpilation, not sure if it can simply be retrieved from transpiled_circuit.

qiskit_machine_learning/neural_networks/estimator_qnn.py Outdated Show resolved Hide resolved
OkuyanBoga and others added 13 commits September 30, 2024 14:10
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
…mator_gradient.py

Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
…mator_gradient.py

Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
…mator_gradient.py

Co-authored-by: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com>
@@ -23,6 +23,9 @@
from qiskit_machine_learning.circuit.library import QNNCircuit

from qiskit_machine_learning.neural_networks.estimator_qnn import EstimatorQNN
from qiskit_ibm_runtime import Session, EstimatorV2
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

CASE_DATA = {
Copy link
Owner Author

Choose a reason for hiding this comment

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

@oscar-wallis Can you please copy paste this as CASE_DATA_V2 and adapt for V2?

self,
TestCase,
):
self.backend = GenericBackendV2(num_qubits=8)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Change this to num_qubits=3 or 4

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