Skip to content

Tweak DM normalization after factor #5922

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

Closed
wants to merge 7 commits into from

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Oct 13, 2022

As reported in #5916, when repeatedly factoring and kronning a density matrix during simulation, the rounding error caused by partial_trace can propagate and explode after about 15 repetitions. This PR explicitly re-normalizes the density matrix after factoring.

Fixes #5916

@daxfohl daxfohl requested review from a team, vtomole and cduck as code owners October 13, 2022 22:39
@daxfohl daxfohl requested a review from dstrain115 October 13, 2022 22:39
@CirqBot CirqBot added the size: S 10< lines changed <50 label Oct 13, 2022
Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -717,6 +717,11 @@ def factor_density_matrix(
t2 = transpose_density_matrix_to_axis_order(t1, product_axes)
if not np.allclose(t2, t, atol=atol):
raise ValueError('The tensor cannot be factored by the requested axes')
# Tweak trace back to 1 to avoid rounding error propagation
extracted_dim = int(np.sqrt(np.prod(extracted.shape)))
extracted /= np.trace(extracted.reshape((extracted_dim, extracted_dim)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Open question: should this go into partial_trace instead? Since it appears that partial_trace is the root cause of the rounding error.

@daxfohl daxfohl closed this Nov 1, 2022
@daxfohl
Copy link
Collaborator Author

daxfohl commented Nov 1, 2022

I'm closing this because I think the right thing to do here is to do this in partial_trace. The einsum there is losing precision and ending up with a not-quite-one trace. Fudging this in factor solves the linked issue but does not address the root cause.

Of course fixing this in partial_trace will have larger perf impact and the extent of that impact needs to be investigated before making the change. This investigation and the determination of whether that is acceptable or not is a something that needs to be managed by a core maintainer.

@daxfohl daxfohl deleted the fix-factor branch November 4, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Density matrix traces not remaining at 1 after certain operations
3 participants