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

Add operation to trace oper-ket without reshaping #2126

Merged
merged 3 commits into from Mar 21, 2023

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented Mar 17, 2023

Description
Add and operation to compute the trace of column stacked operators without reshaping them.
The reshape would otherwise do a temporary copy of the data.
Another addition to improve stochastic solvers timings.

@coveralls
Copy link

coveralls commented Mar 17, 2023

Coverage Status

Coverage: 75.391%. Remained the same when pulling 823f1d5 on Ericgig:operkettrace into fd89a25 on qutip:master.

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

Looks good.

I don't see a way to do this without adjusting the data layer somehow, since it doesn't have the information to decide whether a matrix is a stacked operator or not.

What happens in one wants to trace the adjoint of an oper_ket? I.e. an oper_bra? Or does QuTiP not really support that?

@@ -225,12 +225,12 @@ def reset(self, hard=False):

def _prob_func(self, state):
if self.issuper:
return _data.norm.trace(unstack_columns(state))
return _data.trace_oper_ket(state).real
Copy link
Contributor

Choose a reason for hiding this comment

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

Should trace_oper_ket not be exposed under data.norm the way the other norm operations are?

Copy link
Member Author

Choose a reason for hiding this comment

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

We have both data.trace and data.norm.trace.
data.norm.trace is defined as tr(sqrt(A @ A.adjoint()))...
For dm, they give the same result and the normal trace is faster, so I should have used that one from the start.

Not a fan of having 2 functions with the same name, I sometime get confused and use the wrong one.
But this one should not be in data.norm.

qutip/core/data/trace.pyx Outdated Show resolved Hide resolved
@Ericgig Ericgig requested a review from hodgestar March 20, 2023 15:58
@Ericgig
Copy link
Member Author

Ericgig commented Mar 21, 2023

@hodgestar, is there anything else you want me to fix in this PR?

ps. Right now, to trace oper-bra, you would need to get it's adjoint first, use this or unstack then trace.

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

Looks good!

@hodgestar
Copy link
Contributor

@Ericgig Apologies for the delay. I wanted to go look at data.norm.trace. The implementation there is completely different and the default one used by Qobj for qobj.norm() for operators. I'm wondering if the more complex eigenvalue decomposition definition is really worth it? Not a question for this PR though.

@Ericgig Ericgig merged commit 9c97237 into qutip:master Mar 21, 2023
11 checks passed
@Ericgig Ericgig deleted the operkettrace branch March 21, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants