Hi! I tried running pennylane with qulacs plugin recently and received error messages which I did not see before. Kindly help thanks!
Test code:
import pennylane as qml
dev = qml.device('qulacs.simulator',wires=2)
@qml.qnode(dev)
def circuit(x, y, z):
qml.RZ(z, wires=[0])
qml.RY(y, wires=[0])
qml.RX(x, wires=[0])
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(wires=1))
circuit(0.2, 0.1, 0.3)
If you want help with diagnosing an error, please put the full error message below:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [8], line 12
10 qml.CNOT(wires=[0, 1])
11 return qml.expval(qml.PauliZ(wires=1))
---> 12 circuit(0.2, 0.1, 0.3)
File ~\anaconda3\lib\site-packages\pennylane\qnode.py:950, in QNode.__call__(self, *args, **kwargs)
948 self.execute_kwargs.pop("mode")
949 # pylint: disable=unexpected-keyword-arg
--> 950 res = qml.execute(
951 [self.tape],
952 device=self.device,
953 gradient_fn=self.gradient_fn,
954 interface=self.interface,
955 gradient_kwargs=self.gradient_kwargs,
956 override_shots=override_shots,
957 **self.execute_kwargs,
958 )
960 res = res[0]
962 # convert result to the interface in case the qfunc has no parameters
File ~\anaconda3\lib\site-packages\pennylane\interfaces\execution.py:642, in execute(tapes, device, gradient_fn, interface, grad_on_execution, gradient_kwargs, cache, cachesize, max_diff, override_shots, expand_fn, max_expansion, device_batch_transform)
639 elif mapped_interface == "jax":
640 _execute = _get_jax_execute_fn(interface, tapes)
--> 642 res = _execute(
643 tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=max_diff
644 )
646 except ImportError as e:
647 raise qml.QuantumFunctionError(
648 f"{mapped_interface} not found. Please install the latest "
649 f"version of {mapped_interface} to enable the '{mapped_interface}' interface."
650 ) from e
File ~\anaconda3\lib\site-packages\pennylane\interfaces\autograd.py:319, in execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n, max_diff)
314 # pylint misidentifies autograd.builtins as a dict
315 # pylint: disable=no-member
316 parameters = autograd.builtins.tuple(
317 [autograd.builtins.list(t.get_parameters()) for t in tapes]
318 )
--> 319 return _execute(
320 parameters,
321 tapes=tapes,
322 device=device,
323 execute_fn=execute_fn,
324 gradient_fn=gradient_fn,
325 gradient_kwargs=gradient_kwargs,
326 _n=_n,
327 max_diff=max_diff,
328 )[0]
File ~\anaconda3\lib\site-packages\autograd\tracer.py:48, in primitive.<locals>.f_wrapped(*args, **kwargs)
46 return new_box(ans, trace, node)
47 else:
---> 48 return f_raw(*args, **kwargs)
File ~\anaconda3\lib\site-packages\pennylane\interfaces\autograd.py:363, in _execute(parameters, tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n, max_diff)
342 """Autodifferentiable wrapper around ``Device.batch_execute``.
343
344 The signature of this function is designed to work around Autograd restrictions.
(...)
360 understand the consequences!
361 """
362 unwrapped_tapes = tuple(convert_to_numpy_parameters(t) for t in tapes)
--> 363 res, jacs = execute_fn(unwrapped_tapes, **gradient_kwargs)
365 return res, jacs
File ~\anaconda3\lib\site-packages\pennylane\interfaces\execution.py:287, in cache_execute.<locals>.wrapper(tapes, **kwargs)
282 return (res, []) if return_tuple else res
284 else:
285 # execute all unique tapes that do not exist in the cache
286 # convert to list as new device interface returns a tuple
--> 287 res = list(fn(execution_tapes.values(), **kwargs))
289 final_res = []
291 for i, tape in enumerate(tapes):
File ~\anaconda3\lib\site-packages\pennylane\interfaces\execution.py:210, in cache_execute.<locals>.fn(tapes, **kwargs)
208 def fn(tapes: Sequence[QuantumTape], **kwargs): # pylint: disable=function-redefined
209 tapes = [expand_fn(tape) for tape in tapes]
--> 210 return original_fn(tapes, **kwargs)
File ~\anaconda3\lib\contextlib.py:79, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
76 @wraps(func)
77 def inner(*args, **kwds):
78 with self._recreate_cm():
---> 79 return func(*args, **kwds)
File ~\anaconda3\lib\site-packages\pennylane\_qubit_device.py:603, in QubitDevice.batch_execute(self, circuits)
598 for circuit in circuits:
599 # we need to reset the device here, else it will
600 # not start the next computation in the zero state
601 self.reset()
--> 603 res = self.execute(circuit)
604 results.append(res)
606 if self.tracker.active:
File ~\anaconda3\lib\site-packages\pennylane\_qubit_device.py:320, in QubitDevice.execute(self, circuit, **kwargs)
317 self.check_validity(circuit.operations, circuit.observables)
319 # apply all circuit operations
--> 320 self.apply(circuit.operations, rotations=self._get_diagonalizing_gates(circuit), **kwargs)
322 # generate computational basis samples
323 if self.shots is not None or circuit.is_sampled:
File ~\anaconda3\lib\site-packages\pennylane_qulacs\qulacs_device.py:147, in QulacsDevice.apply(self, operations, **kwargs)
144 def apply(self, operations, **kwargs):
145 rotations = kwargs.get("rotations", [])
--> 147 self.apply_operations(operations)
148 self._pre_rotated_state = self._state.copy()
150 # Rotating the state for measurement in the computational basis
File ~\anaconda3\lib\site-packages\pennylane_qulacs\qulacs_device.py:179, in QulacsDevice.apply_operations(self, operations)
177 self._apply_matrix(op)
178 else:
--> 179 self._apply_gate(op)
File ~\anaconda3\lib\site-packages\pennylane_qulacs\qulacs_device.py:287, in QulacsDevice._apply_gate(self, op)
284 par = op.parameters
286 mapped_operation = self._operation_map[op.name]
--> 287 if op.inverse:
288 mapped_operation = self._get_inverse_operation(mapped_operation, device_wires, par)
290 # Negating the parameters such that it adheres to qulacs
AttributeError: 'RZ' object has no attribute 'inverse'
And, finally, make sure to include the versions of your packages. Specifically, show us the output of qml.about()
.
Name: PennyLane
Version: 0.31.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
Author:
Author-email:
License: Apache License 2.0
Location: c:\users\sorac\anaconda3\lib\site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning, PennyLane-Orquestra, pennylane-qulacs
Platform info: Windows-10-10.0.19045-SP0
Python version: 3.9.13
Numpy version: 1.21.5
Scipy version: 1.9.3
Installed devices:
- default.gaussian (PennyLane-0.31.1)
- default.mixed (PennyLane-0.31.1)
- default.qubit (PennyLane-0.31.1)
- default.qubit.autograd (PennyLane-0.31.1)
- default.qubit.jax (PennyLane-0.31.1)
- default.qubit.tf (PennyLane-0.31.1)
- default.qubit.torch (PennyLane-0.31.1)
- default.qutrit (PennyLane-0.31.1)
- null.qubit (PennyLane-0.31.1)
- lightning.qubit (PennyLane-Lightning-0.31.0)
- qulacs.simulator (pennylane-qulacs-0.24.0)