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

Density matrix class and simulation #324

Open
wants to merge 13 commits into
base: devel
Choose a base branch
from

Conversation

Praveen91299
Copy link
Contributor

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

@kottmanj
Copy link
Collaborator

kottmanj commented Feb 9, 2024

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)

@Praveen91299
Copy link
Contributor Author

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.

@@ -176,9 +176,9 @@ def pick_backend(backend: str = None, samples: int = None, noise: NoiseModel = N
for f in INSTALLED_SAMPLERS.keys():
return f
else:
if samples is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will lead to too many clashes with other applications.
return type of tq.simulate(circuit) is not clear from context anymore (wavefunction or density matrix)

Propose the following: Add simulate_density_matrix method. Within the method, check backend and only allow qiskit (because the simulation is not supported for others currently, as far as I understand).

@kottmanj
Copy link
Collaborator

kottmanj commented Apr 5, 2024

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.

@Praveen91299
Copy link
Contributor Author

Hey Jakob, thanks for following up! Been a bit lazy on this, I'll get this done asap.

@kottmanj
Copy link
Collaborator

kottmanj commented Apr 5, 2024

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.

@Praveen91299
Copy link
Contributor Author

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.

  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())?

@kottmanj
Copy link
Collaborator

kottmanj commented Jul 1, 2024

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.

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

@kottmanj
Copy link
Collaborator

kottmanj commented Jul 9, 2024

General-Notes-31

@Praveen91299
Copy link
Contributor Author

Thanks for the flow chart! Will let you know if any questions and hopefully wrap his up soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants