-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Density matrix traces not remaining at 1 after certain operations #5916
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
Comments
This seems to be happening in the factor when the measurement gate is encountered. https://github.com/quantumlib/cirq/blob/8953eebe05e2510d798356dfd9fc2d5ba922cfe9/cirq-core/cirq/linalg/transformations.py#L636 likely needs to renormalize after getting the partial traces. For now, OP can create the simulator as |
Note reverting #4300 fixes this, though that implementation is still incorrectly (and worsely) normalized in other cases. I think the pre-#4300 implementation should be faster since it calculates both factors at the same time rather than two calls to partial_trace (I haven't tested this). However it needs renormalized as a density matrix rather than a state vector ( |
split_untangled_states = False seems to work in the provided test script |
Ran some tests and the newer implementation using partial_trace is faster than the old implementation. Will push a PR that restabilizes the DM by trace after factoring. |
I closed the linked PR with the fix because I think the right thing to do here is to do the renormalization in Of course fixing this in |
NaN seems to be a problem. Otherwise this appears to be accumulation of numerical errors. |
Description of the issue
When looping over certain gate operations and measurements, the trace of the density matrix decreases and eventually approaches 0.
How to reproduce the issue
The following script (@kinetic-cipher) reproduces the issue:
The printed output is:
(0.9999999+0j)
(0.99999976+0j)
(0.9999994+0j)
(0.9999988+0j)
(0.9999976+0j)
(0.99999523+0j)
(0.99999034+0j)
(0.99998057+0j)
(0.999961+0j)
(0.99992204+0j)
(0.99984396+0j)
(0.9996879+0j)
(0.99937594+0j)
(0.9987523+0j)
(0.997506+0j)
(0.9950181+0j)
(0.99006104+0j)
(0.98022074+0j)
(0.9608326+0j)
(0.9231992+0j)
(0.8522966+0j)
(0.7264095+0j)
(0.5276707+0j)
(0.27843636+0j)
(0.07752679+0j)
(0.0060104034+0j)
(3.6124948e-05+0j)
(1.3050119e-09+0j)
(1.703056e-18+0j)
(2.9003994e-36+0j)
0j
with error (cirq v0.14.0):
or with error (cirq v1.0.0):

When modifying the same script to use np.complex128 as the dtype of the DensityMatrixSimulator
the density matrix traces get very large.
with the same error:
Cirq version
We tested this in cirq version 1.0.0 as well as 0.14.0 and found the error in both cases.
The text was updated successfully, but these errors were encountered: