-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix for save_expval truncation #2265
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
.github/workflows/build.yml
Outdated
with: | ||
path: ./wheelhouse/*.whl | ||
name: artifact-${{ github.job }} | ||
wheel-gpu: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove GPU build wheel ?
I think we still need them for testing build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a temporary measure since those builds are failing (probably due to CUDA update) and this prevents us from merging this fix.
cfa3697
to
1ca7b96
Compare
Summary
Fixes small problems preventing the usage of
save_expval
truncation.Fixes #2249
Details and comments
PR #2216 added a mechanism for truncating
save_expval
, removing qubits for which the pauli measurement operator isI
, since those qubits are not needed for the simulation of the measurement. This is crucial for running the simulator on small circuits compiled on large backends, since thesave_expval
is extended to all the qubits in the backend, meaning we might have a 127-qubitsave_expval
for a circuit with only 12 active qubits (e.g. in the added test case).However, the truncation code was not activated in practice due to the
!qubitset_.empty()
check performed prior to the execution of the code which excludesI
qubits. Since thesave_expval
command is the last one in the circuit when, e.g., running via an estimator (which adds the command to the circuit just before its run) and gates are traversed in reverse order at this stage, thesave_expval
command would always fail this test, defaulting to thequbitset_.insert(op.qubits.begin(), op.qubits.end());
line which adds all its qubits.This PR removes the
!qubitset_.empty()
check and fixes some problems arising from this:I
the truncation stage results in a circuit without qubits, and so it is skipped and no expval result it obtained. Hence, we always add the a qubit to the qubit set if it is empty, even if it corresponds toI
. This does not enlarge the qubit set enough to pose a real problem, although smarter logics can be implemented.op.qubits.resize(qubitmap_.size());
command was missing in the remapping code (although present in the non-remapping truncation code inset_params
); it was added. Without resizing, thesave_expval
command fails due to generation of invalid pauli mask data in theexpval_pauli
method.ZZ
is used on qubits 1,2 and qubit 0 is truncated away, while creating the new pauli the code will attempt to access the pauli in index 2 (more precisely, in locationpauli.size()-1-2
since paulis are accessed in reverse order). This is fixed by using the index of the qubits insideop.qubits
instead of their absolute index.