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

Switch default circuit unitary/sim precision from np.complex128 to np.complex64 #1030

Closed
Strilanc opened this issue Oct 19, 2018 · 11 comments · Fixed by #5426
Closed

Switch default circuit unitary/sim precision from np.complex128 to np.complex64 #1030

Strilanc opened this issue Oct 19, 2018 · 11 comments · Fixed by #5426
Assignees
Labels
area/circuits area/performance area/simulation BREAKING CHANGE For pull requests that are important to mention in release notes. complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor kind/feature-request Describes new functionality triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@Strilanc
Copy link
Contributor

Strilanc commented Oct 19, 2018

For NISQ circuits, the reduced precision isn't particularly relevant but the speed gains are.

@dabacon
Copy link
Collaborator

dabacon commented May 1, 2020

The simulators currently use np.complex64 but there are other places where the default is still np.complex128.

@dabacon
Copy link
Collaborator

dabacon commented Jun 1, 2020

The places where it needs to be changed are circuit.unitary and circuit.final_state_vector.

@balopat balopat added BREAKING CHANGE For pull requests that are important to mention in release notes. complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. area/circuits area/performance area/simulation kind/feature-request Describes new functionality triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on labels Sep 25, 2020
@diabhiue
Copy link

diabhiue commented Oct 7, 2021

As discussed in Cirq-cync, can someone please assign me here as I don't have permissions?

@vtomole
Copy link
Collaborator

vtomole commented Oct 7, 2021

@diabhiue I've assigned you.

@vtomole
Copy link
Collaborator

vtomole commented Oct 27, 2021

@diabhiue Do your new changes actually improve the performance?

@diabhiue
Copy link

@vtomole, I tried running ./check/asv_run for performance tests(post changes). Initially, it asked for system info (for initial set up) which was chosen by default, but it failed while running. Below is the error message. How can I resolve this?

Error message

(cirq-py3) ~/projects/Cirq(1030 ✗) ./check/asv_run 
· No executable found for python 3.6
· No executable found for python 3.7
· Creating environments
· Discovering benchmarks
·· Uninstalling from virtualenv-py3.8
·· Building 31daa941 <master> for virtualenv-py3.8.
·· Installing 31daa941 <master> into virtualenv-py3.8.
·· Error running /home/diabhiue/projects/Cirq/.asv/env/76391772e92136ec87b9940d70226329/bin/python -mpip install /home/diabhiue/projects/Cirq/.asv/env/76391772e92136ec87b9940d70226329/asv-build-cache/31daa9410a0e1e1ac3da38109aa8ce3a15aed17b/cirq-0.13.0.dev0-py3-none-any.whl (exit status 1)
   STDOUT -------->
   Processing ./asv-build-cache/31daa9410a0e1e1ac3da38109aa8ce3a15aed17b/cirq-0.13.0.dev0-py3-none-any.whl
   STDERR -------->
   ERROR: Could not find a version that satisfies the requirement cirq-aqt==0.13.0.dev (from cirq) (from versions: 0.12.0.dev20210612195918, 0.12.0.dev20210612203412, 0.12.0.dev20210614144502, 0.12.0.dev20210614155514, 0.12.0.dev20210614212301, 0.12.0.dev20210615004208, 0.12.0.dev20210615021241, 0.12.0.dev20210615161805, 0.12.0.dev20210615184533, 0.12.0.dev20210616203540, 0.12.0.dev20210617161841, 0.12.0.dev20210617163522, 0.12.0.dev20210621203848, 0.12.0.dev20210622155818, 0.12.0.dev20210622164449, 0.12.0.dev20210622165747, 0.12.0.dev20210622211622, 0.12.0.dev20210623024554, 0.12.0.dev20210623155331, 0.12.0.dev20210623201424, 0.12.0.dev20210624115740, 0.12.0.dev20210624162903, 0.12.0.dev20210624192532, 0.12.0.dev20210625201025, 0.12.0.dev20210625210534, 0.12.0.dev20210628152018, 0.12.0.dev20210628225324, 0.12.0.dev20210628232440, 0.12.0.dev20210629225807, 0.12.0.dev20210630005811, 0.12.0.dev20210630121854, 0.12.0.dev20210630205305, 0.12.0.dev20210702133320, 0.12.0.dev20210702154855, 0.12.0.dev20210702231711, 0.12.0.dev20210703225533, 0.12.0.dev20210706022704, 0.12.0.dev20210707192225, 0.12.0.dev20210707203903, 0.12.0.dev20210707222957, 0.12.0.dev20210708190715, 0.12.0.dev20210709011140, 0.12.0.dev20210709023918, 0.12.0.dev20210709040206, 0.12.0.dev20210709042051, 0.12.0.dev20210709193054, 0.12.0.dev20210709205112, 0.12.0.dev20210709212241, 0.12.0.dev20210709231148, 0.12.0.dev20210709235105, 0.12.0.dev20210712211116, 0.12.0.dev20210713144931, 0.12.0.dev20210714160402, 0.12.0.dev20210714194520, 0.12.0.dev20210714201237, 0.12.0.dev20210714210844, 0.12.0.dev20210714232449, 0.12.0.dev20210715174317, 0.12.0.dev20210715191538, 0.12.0.dev20210715205013, 0.12.0.dev20210719133031, 0.12.0.dev20210720163652, 0.12.0.dev20210720172314, 0.12.0.dev20210720193909, 0.12.0.dev20210720201718, 0.12.0.dev20210721174133, 0.12.0.dev20210721180150, 0.12.0.dev20210723065135, 0.12.0.dev20210725033218, 0.12.0.dev20210726163855, 0.12.0.dev20210726180724, 0.12.0.dev20210726183417, 0.12.0.dev20210726185245, 0.12.0.dev20210726203014, 0.12.0.dev20210728203212, 0.12.0.dev20210728215634, 0.12.0.dev20210728232936, 0.12.0.dev20210729211930, 0.12.0.dev20210730164821, 0.12.0.dev20210802154505, 0.12.0.dev20210804161122, 0.12.0.dev20210804163622, 0.12.0.dev20210804165457, 0.12.0.dev20210804212731, 0.12.0.dev20210805064526, 0.12.0.dev20210806000123, 0.12.0.dev20210806032707, 0.12.0.dev20210806161017, 0.12.0.dev20210808182659, 0.12.0.dev20210810005821, 0.12.0.dev20210810045225, 0.12.0.dev20210810051536, 0.12.0.dev20210810223624, 0.12.0.dev20210811122134, 0.12.0.dev20210811170011, 0.12.0.dev20210811172937, 0.12.0.dev20210811175635, 0.12.0.dev20210811183507, 0.12.0.dev20210811191033, 0.12.0.dev20210811195003, 0.12.0.dev20210811212103, 0.12.0, 0.13.0.dev20210811232553, 0.13.0.dev20210811234906, 0.13.0.dev20210812001719, 0.13.0.dev20210812031536, 0.13.0.dev20210812040004, 0.13.0.dev20210812042106, 0.13.0.dev20210812050310, 0.13.0.dev20210812162815, 0.13.0.dev20210813221249, 0.13.0.dev20210814185508, 0.13.0.dev20210816193359, 0.13.0.dev20210816195849, 0.13.0.dev20210816203535, 0.13.0.dev20210816215342, 0.13.0.dev20210816233321, 0.13.0.dev20210817004448, 0.13.0.dev20210817193329, 0.13.0.dev20210818061230, 0.13.0.dev20210818160808, 0.13.0.dev20210818171827, 0.13.0.dev20210818183948, 0.13.0.dev20210819012929, 0.13.0.dev20210819020806, 0.13.0.dev20210819030321, 0.13.0.dev20210819063020, 0.13.0.dev20210819235148, 0.13.0.dev20210820160855, 0.13.0.dev20210820185342, 0.13.0.dev20210820222802, 0.13.0.dev20210820224938, 0.13.0.dev20210820231011, 0.13.0.dev20210820233111, 0.13.0.dev20210820235213, 0.13.0.dev20210821001415, 0.13.0.dev20210821003550, 0.13.0.dev20210821014747, 0.13.0.dev20210821025135, 0.13.0.dev20210821030827, 0.13.0.dev20210822190736, 0.13.0.dev20210823180755, 0.13.0.dev20210823231908, 0.13.0.dev20210824004854, 0.13.0.dev20210824170204, 0.13.0.dev20210825162618, 0.13.0.dev20210825205214, 0.13.0.dev20210825212610, 0.13.0.dev20210826004924, 0.13.0.dev20210826185640, 0.13.0.dev20210826225825, 0.13.0.dev20210826231852, 0.13.0.dev20210831164745, 0.13.0.dev20210901060306, 0.13.0.dev20210901195302, 0.13.0.dev20210907233535, 0.13.0.dev20210908171519, 0.13.0.dev20210910231739, 0.13.0.dev20210914155943, 0.13.0.dev20210914173402, 0.13.0.dev20210915180606, 0.13.0.dev20210916200646, 0.13.0.dev20210917162100, 0.13.0.dev20210917191651, 0.13.0.dev20210917210754, 0.13.0.dev20210917214256, 0.13.0.dev20210918213009, 0.13.0.dev20210918215545, 0.13.0.dev20210921185444, 0.13.0.dev20210922165312, 0.13.0.dev20210923190159, 0.13.0.dev20210923212346, 0.13.0.dev20210924035311, 0.13.0.dev20210924202240, 0.13.0.dev20210924204253, 0.13.0.dev20210924212510, 0.13.0.dev20210924233357, 0.13.0.dev20210927221740, 0.13.0.dev20210928043924, 0.13.0.dev20210928210043, 0.13.0.dev20210929041120, 0.13.0.dev20210929175218, 0.13.0.dev20210929200623, 0.13.0.dev20210929215257, 0.13.0.dev20210929225605, 0.13.0.dev20210930233358, 0.13.0.dev20211001180414, 0.13.0.dev20211001182844, 0.13.0.dev20211001184738, 0.13.0.dev20211004030023, 0.13.0.dev20211005015203, 0.13.0.dev20211005182832, 0.13.0.dev20211005202633, 0.13.0.dev20211005225442, 0.13.0.dev20211006192945, 0.13.0.dev20211006230807, 0.13.0.dev20211008171744, 0.13.0.dev20211008211012, 0.13.0.dev20211011220323, 0.13.0.dev20211012141432, 0.13.0.dev20211012175707, 0.13.0.dev20211012220646, 0.13.0.dev20211012234056, 0.13.0.dev20211013002532, 0.13.0.dev20211013173027, 0.13.0.dev20211013203102, 0.13.0.dev20211013213216, 0.13.0.dev20211014011808, 0.13.0.dev20211014162700, 0.13.0.dev20211014185350, 0.13.0.dev20211015205930, 0.13.0.dev20211015220941, 0.13.0.dev20211016034750, 0.13.0.dev20211018204936, 0.13.0.dev20211019085906, 0.13.0.dev20211021025555, 0.13.0.dev20211024223811, 0.13.0, 0.13.1, 0.14.0.dev20211024234303, 0.14.0.dev20211025014153, 0.14.0.dev20211025210608, 0.14.0.dev20211026024027, 0.14.0.dev20211026172444)
   ERROR: No matching distribution found for cirq-aqt==0.13.0.dev

·· Failed to build the project and import the benchmark suite.

Adding @tanujkhattar as per git blame

I also noticed that there were some test failures before making any changes. Below are those failed tests. Are these expected?

Failed tests(./check/all)

=========================== short test summary info ============================
FAILED cirq-rigetti/cirq_rigetti/sampler_bell_circuit_test.py::test_bell_circuit_through_sampler
FAILED cirq-rigetti/cirq_rigetti/sampler_parametric_circuit_test.py::test_parametric_circuit_through_sampler
FAILED cirq-rigetti/cirq_rigetti/sampler_parametric_circuit_test.py::test_parametric_circuit_through_sampler_with_parametric_compilation
FAILED cirq-rigetti/cirq_rigetti/sampler_readout_reassigned_qubits_test.py::test_readout_on_reassigned_qubits
FAILED cirq-rigetti/cirq_rigetti/sampler_readout_separate_memory_regions_test.py::test_circuit_with_separate_readout_keys_through_sampler
FAILED cirq-rigetti/cirq_rigetti/sampler_test.py::test_get_rigetti_qcs_sampler
FAILED cirq-rigetti/cirq_rigetti/service_bell_circuit_test.py::test_bell_circuit_through_service
FAILED cirq-rigetti/cirq_rigetti/service_parametric_circuit_test.py::test_parametric_circuit_through_service
FAILED cirq-rigetti/cirq_rigetti/service_test.py::test_get_rigetti_qcs_service
FAILED dev_tools/bash_scripts_test.py::test_pytest_changed_files_file_selection
FAILED dev_tools/bash_scripts_test.py::test_pytest_changed_files_branch_selection
FAILED dev_tools/bash_scripts_test.py::test_pytest_and_incremental_coverage_branch_selection
FAILED dev_tools/bash_scripts_test.py::test_incremental_format_branch_selection
FAILED dev_tools/bash_scripts_test.py::test_pylint_changed_files_file_selection
FAILED dev_tools/docker_test.py::test_docker_stable - AssertionError: assert ...
FAILED dev_tools/docker_test.py::test_docker_pre - AssertionError: assert 1 == 0
16 failed, 14660 passed, 51 skipped, 77 xfailed, 571 warnings in 582.07s (0:09:42)

@vtomole
Copy link
Collaborator

vtomole commented Nov 20, 2021

Hey @diabhiue, I'm just seeing your ping. I'm also going to be out of office for the next 2 weeks.

Anyway, it seems like the second error is due to #4660 and the first one is due to cirq's sub-packages are not installed before the benchmarks are executed. Since the benchmarks only need cirq-google, you will need to tell asv where it is. I was able to run the benchmarks after making this change: 024f6fb on my local asv.conf.json.

(venv3.7) vtomole@vtomole:~/Cirq$ ./check/asv_run 
· No executable found for python 3.6
· Creating environments
· Discovering benchmarks
·· Uninstalling from virtualenv-py3.7
·· Building a75b215f <master> for virtualenv-py3.7.
·· Installing a75b215f <master> into virtualenv-py3.7.
· Running 22 total benchmarks (1 commits * 2 environments * 11 benchmarks)
[  0.00%] · For Cirq commit a75b215f <master>:
[  0.00%] ·· Building for virtualenv-py3.7
[  0.00%] ·· Benchmarking virtualenv-py3.7
[  2.27%] ··· Running (bench_examples.ExamplesTest.time_example_runs_bcs_mean_field_perf--)...........
[ 27.27%] ··· bench_examples.ExamplesTest.time_example_runs_bcs_mean_field_perf                                                                                                                     183±1ms
[ 29.55%] ··· bench_examples.ExamplesTest.time_example_runs_bell_inequality_perf                                                                                                                4.46±0.02ms
[ 31.82%] ··· bench_examples.ExamplesTest.time_example_runs_bernstein_vazirani_perf                                                                                                             4.33±0.07ms
[ 34.09%] ··· bench_examples.ExamplesTest.time_example_runs_grover_perf                                                                                                                          6.45±0.1ms
[ 36.36%] ··· bench_examples.ExamplesTest.time_example_runs_hello_line_perf                                                                                                                         199±7ms
[ 38.64%] ··· bench_examples.ExamplesTest.time_example_runs_hello_qubit_perf                                                                                                                    1.27±0.01ms
[ 40.91%] ··· bench_examples.ExamplesTest.time_example_runs_phase_estimator_perf                                                                                                                   44.2±2ms
[ 43.18%] ··· bench_examples.ExamplesTest.time_example_runs_quantum_fourier_transform_perf                                                                                                       6.44±0.3ms
[ 45.45%] ··· bench_examples.ExamplesTest.time_example_runs_quantum_teleportation                                                                                                                5.89±0.3ms
[ 47.73%] ··· bench_examples.ExamplesTest.time_example_runs_superdense_coding                                                                                                                      36.6±2ms
[ 50.00%] ··· bench_linalg_decompositions.time_kak_decomposition 

Thanks!

@dabacon
Copy link
Collaborator

dabacon commented Apr 19, 2022

Doing this for the methods on circuit seems to break a ton of tests (600+) likely because a lot of our default precisions are 1e-7 or 1e-8.

@dabacon dabacon assigned dabacon and unassigned diabhiue May 31, 2022
@dabacon dabacon removed the good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. label Jun 2, 2022
@dabacon
Copy link
Collaborator

dabacon commented Jun 15, 2022

The method final_state_vector will need to be updated to default to np.complex64.

@dabacon dabacon reopened this Jun 15, 2022
@vtomole
Copy link
Collaborator

vtomole commented Jul 5, 2022

@dabacon Given #5636, did we decide that this is not worth doing due to the frequency of the flakes? If so, then I think the only thing left is to monitor the CI for the next few days to confirm that the roll back fixed everything and then close this.

@dabacon
Copy link
Collaborator

dabacon commented Jul 6, 2022

Yes we decided to keep the different precision on the Circuit class. Closing.

@dabacon dabacon closed this as completed Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/circuits area/performance area/simulation BREAKING CHANGE For pull requests that are important to mention in release notes. complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor kind/feature-request Describes new functionality triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants