quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Test hash consistency of cirq objects loaded from a pickle #6677

Closed pavoljuhas closed 1 month ago

pavoljuhas commented 2 months ago

Ensure cirq objects passed as pickles in multiprocessing calls work consistently in dictionaries just as the in-process created objects.

Partially resolves #6674

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.83%. Comparing base (51e8c3d) to head (72217dc).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6677 +/- ## ======================================== Coverage 97.82% 97.83% ======================================== Files 1074 1075 +1 Lines 92187 92325 +138 ======================================== + Hits 90186 90323 +137 - Misses 2001 2002 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

pavoljuhas commented 1 month ago

@maffoo - I have addressed all comments, let me know if anything else is needed.

senecameeks commented 1 month ago

When I checkout to this PR and do a fresh install of Cirq, I get test errors for hash_from_pickle_test , do you know why that is?

FAILED cirq-core/cirq/protocols/hash_from_pickle_test.py::test_hash_from_pickle[/usr/local/google/home/smeeks/.virtualenvs/cirq-py3/lib/python3.11/site-packages/cirq_pasqal/json_test_data/PasqalDevice.json] - TypeError: unhashable type: 'list'
FAILED cirq-core/cirq/protocols/hash_from_pickle_test.py::test_hash_from_pickle[/usr/local/google/home/smeeks/.virtualenvs/cirq-py3/lib/python3.11/site-packages/cirq_rigetti/json_test_data/RigettiQCSAspenDevice.json] - TypeError: cannot pickle 'builtins.InstructionSetArchitecture' object
FAILED cirq-core/cirq/protocols/hash_from_pickle_test.py::test_hash_from_pickle[/usr/local/google/home/smeeks/.virtualenvs/cirq-py3/lib/python3.11/site-packages/cirq_google/json_test_data/cirq.google.QuantumExecutableGroup.json] - AssertionError: assert -1119203413633176159 == -1369517243038828412
FAILED cirq-core/cirq/protocols/hash_from_pickle_test.py::test_hash_from_pickle[/usr/local/google/home/smeeks/.virtualenvs/cirq-py3/lib/python3.11/site-packages/cirq_pasqal/json_test_data/PasqalVirtualDevice.json] - TypeError: unhashable type: 'list'
pavoljuhas commented 1 month ago

When I checkout to this PR and do a fresh install of Cirq, I get test errors for hash_from_pickle_test , do you know why that is?

FAILED cirq-core/cirq/protocols/hash_from_pickle_test.py::test_hash_from_pickle[/usr/local/google/home/smeeks/.virtualenvs/cirq-py3/lib/python3.11/site-packages/cirq_pasqal/json_test_data/PasqalDevice.json] - TypeError: unhashable type: 'list'
...

Thanks for pointing that out!

The test seems to be using installed sources rather than those from source repository. Please run the tests with check/pytest which adjusts PYTHONPATH to use the repo sources. (Alternatively, you can also source dev_tools/pypath in the shell for the same effect.)

That said the test should also pass if run w/r to an installed cirq, e.g., for a fresh environment

pip install ./cirq-{aqt,core,google,ionq,pasqal,rigetti,web} ./
pip install -r dev_tools/requirements/deps/pytest.txt
pytest --pyargs cirq.protocols.hash_from_pickle_test

This was not working, because the test assumed data locations as in the Cirq repo, but they are different when installed to site-packages. This should be fixed with f26dab5d647560145392da0225dafb1ce8064d03.