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

Improvements for State::get_probability_helper for the stabilizer simulator #2259

Open
aromanro opened this issue Nov 15, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@aromanro
Copy link
Contributor

What is the expected behavior?

The functionality is correct, but the code (here:

void State::get_probability_helper(const reg_t &qubits,
) could be improved a little bit.

First possible improvement

Instead of simply marking a qubit that has random outcome, count them. Checking for their number allows returning not only for zero such qubits, but also for the case when a single one exists:

If there is only one, set prob_carry to 0.5 and return.

Second possible improvement

The code deals with cases of random outcome qubits recursively, by saving the 'state' (that is, stabilizers & destabilizers) then doing a measurement on the random outcome qubit, then dealing with the rest of them recursively (some of them might turn into deterministic after the measurement).
Saving and restoring the 'state' is done each such recursive branch... which is not needed, only the first save/restore is needed.

This can be solved by passing a flag to the call. In State::get_probability the flag would be set to true to indicate saving the state if needed, but the call in State::get_probability_helper would have the flag set to false.

Restoring the 'state' could be done not by simply using equality (which might mean copy) but by using move semantics (explicitly with std::move or by using swap). The compiler might optimize this anyway, but better safe...

Third possible improvement

The recursive call is at the end, the tail recursivity can be easily removed with a loop. I guess the compiler already can do such a thing when optimizing, so this is not something that would really bring much benefit.

I have an implementation for something similar here: https://github.com/aromanro/QCSim/blob/b53b9479f131a10d59bf0095fbe23ad956fbb6de/QCSim/Clifford.h#L394 the above ideas are present there as well, maybe it's helpful.

@aromanro aromanro added the enhancement New feature or request label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant