Error in quantumn neural network code fraud detection code

Hi,@tom Bromley

As discussed in below chat I have done the rectification step you had said.

But I am getting error in extracting the state

While giving

Ket = state.ket()

I m getting error like

“Result object has no attribute ket”

Can you pls help me for this issue…

I’m using the current version of strawberry fields.

Here in I’m attaching the Google Collab which I m using…

Feel free to edit

Hi @JEEVARATHINAM, welcome to the forum!

You’re getting this error because you haven’t actually extracted the state. This is how you can extract the state.

result =
state = result.state

After you do this then you can use state.ket()

You can learn more about states here in the docs.

Let me know if this solves your problem!

Now also I m getting error in next step

#Building up the function to minimize by looping through batch

for i in range(batch_size):
    # Probabilities corresponding to a single photon in either mode
    prob = tf.abs(ket[i, classification[i, 0], classification[i, 1]]) ** 2

In second line prob = I m getting error

It shows error like FockstateTf object is not subscriptable.

I m trying to run this code in current version…pls help…

This drive consist of files. You can use it work

Pls use the Colab notebook in the previous post

Feel free to edit


Looking forward to your support

Hi @JEEVARATHINAM, I think the problem is that you’re trying to extract information from “ket” in an invalid way: ket[i, classification[i, 0], classification[i, 1]])

Have you tried using state.fock_prob() to get the probabilities you need? I’m not sure if this will do what you’re looking for but it may help. You can read more about it here.

Please let me know if this helps!


I tried using fock_prob()

#extract the state
Ket = state.fock_prob()

It shows me error like.
"Result object has no attribute ‘fock_prob’

I’m trying to create solution for past three days.pls help

I also updated in google colab link in the first post pls check that too


Looking forward to your support @CatalinaAlbornoz @Maria_Schuld


I built this minimum working example which may help you move forward with your project

import strawberryfields as sf
prog = sf.Program(mode_number)

with prog.context as q:
    sf.ops.Sgate(0.54) | q[0]
    sf.ops.Sgate(0.54) | q[1]
    sf.ops.BSgate(0.43, 0.1) | (q[0], q[1])

eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 5})
result =
state = result.state
prob=state.fock_prob([0, 0])

As you can see in this example produces a result, and from that result you can extract the state. You can find a similar example here.
In your code you’re trying to extract the probabilities from the result instead of the state so this will cause an error.

On the other hand, if you look at the documentation for fock_prob you will notice that you need to input a parameter n.

" n ( Sequence [ int ] ) – the Fock state |→n⟩|n→⟩ that we want to measure the probability of"

In my example, n is [0,0].

Finally, you will notice that I changed the backend to “fock”. You can use “tf” as a backend but you may get some warnings about how you installed it.

I hope this helps you!

still i am getting error in same line

# Building up the function to minimize by looping through batch

for i in range(batch_size):

    # Probabilities corresponding to a single photon in either mode

    prob = tf.abs(prob[i, classification[i, 0], classification[i, 1]]) ** 2

i m getting error in prob=

the error is:

IndexError: invalid index to scalar variable.

kindly check the colab link


pls support.

Hi @JEEVARATHINAM, as you can see in the previous cell, “prob” is a scalar number. This means that prob[a,b,c] is invalid because it’s a single number, not a list.

I hope this helps!

Yes you are correct. In such case how we are going to proceed with code.
Can you please help me on that



I’m not sure what you want to do. fock_prob gives you the probability of a specific fock state so you have to decide what you want to do with that information, and even decide whether or not that’s the information you need.

Thanks for your response
code worked

I’m glad it worked @JEEVARATHINAM!