One of my use cases essentially involves applying tomography on a subset of the states. For example, for a 4 qubit circuit I might only be interested in the coefficients for ket(0101),ket(1001),ket(0110),ket(1010). Now I know I can do qml.state() or find the probabilities then take the square root for the absolute value of this coefficient.
In general if we consider splitting the N qubits into two registers N = n + d. I am interested in the states with a single 1 in each of the registers. Clearly for a large number of qubits the states I’m interested in are only a small subset of the full system. Are there any computational tricks / pennylane methods to do this more efficiently instead of finding the full state vector then selecting from that?
The full application would involve states with a certain number of 1s in each of the registers but we can just stick to this simpler version for now.
My colleagues Nathan and Yushao mentioned a couple of things.
The statevector is already instantiated inside default.qubit, so you won’t really save computational resources by selecting some specific states upon measurement.
The physics context that you mentioned can become quite complex, especially if you increase the number of qubits. So doing something like what you’re asking for is not natively supported in PennyLane.
Thanks for the response I was playing around with it further and I would like to avoid using qml.state() as I’d like to use the lightning simulators and they don’t allow the result to be differentiated if qml.state() is used. My current implementation uses the sparse matrices you mentioned and batching over them for required expectation values.
Unfortunately, using these sparse matrices sp.csr_matrix doesn’t allow me to JIT my code. I did also try the built in Pennylane projector features but the memory usage for those is orders of magnitude larger. If you have any further suggestions that would be much appreciated or is there ever a plan to allow the usage of jax.experimental.sparse for the observables instead of just scipy?
Are you able to share a minimal reproducible example so that I can better understand your use case, your goals, and your issues? We’re working on support of sparse matrices but it’s hard to know if this will benefit you without seeing your code.