-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Set default unitary precision np.complex64 #5426
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
I'm on board with the breaking change here, just some comments on your comments 😝
kak decomposition is calculated from the `interaction`s. T | ||
Thisd etermines how close $k_x$ must be to π/4 to guarantee |
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.
T Thisd etermines
-> This determines
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.
fixed
@@ -83,7 +83,7 @@ def test_decompose_two_qubit_interaction_into_two_b_gates(obj: Any): | |||
desired_unitary = obj if isinstance(obj, np.ndarray) else cirq.unitary(obj) | |||
for operation in circuit.all_operations(): | |||
assert len(operation.qubits) < 2 or operation.gate == _B | |||
assert cirq.approx_eq(cirq.unitary(circuit), desired_unitary, atol=1e-6) | |||
np.testing.assert_allclose(cirq.unitary(circuit), desired_unitary, atol=3e-5) |
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.
Should this also get the "lose a lot of precision" notice?
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.
added
@@ -384,8 +384,10 @@ def _create_corrected_circuit( | |||
implements `target_unitary`. | |||
""" | |||
# Get the local equivalents | |||
# We use higher precision than normal to avoid nummerical instabilities. |
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.
nummerical
-> numerical
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.
fixed
…final_state_vector (#5636) Rolls back change in #5426 that set the default precision on `Circuit#unitary` to `np.complex128`. Also sets the default on `Circuit#final_state_vector` to `np.complex128`. There was a deprecation warning that this was going to be downgraded to `np.complex64`,, but this will now remain `np.complex128`. This is breaking in that is someone explicitly passed `dtype=None` to this method it would now break. Rolls back #5426 #5616 #5537 #5535
…final_state_vector (quantumlib#5636) Rolls back change in quantumlib#5426 that set the default precision on `Circuit#unitary` to `np.complex128`. Also sets the default on `Circuit#final_state_vector` to `np.complex128`. There was a deprecation warning that this was going to be downgraded to `np.complex64`,, but this will now remain `np.complex128`. This is breaking in that is someone explicitly passed `dtype=None` to this method it would now break. Rolls back quantumlib#5426 quantumlib#5616 quantumlib#5537 quantumlib#5535
…final_state_vector (quantumlib#5636) Rolls back change in quantumlib#5426 that set the default precision on `Circuit#unitary` to `np.complex128`. Also sets the default on `Circuit#final_state_vector` to `np.complex128`. There was a deprecation warning that this was going to be downgraded to `np.complex64`,, but this will now remain `np.complex128`. This is breaking in that is someone explicitly passed `dtype=None` to this method it would now break. Rolls back quantumlib#5426 quantumlib#5616 quantumlib#5537 quantumlib#5535
This changes the
unitary
method onCircuit
to return a numpy array that usesnp.complex64
instead ofnp.complex128
.This is a breaking change.
Some ways we could deprecate this, but they all have some serious issues
We could add a deprecation warning as was done with
final_state_vector
if no override is None. See Consistent final_state_vector #5267. However, unlike in that PR, if we do make this warn in tests, we will need to fix many 1000s of tests (which we will then want to revert), becausefinal_state_vector
is not widely used, butunitary
is all over our tests.We could just start warning about this in our release notes, but not change it until a set version update (say 0.16). We could submit this PR, or use it for a future PR to update the tests as necessary.
Some comments on this change:
Mostly the changes here are to update the precision in tests, since we only have a little over 7 digits of precision in the new switch most of the precision is set to 1e-6. However there are cases where we build larger circuits that have many rounding errors and so end up closer to 5e-6 or even on 1e-5.
This changes the default precision on kak_decompositions, which was a large source of many of the test failures.
I check this for flakes at 200 repetitions. In the process I found some interesting failures. These are currently here, but I moved them out to #5431 for separate review.
Fixes: #1030