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

fix precomputation in get_objective_maxcut.py #11

Merged
merged 6 commits into from
Sep 9, 2023

Conversation

danlkv
Copy link
Contributor

@danlkv danlkv commented Sep 8, 2023

fixes #9

@danlkv danlkv requested a review from rsln-s September 8, 2023 21:56
@rsln-s
Copy link
Contributor

rsln-s commented Sep 9, 2023

The tests are failing because the GPU test is not skipped properly if no GPU is available (see logs in the check above):

=================================== FAILURES ===================================
____________________________ test_maxcut_precompute ____________________________

    def test_maxcut_precompute():
        N = 4
        G = nx.random_regular_graph(3, N)
        print(G.edges())
        for u, v, w in G.edges(data=True):
            w["weight"] = np.random.rand()
        precomputed_cuts = precompute_energies(maxcut_obj, N, w=get_adjacency_matrix(G))
        simclass = qokit.fur.choose_simulator("gpu")
        terms = get_maxcut_terms(G)
>       sim = simclass(N, terms=terms)

tests/test_maxcut.py:93: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
qokit/fur/nbcuda/qaoa_simulator.py:24: in __init__
    super().__init__(n_qubits, costs, terms)
qokit/fur/qaoa_simulator_base.py:63: in __init__
    self._hc_diag = self._diag_from_terms(terms)
qokit/fur/nbcuda/qaoa_simulator.py:31: in _diag_from_terms
    out = numba.cuda.device_array(self.n_states, dtype="float32")  # type: ignore
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/numba/cuda/cudadrv/devices.py:231: in _require_cuda_context
    with _runtime.ensure_context():
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/contextlib.py:119: in __enter__
    return next(self.gen)
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/numba/cuda/cudadrv/devices.py:121: in ensure_context
    with driver.get_active_context():
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/numba/cuda/cudadrv/driver.py:499: in __enter__
    driver.cuCtxGetCurrent(byref(hctx))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

for u, v, w in G.edges(data=True):
w["weight"] = np.random.rand()
precomputed_cuts = precompute_energies(maxcut_obj, N, w=get_adjacency_matrix(G))
simclass = qokit.fur.choose_simulator("gpu")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this function call fail if no GPU is present? I checked on a CPU-only instance, and it does not throw an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

precompute_energies is the CPU-only function, so it shouldn't fail. If you use the simulator from choose_simulator("gpu") it should fail on initialization.

Copy link
Contributor

Choose a reason for hiding this comment

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

Github comments are a bit ambiguous; I was referring to line 91 in particular. Running the following two lines in a CPU-only instance does not throw an error:

import qokit
qokit.fur.choose_simulator("gpu")

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, this is expected, since choose_simulator returns the class, which is then used in later steps of simulation. Using this class will raise an error

Copy link
Contributor

@rsln-s rsln-s left a comment

Choose a reason for hiding this comment

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

Tests should pass both on CPU and GPU before the review is requested

@danlkv danlkv requested a review from rsln-s September 9, 2023 16:22
Copy link
Contributor

@rsln-s rsln-s left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing promptly!

@danlkv danlkv merged commit 46b1f51 into main Sep 9, 2023
12 checks passed
@alex124585 alex124585 deleted the fix/9_objective_gpu_precompute branch September 20, 2023 20:41
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.

get_qaoa_maxcut_objective does not use GPU precomputation of energy when graph G is passed
2 participants