Extract MPS shape in default.tensor

Hello,

So I’ve been playing around with the default.tensor device for simulating quantum circuits. Since the device is based on QUIMB, I was wondering if when simulating a circuit, is there a way to output the MPS shape (i.e. all the bond dimensions in the chain) similar QUIMB? Another way of asking this is, is there a way to return the final state as a QUIMB’s MatrixProductState instance?

Or at least can we access the maximal bond dimension of the MPS decomposition when using:

dev = qml.device('default.tensor', method='mps', max_bond_dim= None)

Thanks!

I’m also new to PennyLane, but if I’m understanding your question correctly you can pull the max_bond_dim argument by just using dev._max_bond_dim

For example:

dev = qml.device('default.tensor', method='mps',  max_bond_dim= 123)
print(dev._max_bond_dim)

which prints:

123

I’m not positive if this was what you’re looking for or if there is a simpler way to extract the MPS state directly.

Hope this helps.

Hi! Thanks for your response, but that is not quite what I meant. So if you choose max_bond_dim=None, the MPS decomposition will be exact, i.e., it will take all the non-zero singular values in each SVD during the construction. What I would like to know is: in that “exact” MPS construction, where we set max_bond_dim=None, what is the maximum bond dimension, i.e. what is the maximum number of non-zero singular values obtained in the construction?

I hope this makes my question clearer. I’ve edited the tittle a little bit to (hopefully) make it clearer.

Thanks!

I may be incorrect, but I’m pretty sure if given some matrix M and it was encoded using PennyLane, it is done by initializing some np.ndarray and then it is flattened.

Would this not remove the ability to be able to determine the max bond dimension directly from the array?

I’m not sure I follow what you mean.

Basically, what I’m saying is that in QUIMB, when defining an MPS as a MatrixProductState instance, it allows you to extract each of the tensors composing the MPS “chain”. The shape of each tensor is of the form (i, j, k), where i and k are bond dimensions and j is the physical dimension (j=2 for qubit states).

You can always obtain the statevector as a dense array with the method to_dense() which will contract the tensor network into a flattened array of 2^num_qubits elements.

Since the backend of default.tensor is QUIMB, I’m wondering if I can do something similar here.

Hi @loruma, thank you for your question.

I’m checking with our team and will get back to you on this soon.

Hi @loruma

My colleague Pietropaolo found a way to obtain the information you need!

A way to access the underlying quimb instance of the circuit is by using the private class attribute _quimb_circuit:

import pennylane as qml

dev = qml.device("default.tensor", wires=2)

dev._quimb_circuit

The output is:

<Circuit(n=2, num_gates=0, gate_opts={'contract': 'auto-mps', 'propagate_tags': False, 'max_bond': None, 'cutoff': None, 'info': {}})>

The _quimb_circuit attribute allows manipulating the quimb instance that the device creates under the hood.

To get the MPS in a dense form we can do the following:

dev._quimb_circuit.psi.to_dense()

The output is:

array([[1.+0.j],
       [0.+0.j],
       [0.+0.j],
       [0.+0.j]])

Note: The _quimb_circuit attribute is private because it’s not compatible with PennyLane’s new device API, so things might break for certain workflows.

Let us know if this works for you or if you have trouble using it.

I hope this helps!

Hi @CatalinaAlbornoz! That is exactly what I needed!

When running

dev._quimb_circuit.psi

On a Jupyter notebook, it will output the MatrixProductState instance I was looking for.

Thanks a lot!

1 Like

I’m glad to hear @loruma !

Thanks for jumping in and offering to help @Classy ! Your discussion in the first few posts in this thread was useful to me to understand the issue/question. :heart:

Enjoy using PennyLane!

1 Like