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

Allow sparse matrix as circuit input #197

Open
royess opened this issue Dec 4, 2023 · 3 comments
Open

Allow sparse matrix as circuit input #197

royess opened this issue Dec 4, 2023 · 3 comments

Comments

@royess
Copy link
Contributor

royess commented Dec 4, 2023

Issue Description

In some cases, we would like a sparse matrix as circuit input.

Right now, this seems impossible because of type conversion. For example, DMCircuit does this:

dminputs = backend.convert_to_tensor(dminputs)

which throws an error like "TypeError: Failed to convert elements of SparseTensor(...) to Tensor" in TensorFlow.

Proposed Solution

I'm not sure whether we can just modify type conversions.

@refraction-ray
Copy link
Member

It is not only a type conversion. If you keep the input density matrix in sparse matrix form, how to deal with gate application in the language of tensor network in implementation level? It requires heavy code refactoring if possible.

An alternative is to use mpo_dminputs where you specify the input density matrix in the form of MPO instead of sparse matrix to save the memory. Of course, not every sparse matrix has efficient MPO representation, it depends on your sepcific user scenario.

@royess
Copy link
Contributor Author

royess commented Dec 4, 2023

OK, I can understand the difficulty.

If you keep the input density matrix in sparse matrix form, how to deal with gate application in the language of tensor network in implementation level?

Notice that sparse matrices for observable expectations are already implemented. I am wondering whether we can do a similar thing for input states. Because input states and observables seem to be dual to each other in my understanding.

@refraction-ray
Copy link
Member

refraction-ray commented Dec 4, 2023

Notice that sparse matrices for observable expectations are already implemented. I am wondering whether we can do a similar thing for input states. Because input states and observables seem to be dual to each other in my understanding.

A very interesting point! Of course the input state and the observable are dual where you can simulate the same quantity by specifying the observable as the input state in mpo_dminputs form and get the tensor network representation of the "density matrix". The final step will involved compute the trace of a mpo based matrix and a spares matrix then, which I am not sure whether there is a sparse matrix tailored primitive for this. In the pure state case, to compute some expectation, the final computation is a sparse matrix multiplied by the wavefunction vector which can be well captured by a sparse_matmul primitive.

Essentially, the observable expectation for sparse matrix is only valid for pure state simulator as well.

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

No branches or pull requests

2 participants