jpmorganchase / QOKit

QOKit
https://www.jpmorgan.com/technology/applied-research
Apache License 2.0
44 stars 21 forks source link

LABS using circuit? #28

Closed jmlarson1 closed 7 months ago

jmlarson1 commented 8 months ago

Is there an example where QOKit evaluates the LABS circuit instead of the statevector simulation?

In the qaoa_objective_labs file: https://github.com/jpmorganchase/QOKit/blob/29e010c420436746534e86a6da5b1a0492ef0161/qokit/qaoa_objective_labs.py#L19

I see that the circuit is imported, but I don't see where it is ever used/evaluated? Isn't this necessary for large N?

(I see QOKit has this implemented for portfolio optimization though.)

@mmenickelly

rsln-s commented 8 months ago

@jmlarson1, thank you for raising this issue!

This is indeed a bug as the support for Qiskit simulation leveraging the parameterized QAOA circuit appears to have been lost. Somehow, this has escaped our test coverage, which is unfortunate.

The short of it is that simply instantiating parameterized QAOA circuit and passing it to get_qaoa_objective should work.

We will aim to resolve this soon (though possibly after the holidays).

jmlarson1 commented 8 months ago

Many of us, including @Shagun-G are interested in having this functionality

rsln-s commented 8 months ago

@jmlarson1 @Shagun-G @mmenickelly: I added a quick hot fix in #30 that should address your needs. Here is a quick test that the implementation is correct:

import numpy as np
from qokit.parameter_utils import get_best_known_parameters_for_LABS_wrt_overlap_for_p
from qokit.qaoa_objective_labs import get_qaoa_labs_objective

N = 7
p = 8
gamma, beta = get_best_known_parameters_for_LABS_wrt_overlap_for_p(N, p)

f1 = get_qaoa_labs_objective(N, p, parameterization="gamma beta", simulator="auto")
f2 = get_qaoa_labs_objective(N, p, parameterization="gamma beta", simulator="qiskit")

assert np.isclose(f1(gamma, beta), f2(gamma, beta))
jmlarson1 commented 8 months ago

Thank you. I need to try a different build because I get an error:

Traceback (most recent call last):
  File "/home/jlarson/QOKit/ruslan_rocks.py", line 2, in <module>
    from qokit.parameter_utils import get_best_known_parameters_for_LABS_wrt_overlap_for_p
  File "/home/jlarson/QOKit/qokit/__init__.py", line 6, in <module>
    from .qaoa_objective import get_qaoa_objective
  File "/home/jlarson/QOKit/qokit/qaoa_objective.py", line 10, in <module>
    import numba.cuda
  File "/home/jlarson/.local/lib/python3.10/site-packages/numba/__init__.py", line 55, in <module>
    _ensure_critical_deps()
  File "/home/jlarson/.local/lib/python3.10/site-packages/numba/__init__.py", line 42, in _ensure_critical_deps
    raise ImportError("Numba needs NumPy 1.24 or less")
ImportError: Numba needs NumPy 1.24 or less
rsln-s commented 8 months ago

I would suggest trying to re-install from source in a clean venv/conda environment.

rsln-s commented 8 months ago

@jmlarson1 was your issue resolved by #30?

jmlarson1 commented 7 months ago

Yes! The example works for me. Thank you.

Is there some obvious way to pass the desired number of shots to the get_qaoa_labs_objective method? f1(gamma, beta, shots=1000) would be nice, and would seem to match qokit/qaoa_circuit_portfolio.py where one can execute(circuit, backend, shots=n_trials).

But that doesn't work (and I don't even see that kwargs are passed to get_qaoa_labs_objective).

rsln-s commented 7 months ago

The simulator does not support emulating shot-based noise. Only exact expectation value is returned currently.

jmlarson1 commented 7 months ago

That is understandable. Is there a shot-based get_qaoa_labs_objective (without a simulator, perhaps)?