tensorly / quantum

Tensor-Based Quantum Machine Learning
http://tensorly.org/quantum/dev/
BSD 3-Clause "New" or "Revised" License
116 stars 17 forks source link

CNOT gate issue #6

Open marionsilv opened 2 years ago

marionsilv commented 2 years ago

Hello,

I have been trying to build a circuit with a CNOT gate acting on non-contiguous qubits (e.g., qubit 1 and 4), but I am finding strange results.

For example, if I choose an initial state [1,0,0,0]

and apply the unitary uni = tlq.Unitary([tlq.CNOTL(device=device, dtype=dtype), tlq.CNOTR(device=device, dtype=dtype), tlq.IDENTITY(dtype=dtype, device=device), tlq.IDENTITY(dtype=dtype, device=device)], nqubits, ncontraq, device=device, dtype=dtype)

I get (for the expected value of Sz): tensor([-1., -1., 1., 1.])

However, if I apply the CNOT cores to non-adjacent qubits in the same initial state, with uni = tlq.Unitary([tlq.CNOTL(device=device, dtype=dtype), tlq.IDENTITY(dtype=dtype, device=device), tlq.IDENTITY(dtype=dtype, device=device), tlq.CNOTR(device=device, dtype=dtype)], nqubits, ncontraq, device=device, dtype=dtype)

I find, again for the expected value of Sz: tensor([-2., 2., 2., 0.])

Is there any limitation regarding the CNOT cores that make it only valid for adjacent qubits, or am I doing something wrong? I am attaching a file with the full code for running: code.txt

Thanks for the help, Marion Silvestrini.

taylorpatti commented 2 years ago

Hi Marion,

Good to hear from you. Yes indeed, with our standard tensor network gates the two-qubit gates like CNOT are supposed to be next to each other.

We do have a tensor ring structure, so you can act a CNOT from the last qubit to the first qubit (as they are next to each other on the ring), but distant qubits cannot be connected in this way.

That being said, you can write an extension of gates that interact non-adjacent qubits by writing your own Unitary. If you write some test functions for this, I'd be happy to merge it into the general library. Something to keep in mind is that the size of the matrices that you will need in your tensor core will roughly grow as 2^{n+1}, where n is the number of qubits between the two qubits that you're interacting, so this distance can't go on forever.

rafaeleb commented 2 years ago

Hello all,

This is not a solution to the above issue, but it could be of interest anyway: a CNOT where the right qubit is the control. You can find the class here: https://github.com/rafaeleb/TLQ-cont I have not extensively tested it, but I think it works fine.

I am also interested in the class for non-adjacent qubits. I could not figure out the proper dimensionality of the left and right cores though, so any tip is welcome.

Rafael