This is the contents of a file that I’m trying to import,
import pennylane as qml
from catalyst import qjit
from pennylane.numpy import pi, tensor
from pennylane.operation import Operation
class StronglyEntanglingLayer(Operation):
num_params = 6
num_wires = 2
grad_method = None
grad_recipe = ([[0.5, 1, pi / 2], [-0.5, 1, -pi / 2]],)
@qjit
def compute_decomposition(
weight0: tensor,
weight1: tensor,
weight2: tensor,
weight3: tensor,
weight4: tensor,
weight5: tensor,
wires: list,
):
op_list = [
qml.RZ(weight0, wires=wires[0]),
qml.RZ(weight1, wires=wires[1]),
qml.RY(weight2, wires=wires[0]),
qml.RY(weight3, wires=wires[1]),
qml.RZ(weight4, wires=wires[0]),
qml.RZ(weight5, wires=wires[1]),
qml.CNOT(wires=[wires[0], wires[1]]),
qml.CNOT(wires=[wires[1], wires[0]]),
]
return op_list
This is the error message that I get shown when trying to import the above
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/api_util.py:450, in shaped_abstractify(x)
449 try:
--> 450 return _shaped_abstractify_handlers[type(x)](x)
451 except KeyError:
KeyError: <class 'type'>
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/dtypes.py:101, in _canonicalize_dtype(x64_enabled, allow_opaque_dtype, dtype)
100 try:
--> 101 dtype_ = np.dtype(dtype)
102 except TypeError as e:
TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.ndarray' objects>' as a data type
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
File /project_title/.venv/lib/python3.11/site-packages/catalyst/compilation_pipelines.py:214, in CompiledFunction.get_runtime_signature(*args)
213 for arg in args:
--> 214 r_sig.append(jax.api_util.shaped_abstractify(arg))
215 return r_sig
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/api_util.py:452, in shaped_abstractify(x)
451 except KeyError:
--> 452 return _shaped_abstractify_slow(x)
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/api_util.py:441, in _shaped_abstractify_slow(x)
440 if hasattr(x, 'dtype'):
--> 441 dtype = dtypes.canonicalize_dtype(x.dtype, allow_opaque_dtype=True)
442 else:
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/dtypes.py:117, in canonicalize_dtype(dtype, allow_opaque_dtype)
116 def canonicalize_dtype(dtype: Any, allow_opaque_dtype: bool = False) -> Union[DType, OpaqueDType]:
--> 117 return _canonicalize_dtype(config.x64_enabled, allow_opaque_dtype, dtype)
File /project_title/.venv/lib/python3.11/site-packages/jax/_src/dtypes.py:103, in _canonicalize_dtype(x64_enabled, allow_opaque_dtype, dtype)
102 except TypeError as e:
--> 103 raise TypeError(f'dtype {dtype!r} not understood') from e
105 if x64_enabled:
TypeError: dtype <attribute 'dtype' of 'numpy.ndarray' objects> not understood
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
Cell In[1], line 8
5 import matplotlib.pyplot as plt
7 import quantum.project_title.data.data_generation as data_gen
----> 8 from quantum.project_title.circuit_components.ansatz import StronglyEntanglingLayer
9 from quantum.project_title.circuit_components.data_loader import PriceLoader
10 from quantum.project_title.utils.utils import (angle_encode_spot_price,
11 normalize_option_price,
12 decode,
13 calculate_delta)
File /project_title/quantum/project_title/circuit_components/ansatz.py:7
3 from pennylane.numpy import pi, tensor
4 from pennylane.operation import Operation
----> 7 class StronglyEntanglingLayer(Operation):
8 num_params = 6
9 num_wires = 2
File /project_title/quantum/project_title/circuit_components/ansatz.py:13, in StronglyEntanglingLayer()
10 grad_method = None
11 grad_recipe = ([[0.5, 1, pi / 2], [-0.5, 1, -pi / 2]],)
---> 13 @qjit
14 def compute_decomposition(
15 weight0: tensor,
16 weight1: tensor,
17 weight2: tensor,
18 weight3: tensor,
19 weight4: tensor,
20 weight5: tensor,
21 wires: list,
22 ):
23 op_list = [
24 qml.RZ(weight0, wires=wires[0]),
25 qml.RZ(weight1, wires=wires[1]),
(...)
31 qml.CNOT(wires=[wires[1], wires[0]]),
32 ]
33 return op_list
File /project_title/.venv/lib/python3.11/site-packages/catalyst/compilation_pipelines.py:675, in qjit(fn, target, keep_intermediate, verbose, logfile)
588 """A just-in-time decorator for PennyLane and JAX programs using Catalyst.
589
590 This decorator enables both just-in-time and ahead-of-time compilation,
(...)
671 :class:`~.pennylane_extensions.QJITDevice`.
672 """
674 if fn is not None:
--> 675 return QJIT(fn, target, keep_intermediate, CompileOptions(verbose, logfile))
677 def wrap_fn(fn):
678 return QJIT(fn, target, keep_intermediate, CompileOptions(verbose, logfile))
File /project_title/.venv/lib/python3.11/site-packages/catalyst/compilation_pipelines.py:484, in QJIT.__init__(self, fn, target, keep_intermediate, compile_options)
482 self.user_typed = True
483 if target in ("mlir", "binary"):
--> 484 self.mlir_module = self.get_mlir(*parameter_types)
485 if target == "binary":
486 self.compiled_function = self.compile()