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

faster state_number_enumerate #1594

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

jfeist
Copy link
Contributor

@jfeist jfeist commented Jun 30, 2021

Description
When the number of excitations in state_number_enumerate is limited, instead of iterating over all states and discarding the ones with too many excitations, directly choose the limits to only iterate over allowed states. As a small additional optimization, do not redo the same sum every time, but keep track of the sum within the algorithm. For the tests I've made, this is a factor of ~4-10 faster than the current version. Together with #1593, this reduces the runtime of enr_destroy (which uses state_number_enumerate) from almost 4s to 15 ms for the case I just treated, and another much bigger case takes 2.5 s now, while it hadn't finished after more than an hour with the previous version.

Note that since the two PRs (this one and #1593) are somewhat related, it might make sense to combine them into a single one. I'd be happy to do that.

Changelog
Made state_number_enumerate somewhat faster.

@coveralls
Copy link

coveralls commented Jun 30, 2021

Coverage Status

Coverage increased (+0.006%) to 65.121% when pulling 5d3bf0e on jfeist:faster_state_number_enumerate into 0d18b53 on qutip:master.

When the number of excitations is limited, instead of iterating over all
states and discarding the ones with too many excitations, directly
choose the limits to only iterate over allowed states. As a small
additional optimization, do not redo the same sum every time, but keep
track of the sum within the algorithm.
@jfeist jfeist force-pushed the faster_state_number_enumerate branch from 2724beb to 5d3bf0e Compare June 30, 2021 18:25
@nwlambert
Copy link
Member

This and #1593 both look like solid improvements to me, I did a little testing and couldn't break anything. Also your approach makes the code much more readable than it was.

Probably @hodgestar can comment on whether it is best to combine them into one?

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.

Thanks @jfeist!

I think we could make an even faster non-recursive version. Are you interested in giving that a try? If not, maybe I will find a bit of time to do it.

@hodgestar hodgestar added this to the QuTiP 4.6.3 milestone Jul 7, 2021
@hodgestar hodgestar merged commit 3110850 into qutip:master Jul 7, 2021
@jfeist
Copy link
Contributor Author

jfeist commented Jul 13, 2021

I've given it a shot in #1604, together with some other (possible) improvements.

hodgestar added a commit to hodgestar/qutip that referenced this pull request Feb 4, 2022
Faster state_number_enumerate implementation.
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.

5 participants