My proj is from https://pennylane.ai/qml/demos/tutorial_rotoselect.html
In verifying the application of this theory in more complex circuits, the following problems occurred.
How to fix this, I tried the suggestions in github still no solution ? How to fix this, I tried the suggestions in github still no solution,
https://github.com/PennyLaneAI/pennylane/issues/1459
> WireError Traceback (most recent call
> last) File d:\miniconda3\lib\site-packages\pennylane\_device.py:369,
> in Device.map_wires(self, wires)
> 368 try:
> --> 369 mapped_wires = wires.map(self.wire_map)
> 370 except WireError as e:
>
> File d:\miniconda3\lib\site-packages\pennylane\wires.py:273, in
> Wires.map(self, wire_map)
> 272 if w not in wire_map:
> --> 273 raise WireError(f"No mapping for wire label {w} specified in wire map {wire_map}.")
> 275 new_wires = [wire_map[w] for w in self]
>
> WireError: No mapping for wire label 0 specified in wire map
> OrderedDict([(tensor(18, requires_grad=True), 0)]).
>
> The above exception was the direct cause of the following exception:
>
> WireError Traceback (most recent call
> last) Input In [11], in <cell line: 137>()
> 136 costs_rotosolve = []
> 137 for i in range(n_steps):
> --> 139 costs_rotosolve.append(cost(params_rsol, wires))
> 140 params_rsol = rotosolve_cycle(cost, params_rsol)
> 142 params_gd = init_params.copy()
>
> Input In [11], in cost(params, wires)
> 89 def cost(params, wires):
> ---> 90 Z = circuit(params, wires)
> 91 return Z
>
> File d:\miniconda3\lib\site-packages\pennylane\qnode.py:576, in
> QNode.__call__(self, *args, **kwargs)
> 569 using_custom_cache = (
> 570 hasattr(cache, "__getitem__")
> 571 and hasattr(cache, "__setitem__")
> 572 and hasattr(cache, "__delitem__")
> 573 )
> 574 self._tape_cached = using_custom_cache and self.tape.hash in cache
> --> 576 res = qml.execute(
> 577 [self.tape],
> 578 device=self.device,
> 579 gradient_fn=self.gradient_fn,
> 580 interface=self.interface,
> 581 gradient_kwargs=self.gradient_kwargs,
> 582 override_shots=override_shots,
> 583 **self.execute_kwargs,
> 584 )
> 586 if autograd.isinstance(res, (tuple, list)) and len(res) == 1:
> 587 # If a device batch transform was applied, we need to 'unpack'
> 588 # the returned tuple/list to a float. (...)
> 595 # TODO: find a more explicit way of determining that a batch transform
> 596 # was applied.
> 598 res = res[0]
>
> File
> d:\miniconda3\lib\site-packages\pennylane\interfaces\execution.py:409,
> in execute(tapes, device, gradient_fn, interface, mode,
> gradient_kwargs, cache, cachesize, max_diff, override_shots,
> expand_fn, max_expansion, device_batch_transform)
> 402 interface_name = [k for k, v in INTERFACE_NAMES.items() if interface in v][0]
> 404 raise qml.QuantumFunctionError(
> 405 f"{interface_name} not found. Please install the latest "
> 406 f"version of {interface_name} to enable the '{interface}' interface."
> 407 ) from e
> --> 409 res = _execute(
> 410 tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=max_diff, mode=_mode
> 411 )
> 413 return batch_fn(res)
>
> File
> d:\miniconda3\lib\site-packages\pennylane\interfaces\autograd.py:64,
> in execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs,
> _n, max_diff, mode)
> 58 tape.trainable_params = qml.math.get_trainable_indices(params)
> 60 parameters = autograd.builtins.tuple(
> 61 [autograd.builtins.list(t.get_parameters()) for t in tapes]
> 62 )
> ---> 64 return _execute(
> 65 parameters,
> 66 tapes=tapes,
> 67 device=device,
> 68 execute_fn=execute_fn,
> 69 gradient_fn=gradient_fn,
> 70 gradient_kwargs=gradient_kwargs,
> 71 _n=_n,
> 72 max_diff=max_diff,
> 73 )[0]
>
> File d:\miniconda3\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
> d:\miniconda3\lib\site-packages\pennylane\interfaces\autograd.py:108,
> in _execute(parameters, tapes, device, execute_fn, gradient_fn,
> gradient_kwargs, _n, max_diff)
> 87 """Autodifferentiable wrapper around ``Device.batch_execute``.
> 88
> 89 The signature of this function is designed to work around Autograd restrictions. (...)
> 105 understand the consequences!
> 106 """
> 107 with qml.tape.Unwrap(*tapes):
> --> 108 res, jacs = execute_fn(tapes, **gradient_kwargs)
> 110 for i, r in enumerate(res):
> 112 if isinstance(res[i], np.ndarray):
> 113 # For backwards compatibility, we flatten ragged tape outputs
> 114 # when there is no sampling
>
> File
> d:\miniconda3\lib\site-packages\pennylane\interfaces\execution.py:165,
> in cache_execute.<locals>.wrapper(tapes, **kwargs)
> 161 return (res, []) if return_tuple else res
> 163 else:
> 164 # execute all unique tapes that do not exist in the cache
> --> 165 res = fn(execution_tapes.values(), **kwargs)
> 167 final_res = []
> 169 for i, tape in enumerate(tapes):
>
> File
> d:\miniconda3\lib\site-packages\pennylane\interfaces\execution.py:90,
> in cache_execute.<locals>.fn(tapes, **kwargs)
> 88 def fn(tapes, **kwargs): # pylint: disable=function-redefined
> 89 tapes = [expand_fn(tape) for tape in tapes]
> ---> 90 return original_fn(tapes, **kwargs)
>
> File d:\miniconda3\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
> d:\miniconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py:428,
> in QiskitDevice.batch_execute(self, circuits)
> 425 def batch_execute(self, circuits):
> 426 # pylint: disable=missing-function-docstring
> --> 428 compiled_circuits = self.compile_circuits(circuits)
> 430 # Send the batch of circuit objects using backend.run
> 431 self._current_job = self.backend.run(compiled_circuits, shots=self.shots, **self.run_args)
>
> File
> d:\miniconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py:417,
> in QiskitDevice.compile_circuits(self, circuits)
> 413 for circuit in circuits:
> 414 # We need to reset the device here, else it will
> 415 # not start the next computation in the zero state
> 416 self.reset()
> --> 417 self.create_circuit_object(circuit.operations, rotations=circuit.diagonalizing_gates)
> 419 compiled_circ = self.compile()
> 420 compiled_circ.name = f"circ{len(compiled_circuits)}"
>
> File
> d:\miniconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py:230,
> in QiskitDevice.create_circuit_object(self, operations, **kwargs)
> 218 """Builds the circuit objects based on the operations and measurements
> 219 specified to apply.
> 220 (...)
> 226 pre-measurement into the eigenbasis of the observables.
> 227 """
> 228 rotations = kwargs.get("rotations", [])
> --> 230 applied_operations = self.apply_operations(operations)
> 232 # Rotating the state for measurement in the computational basis
> 233 rotation_circuits = self.apply_operations(rotations)
>
> File
> d:\miniconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py:269,
> in QiskitDevice.apply_operations(self, operations)
> 265 circuits = []
> 267 for operation in operations:
> 268 # Apply the circuit operations
> --> 269 device_wires = self.map_wires(operation.wires)
> 270 par = operation.parameters
> 272 for idx, p in enumerate(par):
>
> File d:\miniconda3\lib\site-packages\pennylane\_device.py:371, in
> Device.map_wires(self, wires)
> 369 mapped_wires = wires.map(self.wire_map)
> 370 except WireError as e:
> --> 371 raise WireError(
> 372 f"Did not find some of the wires {wires} on device with wires {self.wires}."
> 373 ) from e
> 375 return mapped_wires
>
> WireError: Did not find some of the wires <Wires = [0]> on device with
> wires <Wires = [tensor(18, requires_grad=True)]>.
tensor(18, requires_grad=True)
, it should be something like wires=5 $\endgroup$