-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: update-V2
Are you sure you want to change the base?
Conversation
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.
@edoaltamura @oscar-wallis please do corrections according to my reviews.
qiskit_machine_learning/gradients/param_shift/param_shift_estimator_gradient.py
Show resolved
Hide resolved
) | ||
results = job.result() | ||
elif isinstance(self._estimator, BaseEstimatorV2): | ||
job = self._estimator.run(PUBs, precision=0.001, **options) |
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.
precision parameter might introduce issues for tests, we need to think about how to make stable tests for V2.
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.
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.
qiskit_machine_learning/gradients/param_shift/param_shift_estimator_gradient.py
Show resolved
Hide resolved
qiskit_machine_learning/gradients/spsa/spsa_estimator_gradient.py
Outdated
Show resolved
Hide resolved
qiskit_machine_learning/gradients/spsa/spsa_estimator_gradient.py
Outdated
Show resolved
Hide resolved
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.') |
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 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/gradients/param_shift/param_shift_estimator_gradient.py
Outdated
Show resolved
Hide resolved
qiskit_machine_learning/gradients/param_shift/param_shift_estimator_gradient.py
Outdated
Show resolved
Hide resolved
qiskit_machine_learning/gradients/param_shift/param_shift_estimator_gradient.py
Outdated
Show resolved
Hide resolved
qiskit_machine_learning/gradients/spsa/spsa_estimator_gradient.py
Outdated
Show resolved
Hide resolved
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 = { |
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.
@oscar-wallis Can you please copy paste this as CASE_DATA_V2 and adapt for V2?
self, | ||
TestCase, | ||
): | ||
self.backend = GenericBackendV2(num_qubits=8) |
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.
Change this to num_qubits=3 or 4
Added support for V2 primitives for estimator_qnn and gradients.
TO DO: