Open Praveen91299 opened 9 months ago
Looks good! Will need some time to go over it, but I think we won't need many changes. Could you provide a minimal example how to use (can be as a comment here) as well as a unit-test (ideally at tests/test_backend.py)
Hi Jakob, sorry got a bit caught up, I'm working on some test cases for the test_backend.py
, will get it done soon. Here's a little snippet for it's use.
import tequila
circ = tequila.QCircuit()
circ += tequila.gates.X(target=[0])
circ += tequila.gates.H(target=[0])
circ += tequila.gates.CNOT(target=[1], control=[0])
#simulating density
density = tequila.simulate(circ, noise=tequila.circuit.noise.DepolarizingError(p=0.1, level=2))
print(density)
#simple density manipulations
print(density.n_qubits)
print(density.trace())
from openfermion import QubitOperator
HQ = QubitOperator('Z0 Z1', 1)
H = tequila.QubitHamiltonian.from_openfermion(HQ)
print(density.QubitHamiltonian_expectation(H))
print(density.QubitHamiltonian_variance(H))
Expected Output:
Tequila DensityMatrix over 2 qubits stored as sparse matrix
array([[ 0.475+0.j, 0. +0.j, 0. +0.j, -0.45 +0.j],
[ 0. +0.j, 0.025+0.j, 0. +0.j, 0. +0.j],
[ 0. +0.j, 0. +0.j, 0.025+0.j, 0. +0.j],
[-0.45 +0.j, 0. +0.j, 0. +0.j, 0.475+0.j]])
2
(1.0000000000000002+0j)
(0.9000000000000002+0j)
(0.18999999999999984+0j)
I do have to note that we'd still need to modify for the other backends to allow for density simulation or flag otherwise.
Hi, Praveen, I am just following up on this (no time pressure, though). PR looks good. I just need the comments addressed/implemented before I can merge it in, as we may face some issues otherwise.
Hey Jakob, thanks for following up! Been a bit lazy on this, I'll get this done asap.
Hey Jakob, thanks for following up! Been a bit lazy on this, I'll get this done asap.
No worries, there is no time pressure. I just wanted to check if there are problems or if some of the comments are unclear.
Hi Jakob, apologies for the delay again. My branch is a bit out-dated with main, will deal with the merge later. I've been looking into adding in density simulation and had a couple of questions, I've added a simulate_density()
and do_simulate_density()
in simulators_base.py
and simulators_qiskit.py
.
simulator_api.py
needs a simulate_density()
function, please confirm.simulators_api/simulate()
)?Hi Jakob, apologies for the delay again. My branch is a bit out-dated with main, will deal with the merge later. I've been looking into adding in density simulation and had a couple of questions, I've added a
simulate_density()
anddo_simulate_density()
insimulators_base.py
andsimulators_qiskit.py
.1. I am not sure in what precedence the simulate function calls these or where else I need to change code. I'm guessing `simulator_api.py` needs a `simulate_density()` function, please confirm. 2. What exactly is a compiled objective object (instantiated in `simulators_api/simulate()`)?
Hi Praveen, tight schedule. I will try to get back to you within this week. Please remind me if you don't hear back
Thanks for the flow chart! Will let you know if any questions and hopefully wrap his up soon.
Thought it would be useful for density simulation to allow for noise. Right now only Qiskit backend, would require to modify other backend simulator files. I'm not sure if I did the pull request right, see commit with ID f378f16