# Error in Expectation value of the FockstateTF backend

**URL:** <https://discuss.pennylane.ai/t/error-in-expectation-value-of-the-fockstatetf-backend/4443>\
**Category:** Strawberry Fields\
**Created:** [April 15, 2024, 3:48pm UTC](https://discuss.pennylane.ai/t/error-in-expectation-value-of-the-fockstatetf-backend/4443 "2024-04-15T15:48:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhtzds](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hhtzds](https://discuss.pennylane.ai/u/hhtzds)\
**Post date:** [April 15, 2024, 3:48pm UTC](https://discuss.pennylane.ai/t/error-in-expectation-value-of-the-fockstatetf-backend/4443/1 "2024-04-15T15:48:50Z")

</div>

There is an error in using quad\_expectation in the FockstateTF backend

```auto
import strawberryfields as sf
from strawberryfields import ops

eng = sf.Engine("tf", backend_options={"cutoff_dim": 10})
prog = sf.Program(1)
with prog.context as q:
    Xgate(1) | q[0]

state= eng.run(prog).state
exp = state.quad_expectation([0])

```

The error message

```auto

InvalidArgumentError Traceback (most recent call last)
Cell In[36], line 10
      7 Xgate(1) | q[0]
      9 state= eng.run(prog5).state
---> 10 exp = state.quad_expectation([0])

File ~\anaconda3\Lib\site-packages\strawberryfields\backends\tfbackend\states.py:383, in FockStateTF.quad_expectation(self, mode, phi, **kwargs)
    380 if not self.batched:
    381 rho = tf.expand_dims(rho, 0) # add fake batch dimension
--> 383 flat_rho = tf.reshape(rho, [-1, self.cutoff_dim**2])
    384 flat_quad = tf.reshape(quad, [1, self.cutoff_dim**2])
    385 flat_quad2 = tf.reshape(quad2, [1, self.cutoff_dim**2])

File ~\anaconda3\Lib\site-packages\tensorflow\python\ops\weak_tensor_ops.py:88, in weak_tensor_unary_op_wrapper.<locals>.wrapper(*args, **kwargs)
     86 def wrapper(*args, **kwargs):
     87 if not ops.is_auto_dtype_conversion_enabled():
---> 88 return op(*args, **kwargs)
     89 bound_arguments = signature.bind(*args, **kwargs)
     90 bound_arguments.apply_defaults()

File ~\anaconda3\Lib\site-packages\tensorflow\python\util\traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    151 except Exception as e:
    152 filtered_tb = _process_traceback_frames(e. __traceback__ )
--> 153 raise e.with_traceback(filtered_tb) from None
    154 finally:
    155 del filtered_tb

File ~\anaconda3\Lib\site-packages\tensorflow\python\eager\execute.py:53, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     51 try:
     52 ctx.ensure_initialized()
---> 53 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
     54 inputs, attrs, num_outputs)
     55 except core._NotOkStatusException as e:
     56 if name is not None:

InvalidArgumentError: {{function_node __wrapped__ Reshape_device_/job:localhost/replica:0/task:0/device:CPU:0}} Input to reshape is a tensor with 1 values, but the requested shape requires a multiple of 100 [Op:Reshape]

```

How to solve this problem?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [April 16, 2024, 6:17pm UTC](https://discuss.pennylane.ai/t/error-in-expectation-value-of-the-fockstatetf-backend/4443/2 "2024-04-16T18:17:27Z")

</div>

Hi @hhtzds, welcome to the Forum!

You can solve this issue by removing the square brackets in the last line. So you specify just `0` instead of `[0]`.

Enjoy using Strawberry Fields!
