# 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:

**URL:** <https://discuss.pennylane.ai/t/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/2003>\
**Category:** PennyLane Help\
**Created:** [June 30, 2022, 1:25am UTC](https://discuss.pennylane.ai/t/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/2003 "2022-06-30T01:25:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RX1](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/rx1/32/698_2.png) [@RX1](https://discuss.pennylane.ai/u/RX1)\
**Post date:** [June 30, 2022, 1:25am UTC](https://discuss.pennylane.ai/t/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/2003/1 "2022-06-30T01:25:30Z")

</div>

How to fix this, I tried the suggestions in github still no solution

1：[https://github.com/PennyLaneAI/pennylane/issues/1459](https://github.com/PennyLaneAI/pennylane/issues/1459)

2：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..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..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..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**..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)]\>.

---

<div class="post-metadata">

**Author:** ![RX1](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/rx1/32/698_2.png) [@RX1](https://discuss.pennylane.ai/u/RX1)\
**Post date:** [June 30, 2022, 1:38am UTC](https://discuss.pennylane.ai/t/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/2003/2 "2022-06-30T01:38:24Z")

</div>

![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/f/f7612da6904c3cdb1193ab7bb18fef83b52c8247.png)

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [June 30, 2022, 6:47pm UTC](https://discuss.pennylane.ai/t/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/2003/3 "2022-06-30T18:47:17Z")

</div>

Hi @RX1,

Thank you for posting this here. Could you please copy-paste your full code? The image you pasted is not enough to reproduce the problem.
