I would like to simulate a quantum circuit consisting of only single qubit gates, i.e. the quantum state in the circuit will always remain a product state. It is therefore unnecessary to keep track of the full state vector in the 2^N- dimensional space, and much more efficient to simply consider the circuit as N fully separate systems, each with a 2-dimensional state vector. I could simulate this by creating N different QNodes, but then I lose the convenience of having to deal with a single circuit, and also lose nice functionalities such as being able to plot and sample from the full circuit all at once. Is there some more clever way of doing this, or do I have to deal with N separate QNodes to accomplish this? Ideally, I would like to just create a single QNode for all qubits, but avoid keeping track of the 2^N-dimensional state vector.
I’m not sure if this will do what you need, but our default.tensor and lightning.tensor devices are made for tensor network simulations and support Matrix Product State (MPS) methods. The default.tensor device works on CPU while the lightning.tensor device works on certain NVIDIA GPUs. You can learn more in our performance page.
You can use these devices together with methods such as qml.MPS(), which allows you to encode your gates as a matrix product state. We have several demos on using matrix product states and tensor networks. You can find them here. I’m thinking the demo on simulating quantum circuits with tensor networks is probably the best one for you.
Let me know if you find what you need there, or if you have any follow up questions!
To be honest, I am only vaguely familiar with tensor networks, so I can not determine right of the bat whether this would allow me to simulate circuit of only single-qubit gates efficiently, the way I want to. I will take a look at the demos you refer to, to try and learn more.
Having read the suggested demos @CatalinaAlbornoz I do believe using the default.tensor device would indeed be well suited for my needs.
One follow-up question I have regarding the device is whether it supports sampling? In your recent tensor network demo Introducing tensor networks for quantum practitioners | PennyLane Demos an efficient sampling algorithm is discussed, which supposedly is also suppored by the Quimb backend. However, when trying to set the number of shots when creating an instance of the default.tensor device I am faced with the error DeviceError: default.tensor only supports analytic simulations with shots=None.
Does this mean sampling is not supported by the device, despite the fact that it is supported by the backend? Or am I simply making some mistake somewhere?
The sampling section of that demo mentions that you need a probability vector, and then generate the samples from that probability vector. So you’re not directly extracting samples from the circuit (it’s not supported with default.tensor). The demo talks about calculating the reduced density matrix and then calculating the terms one by one. I’m not sure how the code for this would look like but you can try following the description in the demo for a small circuit.
I’ll reach out to the author of that demo to see if he can provide any additional insights, but I’m not sure whether he’ll be available to respond.
As you are saying, it should be possible for me to implement this type of sampling functionality by hand, given the output probabilities of the circuit. However, I worry this might become slow and inefficient compared to the sampling provided by Quimb, which cleverly caches relevant sub-results. I suppose there is no clever way of accessing the Quimb backend functionalities, such as sampling, from the Pennylane device?