Wire Error on IBM simulator

Hi there,

I’m attempting to run the following circuit as part of a VQA, I can draw the circuit, and it gives me what I’m looking for, but I keep getting a Wire error when I attempt to run it. For context, this should implement Circuit 19 of https://arxiv.org/pdf/1905.10876.pdf on p8.

code:
dev = qml.device(“qiskit.ibmq”,wires=11, backend=‘ibmq_qasm_simulator’)
@qml.qnode(dev)
def circuit19(params,n,x):

Requires 3n parameters

qml.templates.AngleEmbedding(x,wires=[i for i in range(n)])
index = 0

RX, RZ block

for i in range(n):
    qml.RX(params[index],wires=i)
    index += 1
    qml.RZ(params[index],wires=i)
    index += 1

CRX ring

qml.CRX(params[index], wires=[n-1,0])
index += 1

for i in range(n-1):
    qml.CRX(params[index],wires=[n-2-i,n-1-i])
    index +=1 

return [qml.expval(qml.PauliZ(i)) for i in range(n)]

I try to input
params = array([-0.0032389 , -0.01684838, 0.01511622, -0.00838866, 0.00166207,
-0.00150847, -0.0006588 , 0.01190467, 0.00847062, -0.00101217,
0.00827397, 0.0164149 , -0.0077316 , 0.00027279, -0.00364212,
-0.00350231, 0.00694448, -0.02124912, 0.02051644, 0.01000784,
-0.00304314, 0.00105156, 0.01869766, 0.00629439, 0.00031815,
0.02199048, -0.0043911 , -0.01440873, 0.01359715, 0.01457333,
0.02708231, 0.00355718, -0.01900089])
n = 11
x = array([ 0.78199136, 0.78347364, 1.28256651, -1.09202159, 1.04188643,
0.27299406, -0.11969382, 1.16452877, 1.87329371, 0.56716628,
1. ])

I’m then given the following error message:

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane_device.py”, line 346, in map_wires
mapped_wires = wires.map(self.wire_map)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane\wires.py”, line 271, in map
raise WireError(

WireError: No mapping for wire label 10 specified in wire map OrderedDict([(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]).

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File “”, line 1, in
circuit19(var,11,X_train[0])

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane\qnode.py”, line 598, in call
res = self.qtape.execute(device=self.device)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane\tape\tape.py”, line 1323, in execute
return self._execute(params, device=device)

File “C:\Users\josep\anaconda3\lib\site-packages\autograd\tracer.py”, line 48, in f_wrapped
return f_raw(*args, **kwargs)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane\interfaces\autograd.py”, line 165, in _execute
res = self.execute_device(params, device=device)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane\tape\tape.py”, line 1354, in execute_device
res = device.execute(self)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane_qubit_device.py”, line 192, in execute
self.apply(circuit.operations, rotations=circuit.diagonalizing_gates, **kwargs)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py”, line 211, in apply
applied_operations = self.apply_operations(operations)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane_qiskit\qiskit_device.py”, line 247, in apply_operations
device_wires = self.map_wires(operation.wires)

File “C:\Users\josep\anaconda3\lib\site-packages\pennylane_device.py”, line 348, in map_wires
raise WireError(

WireError: Did not find some of the wires <Wires = [tensor(10, requires_grad=True), 0]> on device with wires <Wires = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>.

Any help would be greatly appreciated.

Hi @JosephT :slight_smile:

You encountered a known quirk of PennyLane that we are trying to find a better workaround for. The package assumes all arguments are trainable by default, and so wraps any non-array input in an array.

This causes a problem with labelling wires, because 11 and np.array(11) have different hash values, and thus are different wires.

You can get the above code to work by calling

circuit19(params, n=n, x=x)

since keyword arguments are not wrapped.

Hi @christina,

Thanks for the explanation! That didn’t seem to work for me because the function call is then using undefined variables to give values. My workaround is just using:

n = int(n)

which redefines it within the function.

Glad it works for you now. We will keep your feedback in mind for future design and setting priorities on what to fix.