Initialize state for a quantum circuit

Hi,

I’m new to ITensors and the entire field of MPS and tensor networks, so I might be missing something fundamental.

I’m trying to write code that simulates quantum gates, but when I attempt to initialize an entangled state, the results are not as expected. I referred to this discussion: MPS Initialization Through State Vector and wrote the following code:

N = 2
A = normalize([1, 1, 0, 0])
sites = siteinds("Qubit",N)

m = MPS(A, sites)
gates_mpo = ops(sites, [("H", 1)])
ψ = apply(gates_mpo, m)

After applying the gate, I used the sample function multiple times (or a custom function based on the example here MPS and MPO Examples · ITensors.jl that returns the amplitude vector). However, the results were always limited to the state [1,1], or the amplitude vector:

4-element Vector{ComplexF64}:
 0.9999999999999998 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im

This does not match the expected outcome. It seems as though the Hadamard gate was applied to the second qubit instead of the first.

However, when I replaced A with a computational basis vector, such as [1, 0, 0, 0], the result was as expected:

4-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
                0.0 + 0.0im
 0.7071067811865475 + 0.0im
                0.0 + 0.0im

I tried constructing the MPS as a sum of computational basis MPS states, weighted by their corresponding amplitudes. This approach worked, but I’m concerned that it might not be efficient in terms of runtime.

I would appreciate any insights into why this happens. Thanks!

Hi @Shachar,
I think there is a misunderstanding on the basis used.

Long explanation on the basis used

The basis used is the usual lexicographic computational basis, i.e. in your case, the first element of the vector A is mapped to the state (1,1)

Starting index mapped index
1 (1,1)
2 (2,1)
3 (1,2)
4 (2,2)

Which means that the vector you are passing is interpreted as the state (in bra-ket) notation

\frac 1{\sqrt{2}} (\ket{00} + \ket{10})

Or calling \ket{+}=(\ket0+\ket1), your starting state is:

\psi_0=\ket{+}\ket{0}

Since the Hamard Gate maps \ket{+}=>\ket0 by applying it to the first site in the state \psi_0 you obtain the state \ket{00}, which is coherent with your sampling results.

If you are interested to the state

\ket{\phi^+}=\frac 1{\sqrt{2}}(\ket{00} +\ket{11})

Using the table above, this is obtained from the vector A=normalize([1. 0. 0. 1.]).

Probably the most user friendly solution is to construct the ITensor first as follows:

s1, s2 = siteinds("Qubit", 2)
A=ITensor(s1, s2)
A[s1=>1, s2=>1] = 1.
A[s1=>2, s2=>2] =1.
psi = normalize(MPS(A, (s1, s2)))
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.