unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
363 stars 160 forks source link

Include backend option for real hardware in mitiq.interface.mitiq_qiskit.qiskit_utils.execute_with_shots #1163

Closed anhdpham closed 2 years ago

anhdpham commented 2 years ago

Pre-Request Checklist

Issue Description

Currently the function execute_with_shots or execute_with_shots_and_noise do not allow for specific backend, e.g real hardware rather than simulator or different noise model from the simulator, so the calculation of the expectation value requires specifies a circuit with different basis measurement X, Y, Z, etc when the Hamiltonian is complex.

Proposed Solution

It would be nice to allow real backend input in the qiskit_utils.execute_with_shots in the qiskit interface so it's a lot easier to calculate the expectation value of an operator.

nathanshammah commented 2 years ago

+1 for unitaryhack bounty.

Misty-W commented 2 years ago

Hi unitaryHACKers! Feel free to tag me in the comments if you want to work on this issue and have questions.

If you want to submit a solution to this issue, please open a pull request with [unitaryHACK] in the title

RamAIbot commented 2 years ago

Hi @Misty-W I would like to work on this. Let me verify once again, I need to run it on real hardware instead of the simulator right?

Misty-W commented 2 years ago

Hi @Misty-W I would like to work on this. Let me verify once again, I need to run it on real hardware instead of the simulator right?

Hi @RamAIbot, great that you'd like to work on this! To test the solution thoroughly you would need to run on real hardware, but I don't think it's required to close the issue. @andreamari please correct me if I'm wrong.

Right now the use of one simulator is hardcoded into mitiq.interface.mitiq_qiskit.qiskit_utils.execute_with_shots, but we want the user to be able to specify a valid Qiskit backend (doesn't have to be hardware, could be another simulator) in mitiq.interface.mitiq_qiskit.qiskit_utils.execute_with_shots and obtain a result from running on that backend.

andreamari commented 2 years ago

Hi @RamAIbot, in Qiskit a backend can represent both a real hardware device and a classical simulator. For testing one could use an abstract classical simulator like AerBackend, or a classical clone of a real device like e.g. FakeLima.

Misty-W commented 2 years ago

hi @RamAIbot, any help needed getting a PR started on this issue? Deadline to get credit for unitaryHACK is this Friday Jun 17!

RamAIbot commented 2 years ago

I’m stuck on how to test the module.I have added the backend. Can you provide any insights?

should I need to write my own test cases

Misty-W commented 2 years ago

I’m stuck on how to test the module.I have added the backend. Can you provide any insights?

should I need to write my own test cases

yes, you'll need to write a test function, or parametrize the existing test test_execute_with_shots in mitiq/interface/mitiq_qiskit/tests/test_qiskit_utils.py with multiple backends. You should test with at least two backends to confirm your modification works. You can take a look at other Mitiq tests that use pytest parametrization as examples to guide your implementation.

RamAIbot commented 2 years ago

Is it possible to continue working on the issue even after unitary hack deadline?

Misty-W commented 2 years ago

Is it possible to continue working on the issue even after unitary hack deadline?

@RamAIbot yes you can, we encourage ongoing contributions!

There's still a little time left to get credit for the hackathon, so if you have a draft PR ready I can take a look. I have to step away from my computer for a couple hours but I'll be available to look at it and answer questions this afternoon US Pacific Time.

RamAIbot commented 2 years ago

Hi @Misty-W , I will send you a draft PR in sometime.

RamAIbot commented 2 years ago

Hi @Misty-W , I have sent you the PR. Let me know if I need to edit.

https://github.com/unitaryfund/mitiq/pull/1360

Misty-W commented 2 years ago

Hi @Misty-W , I have sent you the PR. Let me know if I need to edit.

https://github.com/unitaryfund/mitiq/pull/1360

@RamAIbot, I left some comments on the PR. Feel free to ping me with questions!