# Create a mode-entangled state

I’m interested in making a passive linear interferometer circuitry acting on an initial mode-entangled state, for example: \frac{1}{\sqrt{2}}(a_0^{\dagger}a_2^{\dagger}+a_1^{\dagger}a_3^{\dagger}) in a 4 mode systems [0,4].
What is the best way to create such an initial state? Is there a way to insert it to a circuit without the actual procedure of making it? just define this state as the state of 2 photons in 4 modes and later apply some U on them.

Hi @segev!

We have the ops.Ket function which allows you to instantiate the Ket for the state. It prepares the state given the Ket vectors in the Fock basis.

Is this what you were looking for?

Yes! Thank you @CatalinaAlbornoz!
Do you have any example of using this in code? I can’t figure out what form of state it expects to get (what are the dimensions of the array and it’s format)

Hi @segev, you can input an array (with the first dimension same as the cutoff dimension) or a BaseFockState, where you can specify more information.

For example you can choose one of the following examples (note that the input state is not the same):

import strawberryfields as sf
import numpy as np

cutoff = 4
eng = sf.Engine("fock", backend_options={"cutoff_dim": cutoff})
prog = sf.Program(4)

with prog.context as q:
sf.ops.Ket(np.array([1,0,0,1])) | q[0]

result = eng.run(prog)
state = result.state
probs = state.all_fock_probs()
print(probs)


Or you can do

cutoff = 4
eng = sf.Engine("fock", backend_options={"cutoff_dim": cutoff})
state = sf.backends.BaseFockState(np.array([1,0,0,0]), 4, True, cutoff)
prog = sf.Program(4)

with prog.context as q:
sf.ops.Ket(state) | q[0]

result = eng.run(prog)
state = result.state
probs = state.all_fock_probs()
print(probs)


If you input an array into sf.ops.Ket, it should be a state vector in the Fock basis. This can be provided as either:

• a single ket vector, for single mode state preparation
• a multimode ket, with one array dimension per mode

If you choose a BaseFockState state object as the parameter type, then it already has all of the necessary information.

1 Like

Thanks @CatalinaAlbornoz it really helped. However, I’m still struggling with the multimode ket. I’ve tried this format of state:

import strawberryfields as sf
import numpy as np

cutoff = 2
eng = sf.Engine(“fock”, backend_options={“cutoff_dim”: cutoff})
prog = sf.Program(4)
state = sf.backends.BaseFockState(np.array([[0,1],[1,0],[1,0],[0,1]]), 4, True, cutoff)
with prog.context as q:
sf.ops.Ket(state) | (q[0],q[1],q[2],q[3])

result = eng.run(prog)
state = result.state
probs = state.all_fock_probs()
print(probs)

But it errored with:
ValueError: cannot reshape array of size 8 into shape (4,4)

Isnt this the multimode ket needed for describing the fock state: |1001>?

Hi @segev!

In this case, since you have a pure state, then the state representation in the Fock basis for the state |1001〉is just np.array([1,0,0,1]).

So you would just write
state = sf.backends.BaseFockState(np.array([1,0,0,1]), 4, True, cutoff)

Nice and simple!