I am referring to the QuTIP package https://qutip.org/

To describe a system of 3 atoms in the ground state, I can crate the wavefunction: tensor( basis(2,0), basis(2,0), basis(2,0) )

Now suppose that I want to write a Python function that implements a system with N atoms in such a tensor product. If N=5, the system will look like:

tensor( basis(2,0), basis(2,0), basis(2,0), basis(2,0), basis(2,0) )

If N=100, you get the idea. How would I write the tensor product in a general way, for N tensor products?


1 Answer 1


good question - indeed the qutip API could use some improvements when dealing with tensor products. However, here python comes to the rescue with argument unpacking. To create a 4 qubit basis state, you can do e.g:

qp.tensor(*[qp.basis(2, 0) for _ in range(4)])

if you need more complicated arguments, you can build the list upfront and then unpack it, e.g:

args = [destroy(2)] + [qp.basis(2, 0) for _ in range(4)]

just keep in mind that this:

lst = [qp.basis(2, 0)] * 4

will not work as you probably expect it - it will create a list with 4 references to the same object, not initialize 4 different objects.

Let me know if this helps.

  • $\begingroup$ Thanks for the answer, this is helpful! Suppose I want to create the tensor qp.tensor( destroy(2), basis(2), basis(2), basis(2), basis(2) ) I thought I could use qp.tensor(destroy(2), *[qp.basis(2, 0) for _ in range(4)]) but this does not create a similar object. Do you know how to resolve this? $\endgroup$
    – Halo
    Feb 23, 2022 at 23:56
  • $\begingroup$ @Halo please see edit $\endgroup$
    – Lior
    Feb 24, 2022 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.