-
Notifications
You must be signed in to change notification settings - Fork 318
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
Batching of circuits to overcome memory issues when using statevector simulator #209
Conversation
Added reno file. The correctness of the output of the code is checked by tests already in place; testing the memory usage may be complicated within constraints of gh-actions. |
releasenotes/notes/batch-circuits-statevector-522a842c6f68d954.yaml
Outdated
Show resolved
Hide resolved
….yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com>
The spell checker also fails on this |
Updated the |
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.
Looks good to me, thanks a lot!
@woodsp-ibm Do you have any comments? |
Can I ask you to make a minor change to the docstring for batch_size in the constructor. It says
specifically default 1000 yet the code has
So it should state the default is 900. I think it may have been 1000 at one point but was changed, if I recall correctly, to 900 to fit more with the limits around the provider. In terms of testing you say its covered by the current unit tests. From what I can see there is nothing explicitly testing that aspect. Of course batch_size defaults to 900 and is in main path. I am not sure what we do in test is ever affected by the batch size since from what I can see the tests are pretty small. Having said that if we had a test that dropped the batch size down I am not sure how to test it given its behavior is internal to evaluate - the only way comes to mind is hooking the quantum instance execute and checking the number of circuits is as expected along the way in addition the the final result being as expected. |
Looks good to me. Regarding the |
Updated the docstring as requested by @woodsp-ibm. |
Just a note. Locally I changed the QuantumInstance |
@woodsp-ibm When I mentioned unit tests I did not have anything special on my mind. In general, your idea of setting batch size to 1 and then running a test on the statevector simulator make sense. @rsln-s What do you think? |
|
@woodsp-ibm I approve, merge this PR and open an issue to improve tests for QuantumKernel. Any thoughts? |
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.
merge this PR and open an issue to improve tests for QuantumKernel. Any thoughts?
@adekusar-drl that seems fine by me.
Closed and #242 is opened. |
… simulator (qiskit-community#209) Currently batch_size parameter is ignored if the statevector simulator is used. This leads to unreasonable memory use due to the size of the transpiled circuits, up to 1TB of RAM for 800 by 800 kernel matrix and 20 qubits (see qiskit-terra, issue #6991). This pull request fixes this by transpiling and simulating circuits in batches, never storing the entire 800 circuits. The modification uses batch_size parameter that is already used in non-statevector case. * initial attempt that passes the tests * further improvement * fix formatting * added reno file * Update releasenotes/notes/batch-circuits-statevector-522a842c6f68d954.yaml Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * added the word `transpiled` to the dictionary for spellchecker * updated docstring to accurately reflect default batch size Co-authored-by: Anton Dekusar <62334182+adekusar-drl@users.noreply.github.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Manoel Marques <Manoel.Marques@ibm.com>
Summary
Currently
batch_size
parameter is ignored if the statevector simulator is used. This leads to unreasonable memory use due to the size of the transpiled circuits, up to 1TB of RAM for 800 by 800 kernel matrix and 20 qubits (see qiskit-terra, issue #6991). This pull request fixes this by transpiling and simulating circuits in batches, never storing the entire 800 circuits. The modification usesbatch_size
parameter that is already used in non-statevector case.Details and comments
I had success by setting
batch_size=50
(memory footprint down to <20 GB).