Qiskit / qiskit-aer

Aer is a high performance simulator for quantum circuits that includes noise models
https://qiskit.github.io/qiskit-aer/
Apache License 2.0
479 stars 355 forks source link

Density matrix simulator #39

Closed antoniomezzacapo closed 5 years ago

antoniomezzacapo commented 5 years ago

We need a density matrix simulator to perform noisy simulations of experiments for small-size systems.

pistoia commented 5 years ago

@chriseclectic can you help with this request? It is very urgent for Chemistry. Thanks.

yehuda-naveh commented 5 years ago

@chriseclectic I think you may be able to take Yael's code from the reference-model she built as-is. @yaelbh can comment what is the best way to do it if you prefer to go this way. The reference model was just a density matrix simulator, not optimized for performance of special inputs, but seems this is what they need for now.

chriseclectic commented 5 years ago

@pistoia this is in the roadmap, but it is a major change so won't be done until 0.3. We already have a lot of other things to get done for 0.2.

@yehuda-naveh this simulator needs to be very heavily optimised so i don't think that code is sufficient. The density matrix simulator should be based on the QubitVector base class to incorporate all of its optimizations. I'm currently refactoring the unitary simulator to do this too as a test case. But for the density matrix it will also require significant changes to how noise is handled in the code base so it is not a trivial thing to incorporate.

yehuda-naveh commented 5 years ago

Ok - thanks. Good with me. I missed the fact that the usecase requires heavily optimized simulator, I thought they are more interested in functional results of simple cases. Yael's code is non-optimized by design, to keep it a lean functional reference

antoniomezzacapo commented 5 years ago

@yaelbh @yehuda-naveh

What does Yael's code do? Can it run a quantum circuit with noise as a backend? We could use it temporarily.

yehuda-naveh commented 5 years ago

It can simulate any noise and any mixed state in general. It does it slowly (2^(2n)) and with no optimization in order to keep it clean and analyzable. The code is here, you can have a look: https://github.ibm.com/IBMQuantum/qiskit-aer-internal/commit/fce1506066428f65af8d8219f5e31a8330f8aceb

@yaelbh can work with you on more details, probably tomorrow as she's left for now

antoniomezzacapo commented 5 years ago

@yehuda-naveh , that link is not working for me. What kind of optimization are you referring to?

yehuda-naveh commented 5 years ago

ok, not sure how to give you access, probably @atilag or @chriseclectic can help. Anyway, if you'll be interested in using it we'll figure out where to put it. Optimization I mean working on the code (detailed data structures, caching of variables till they change, c vs python, etc) which make the code much more complex but faster, while preserving functionality. This code has the opposite design - be very clean in order to minimize the probability of bugs, and be able to white-box analyze the development of the density matrix. Runtime was not the drive here.

yaelbh commented 5 years ago

@antoniomezzacapo When you have access to the repository you'll be able to see a usage example in the function test_by_reference_model. It looks like this:

den_sim = DensityMatrixSimulator()
qobj = compile(qc, <another backend, e.g. qasm simulator>, shots=...)
den_result = den_sim.run(qobj)

Note that class DensityMatrixSimulator does not inherit from BaseBackend, and den_result is not of type Result. Noise is supported by a function called qop, which receives as input a set of Kraus operators. As for run time, the code contains multiplications of square matrices with 2^n rows and columns.

atilag commented 5 years ago

@yehuda-naveh , that link is not working for me. What kind of optimization are you referring to?

I'm giving you access @antoniomezzacapo , but this is an IBM internal repo.

antoniomezzacapo commented 5 years ago

Thanks @yaelbh @yehuda-naveh and @atilag !

antoniomezzacapo commented 5 years ago

@chunfuchen see above, this could help running noisy numerics for small systems. @atilag can you give Richard access too?

yehuda-naveh commented 5 years ago

@gadial added recently the full noise interface to Yael's simulator