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

BasicAer's random seeds are shared in the job. #6501

Open
ikkoham opened this issue Jun 3, 2021 · 3 comments
Open

BasicAer's random seeds are shared in the job. #6501

ikkoham opened this issue Jun 3, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@ikkoham
Copy link
Contributor

ikkoham commented Jun 3, 2021

Information

  • Qiskit Terra version:
  • Python version:
  • Operating system:

What is the current behavior?

When one runs the list of quantum circuits with qasm_simulator and fixes the seed by seed_simulator, BasicAer uses the seed all over again, so BasicAer gives the same results.

Steps to reproduce the problem

from qiskit import Aer, BasicAer, QuantumCircuit, execute

qc2 = QuantumCircuit(1, 1)
qc2.h(0)
qc2.measure(0, 0)
print(
    execute([qc2] * 10, Aer.get_backend("qasm_simulator"), seed_simulator=15)
    .result()
    .get_counts()
)
# [{'0': 528, '1': 496}, {'1': 499, '0': 525}, {'0': 511, '1': 513}, {'0': 493, '1': 531}, {'0': 522, '1': 502}, {'1': 521, '0': 503}, {'1': 513, '0': 511}, {'0': 539, '1': 485}, {'0': 516, '1': 508}, {'1': 478, '0': 546}]
print(
    execute([qc2] * 10, BasicAer.get_backend("qasm_simulator"), seed_simulator=15)
    .result()
    .get_counts()
)
# [{'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}, {'1': 481, '0': 543}]

What is the expected behavior?

The initialization of BasicAer's seed should be done only at the beginning of the job, and all the results should change (like Aer).

Suggested solutions

Move this line
https://github.com/Qiskit/qiskit-terra/blob/a9289c085036002fa864b30edcd0b8ce066ea858/qiskit/providers/basicaer/qasm_simulator.py#L504
to _run_job.
NOTE: This change has a very large influence. It is expected that almost all Application tests will fail.

@ikkoham ikkoham added the bug Something isn't working label Jun 3, 2021
@t-imamichi
Copy link
Member

This affects VQE when grouping is disabled because same quantum circuits are executed. As a result, the eigenvalues by VQE with BasicAer (grouping=False) are likely to be biased.

@dhruvbhq
Copy link
Contributor

Hi! May I work on this?

@ikkoham
Copy link
Contributor Author

ikkoham commented Jun 28, 2021

@dhruvbhq Thank you. But please wait. I'm not sure if my suggestion is the right direction to fix it.

I think that BasicAer should be deprecated in the future (related to #4443), so this issue can be left. But, there may be people who run into the same problem, so I've created an issue.

@chriseclectic @mtreinish What do you think? What should we do?

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

3 participants