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

Aer function to check the memory requirement upfront when using simulators #1921

Closed
patdenim opened this issue Aug 30, 2023 · 3 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@patdenim
Copy link

What is the expected behavior?

It would be nice to know what is the memory required before executing a circuit using a simulator.
It is impossible to exactly know the memory needed when using the extended_simulator. Looking at the code extended_stabilizer_state.hpp. The formula required_chi() used by the extended simulator does not seem to be only a function of the exact gate counts in the circuit

size_t State::required_memory_mb(uint_t num_qubits,
                                 const std::vectoroperations::Op &ops) const {
  size_t required_chi = compute_chi(ops.cbegin(), ops.cend());
  // 5 vectors of num_qubits*8byte words
  // Plus 2*CHSimulator::scalar_t which has 3 4 byte words

Here is an example that shows this would help if knowing the exact memory required per circuit.
Consider 2 different circuits, with the following gates (Circuit A is having less gates than Circuit B) :

Circuit A
OrderedDict([
('u1', 272),
('sx', 133),
('cx', 114),
('h', 36),
('measure', 36)])

Circuit B
OrderedDict([
('u1', 480),
('cx', 228),
('sx', 216),
('h', 36),
('measure', 36)])

Then execute those 2 circuits on the extended_stabilizer

extended_stabilizer_simulator = AerSimulator(method='extended_stabilizer')
# Transpile circuit for backend
tcirc = transpile(circuit, extended_stabilizer_simulator)
extended_stabilizer_result = extended_stabilizer_simulator.run(tcirc, shots=1).result()
print('This succeeded?: {}'.format(extended_stabilizer_result.success))

Circuit A is failing with message

Simulation failed and returned the following error message:
ERROR: a circuit requires more memory than max_memory_mb.

while Circuit B works. (even though Circuit B is much bigger than Circuit A)

@patdenim patdenim added the enhancement New feature or request label Aug 30, 2023
@doichanj doichanj self-assigned this Sep 7, 2023
@doichanj doichanj added bug Something isn't working and removed enhancement New feature or request labels Sep 7, 2023
@doichanj doichanj added this to the Aer 0.13.0 milestone Sep 7, 2023
@doichanj
Copy link
Collaborator

doichanj commented Sep 8, 2023

I found issue in calling required_memory_mb function that State::set_config is not called before calculating required memory. In extended stabilizer, extended_stabilizer_approximation_error was not set from config parameters. This parameter can control size requirement when setting lerger error acceptance

@doichanj
Copy link
Collaborator

doichanj commented Sep 8, 2023

By the way, extended stabilizer allocates state buffer whose size is calculated by the same logic as compute_chi function at beginning. I think setting larger extended_stabilizer_approximation_error is the only way to decrease memory usage

@doichanj
Copy link
Collaborator

I think this should be fixed by PR #1933 with option commented above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants