You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
What is the expected behavior?
The functionality is correct, but the code (here:
qiskit-aer/src/simulators/stabilizer/stabilizer_state.hpp
Line 657 in 269c26f
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 totrue
to indicate saving the state if needed, but the call inState::get_probability_helper
would have the flag set tofalse
.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 usingswap
). 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.
The text was updated successfully, but these errors were encountered: