Running the following code without qml
in the argument:
import pennylane as qml
from pennylane import numpy as np
n_register = 3
dev = qml.device('default.qubit', wires=(n_register), analytic=True)
@qml.qnode(dev)
def qft_rotations(n):
"""Performs qft on the first n qubits in circuit (without swaps)"""
n = int(n)
if n == 0:
return qml
n -= 1
qml.Hadamard(wires=n)
for qubit in range(n):
qml.CRZ(pi/2**(n-qubit), wires=[qubit, n])
qft_rotations(n)
def swap_registers(n):
for qubit in range(n//2):
qml.SWAP(wires = [qubit, n-qubit-1])
return qml
def qft(n):
"""QFT on the first n qubits in circuit"""
qft_rotations(qml, n)
swap_registers(qml, n)
return qml
result = qft(3)
print(result.draw())
gives this error:
TypeError Traceback (most recent call last)
<ipython-input-2-fe55010aff02> in <module>()
30 return qml
31
---> 32 result = qft(3)
33 print(result.draw())
<ipython-input-2-fe55010aff02> in qft(n)
26 def qft(n):
27 """QFT on the first n qubits in circuit"""
---> 28 qft_rotations(qml, n)
29 swap_registers(qml, n)
30 return qml
~\Anaconda3\lib\site-packages\pennylane\interfaces\autograd.py in __call__(self, *args, **kwargs)
67 self.set_trainable(args)
68 args = autograd.builtins.tuple(args) # pylint: disable=no-member
---> 69 return self.evaluate(args, kwargs)
70
71 @staticmethod
~\Anaconda3\lib\site-packages\autograd\tracer.py in f_wrapped(*args, **kwargs)
46 return new_box(ans, trace, node)
47 else:
---> 48 return f_raw(*args, **kwargs)
49 f_wrapped.fun = f_raw
50 f_wrapped._is_autograd_primitive = True
~\Anaconda3\lib\site-packages\pennylane\qnodes\base.py in evaluate(self, args, kwargs)
819
820 if self.circuit is None or self.mutable:
--> 821 self._construct(args, kwargs)
822
823 self.device.reset()
~\Anaconda3\lib\site-packages\pennylane\qnodes\jacobian.py in _construct(self, args, kwargs)
88 for each positional parameter.
89 """
---> 90 super()._construct(args, kwargs)
91 self.par_to_grad_method = {k: self._best_method(k) for k in self.variable_deps}
92
~\Anaconda3\lib\site-packages\pennylane\qnodes\base.py in _construct(self, args, kwargs)
550 # pylint: disable=attribute-defined-outside-init, too-many-branches, too-many-statements
551
--> 552 self.arg_vars, self.kwarg_vars = self._make_variables(args, kwargs)
553
554 # temporary queues for operations and observables
~\Anaconda3\lib\site-packages\pennylane\qnodes\base.py in _make_variables(self, args, kwargs)
482 arg_vars = [
483 i.item() if isinstance(i, np.ndarray) and i.ndim == 0 else i
--> 484 for i in unflatten(arg_vars, args)
485 ]
486
~\Anaconda3\lib\site-packages\pennylane\utils.py in unflatten(flat, model)
176 """
177 # pylint:disable=len-as-condition
--> 178 res, tail = _unflatten(np.asarray(flat), model)
179 if len(tail) != 0:
180 raise ValueError("Flattened iterable has more elements than the model.")
~\Anaconda3\lib\site-packages\pennylane\utils.py in _unflatten(flat, model)
158 res = []
159 for x in model:
--> 160 val, flat = _unflatten(flat, x)
161 res.append(val)
162 return res, flat
~\Anaconda3\lib\site-packages\pennylane\utils.py in _unflatten(flat, model)
162 return res, flat
163
--> 164 raise TypeError("Unsupported type in the model: {}".format(type(model)))
165
166
TypeError: Unsupported type in the model: <class 'module'>