ValueError: Continuous variable operations and observables are not supported

I’m using pennylane-sf 0.29 and I want to use defer_measurements in conjunction with photon gates, the exact error statement is as follows

for i in range(num_modes):
        qml.cond(qml.measure(i, reset=True), qml.Kerr)(params[2*num_modes:3*num_modes], wires=[i + num_modes])

The following error occurred.

File /opt/conda/envs/tf1/lib/python3.9/site-packages/pennylane/drawer/draw.py:614, in _draw_mpl_qnode.<locals>.wrapper(*args, **kwargs_qnode)
    612 try:
    613     qnode.expansion_strategy = expansion_strategy or original_expansion_strategy
--> 614     qnode.construct(args, kwargs_qnode)
    615     program = qnode.transform_program
    616     [tape], _ = program([qnode.tape])

File /opt/conda/envs/tf1/lib/python3.9/site-packages/pennylane/workflow/qnode.py:986, in QNode.construct(self, args, kwargs)
    979 expand_mid_measure = (
    980     any(isinstance(op, MidMeasureMP) for op in self.tape.operations)
    981     and not isinstance(self.device, qml.devices.Device)
    982     and not self.device.capabilities().get("supports_mid_measure", False)
    983 )
    984 if expand_mid_measure or self.expansion_strategy == "device":
    985     # Assume that tapes are not split if old device is used since postselection is not supported.
--> 986     tapes, _ = qml.defer_measurements(self._tape, device=self.device)
    987     self._tape = tapes[0]
    989 if self.expansion_strategy == "device":

File /opt/conda/envs/tf1/lib/python3.9/site-packages/pennylane/transforms/core/transform_dispatcher.py:114, in TransformDispatcher.__call__(self, *targs, **tkwargs)
    111         return expand_processing(processed_results)
    113 else:
--> 114     transformed_tapes, processing_fn = self._transform(obj, *targs, **tkwargs)
    116 if self.is_informative:
    117     return processing_fn(transformed_tapes)

File /opt/conda/envs/tf1/lib/python3.9/site-packages/pennylane/transforms/defer_measurements.py:226, in defer_measurements(tape, **kwargs)
    223 if not any(isinstance(o, MidMeasureMP) for o in tape.operations):
    224     return (tape,), null_postprocessing
--> 226 _check_tape_validity(tape)
    228 device = kwargs.get("device", None)
    230 device = kwargs.get("device", None)

File /opt/conda/envs/tf1/lib/python3.9/site-packages/pennylane/transforms/defer_measurements.py:39, in _check_tape_validity(tape)
     33 obs_cv = any(
     34     isinstance(getattr(op, "obs", None), cv_types)
     35     and not isinstance(getattr(op, "obs", None), qml.Identity)
     36     for op in tape.measurements
     37 )
     38 if ops_cv or obs_cv:
---> 39     raise ValueError("Continuous variable operations and observables are not supported.")
     41 for mp in tape.measurements:
     42     if isinstance(mp, (CountsMP, ProbabilityMP, SampleMP)) and not (
     43         mp.obs or mp._wires or mp.mv
     44     ):

ValueError: Continuous variable operations and observables are not supported.

How to overcome the following problems with PENNY-SF 0.29. I really don’t want to use the Strawberry Fields programming language. Strawberry fields programming language is really hard to understand.

Hi @RX1 ,

Unfortunately, as the error says, continuous variable operations are not supported with mid-circuit measurements. Is there a reason why you need to use continuous variable operations? I would generally recommend using either PennyLane for gate-based computations or MrMustard for continuous-variable simulations. However note that they’re not compatible with each other and MrMustard has a completely different syntax.

Thank you for developing another new program, and it might be nice to have some tutorials. But I am already very familiar with Penny, and Penny has the adoration of many scholars. In terms of case studies, it is very rich, especially in the area of QML.

Hi @RX1, yes, we’ve put great care into the development of PennyLane. We’re happy to see that you really like it.