An unknown error occurs when the qiskit plugin draws the circuit diagram

image

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 [49], in <cell line: 118>()
116 paras.append(np.random.random() * np.pi)
117 print(paras)
–> 118 circuit(paras)
119 dev._circuit.draw(output=‘mpl’)
120 paras =

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)]>.

ValueError Traceback (most recent call last)
Input In [61], in <cell line: 119>()
116 paras.append(np.random.random() * np.pi)
117 print(paras)
–> 119 fig, ax = qml.draw_mpl(circuit)(paras)
120 fig.show()
121 paras =

File d:\miniconda3\lib\site-packages\pennylane\drawer\draw.py:433, in draw_mpl..wrapper(*args, **kwargs_qnode)
429 qnode.expansion_strategy = original_expansion_strategy
431 _wire_order = wire_order or qnode.device.wires
–> 433 return tape_mpl(
434 qnode.qtape,
435 wire_order=_wire_order,
436 show_all_wires=show_all_wires,
437 decimals=decimals,
438 **kwargs,
439 )

File d:\miniconda3\lib\site-packages\pennylane\drawer\tape_mpl.py:279, in tape_mpl(tape, wire_order, show_all_wires, decimals, **kwargs)
277 if specialfunc is not None:
278 mapped_wires = [wire_map[w] for w in op.wires]
–> 279 specialfunc(drawer, layer, mapped_wires, op)
281 else:
282 control_wires = [wire_map[w] for w in op.control_wires]

File d:\miniconda3\lib\site-packages\pennylane\drawer\tape_mpl.py:63, in _add_barrier(drawer, layer, mapped_wires, op)
62 def _add_barrier(drawer, layer, mapped_wires, op):
—> 63 ymin = min(mapped_wires) - 0.5
64 ymax = max(mapped_wires) + 0.5
65 drawer.ax.vlines(layer - 0.05, ymin=ymin, ymax=ymax)

ValueError: min() arg is an empty sequence

Hi @RX1,

I think the problem is within the definition of your circuit.

I have created a full working example that may help you. Here I create a circuit with general rotation gates in each of the 4 qubits and then draw the circuit.

import pennylane as qml
from pennylane import numpy as np

qbits_for_single_word = 2
num_words = 2

# Create the random parameters
paras = []
for i in range(3*qbits_for_single_word*num_words):
    paras.append(np.random.random()*np.pi)
print(paras)

# Reshape the parameters for ease of use
par = np.reshape(paras,(qbits_for_single_word*num_words,3))
print(par)

# Create the device
dev = qml.device('default.qubit',wires=4)

# Create the qnode
@qml.qnode(dev)
def circuit(par):
    # Use broadcast to replicate the same gate in several wires
    qml.broadcast(qml.Rot, pattern="single", wires=[0,1,2,3], parameters=par)
    # Add a barrier at the end
    qml.Barrier(wires=[0,1,2,3])
    # Return a measurement
    return qml.expval(qml.PauliZ(0))

# Draw the circuit
qml.draw_mpl(circuit)(par)

# Another way to draw the circuit
fig,ax = qml.draw_mpl(circuit)(par)
fig.show()

As you can see this example prints out the circuit correctly. You can then add more keyword arguments to the drawer. For instance, in case you need to print the value of the parameters for each gate you can use the “decimals” keyword argument. You can learn more about the drawer in the docs!

Please let me know if this answers your question.

Does it exist “wires = 0”?

This problem always occurs, also because my parameter settings are not reasonable?

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 [5], in <cell line: 133>()
133 for i in range(n_steps):
134 costs_rotosolve =
–> 135 costs_rotosolve.append(cost(params_rsol))
136 params_rsol = rotosolve_cycle(cost, params_rsol)

Input In [5], in cost(params)
89 def cost(params):
—> 90 Z = circuit(params)
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)]>.

Hi @RX1,

Wires are 0-indexed so the first wire in your circuit will be wire 0. However when you create a device the minimum number of wires you can have is 1 since this is not an index but a quantity.

I have the impression that you’re passing a wires argument with the wrong type somewhere in your code. It’s hard to know for sure though.

The error traceback is not enough to find the source of your problem. If you can copy-paste your code here it can help. Please try to strip your code of anything that doesn’t contribute to the error.