Problems with Forest plugin

I am very new to Pennylane and I am following the demo tutorials. Everything works fine at the moment, but I have problems with the PyTorch noisy demo. I create the device, but whet I try to run the circuit I get the following error.
Any suggestion to understand and solve the problem?

Many thanks!


KeyError                                  Traceback (most recent call last)
<ipython-input-23-ed065177fbb7> in <module>
      1 print(phi)
      2 print(theta)
----> 3 print(circuit(phi, theta))
      4 print(cost(phi, theta, 400))

C:\ProgramData\Anaconda3\lib\site-packages\pennylane\interfaces\ in custom_apply(*args, **kwargs)
    295         # [keyword_values[k] for k in sorted(keyword_positions, key=keyword_positions.get)]
--> 297         return _TorchQNode.apply(keyword_values, *args)
    299     return custom_apply

C:\ProgramData\Anaconda3\lib\site-packages\pennylane\interfaces\ in forward(ctx, input_kwargs, *input_)
    188             # evaluate the QNode
--> 189             res = qnode(*ctx.args, **ctx.kwargs)
    191             if not isinstance(res, np.ndarray):

C:\ProgramData\Anaconda3\lib\site-packages\pennylane\qnodes\ in __call__(self, *args, **kwargs)
    799         """Wrapper for :meth:`BaseQNode.evaluate`.
    800         """
--> 801         return self.evaluate(args, kwargs)
    803     def evaluate(self, args, kwargs):

C:\ProgramData\Anaconda3\lib\site-packages\pennylane\qnodes\ in evaluate(self, args, kwargs)
    826         if isinstance(self.device, qml.QubitDevice):
    827             # TODO: remove this if statement once all devices are ported to the QubitDevice API
--> 828             ret = self.device.execute(self.circuit, return_native_type=temp)
    829         else:
    830             ret = self.device.execute(

C:\ProgramData\Anaconda3\lib\site-packages\pennylane\ in execute(self, circuit, **kwargs)
    181         # apply all circuit operations
--> 182         self.apply(circuit.operations, rotations=circuit.diagonalizing_gates, **kwargs)
    184         # generate computational basis samples

C:\ProgramData\Anaconda3\lib\site-packages\pennylane_forest\ in apply(self, operations, **kwargs)
    148         # pylint: disable=attribute-defined-outside-init
    149         if self.parametric_compilation and "pyqvm" not in
--> 150             self.apply_parametric_program(operations, **kwargs)
    151         else:
    152             super().apply(operations, **kwargs)

C:\ProgramData\Anaconda3\lib\site-packages\pennylane_forest\ in apply_parametric_program(self, operations, **kwargs)
    179         for i, operation in enumerate(operations):
    180             # map the operation wires to the physical device qubits
--> 181             wires = self.remap_wires(operation.wires)
    183             if i > 0 and in ("QubitStateVector", "BasisState"):

C:\ProgramData\Anaconda3\lib\site-packages\pennylane_forest\ in remap_wires(self, wires)
    231         """
    232         if hasattr(self, "wiring"):
--> 233             return [int(self.wiring[i]) for i in wires]
    235         return [int(w) for w in wires]

C:\ProgramData\Anaconda3\lib\site-packages\pennylane_forest\ in <listcomp>(.0)
    231         """
    232         if hasattr(self, "wiring"):
--> 233             return [int(self.wiring[i]) for i in wires]
    235         return [int(w) for w in wires]

KeyError: <Wires = [0]>

Hi @AntonioPolicicchio!

The current release of the Forest plugin no longer works with PennyLane, due to some major changes in PennyLane over the last couple of months. You have two options:

  1. Install the latest GitHub version of the Forest plugin; this should continue to work with PennyLane:
pip install git+
  1. Use a different device for the tutorial. A good choice would be the Cirq or Qiskit devices which also allow for noisy simulations — for example, check out our tutorial on optimizing noisy circuits using Cirq. A full list of devices available can be found on our website: Plugins and ecosystem.

Hi @josh


Indeed now it works with sol. 1 :slight_smile: