# Buggy code
def decomposition(theta, pauli_word, wires):
    active_wires, active_gates = zip(
        *[(wire, gate) for wire, gate in zip(wires, pauli_word) if gate != "I"]
    )

    for wire, gate in zip(active_wires, active_gates):
        if gate == "X":
            Hadamard(wires=[wire])
        elif gate == "Y":
            RX(np.pi / 2, wires=[wire])

    MultiRZ(theta, wires=list(active_wires))

    for wire, gate in zip(active_wires, active_gates):
        if gate == "X":
            Hadamard(wires=[wire])
        elif gate == "Y":
            RX(-np.pi / 2, wires=[wire])


# Traceback (ValueError)
----------------------------------------------------
ValueError         Traceback (most recent call last)
<ipython-input-27-611f77c1af9c> in <module>
12     return qml.expval(qml.PauliX(1))
13
---> 14 print(apply_pauli_rots(0.345))

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/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

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/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

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/base.py in evaluate(self, args, kwargs)
817
818         if self.circuit is None or self.mutable:
--> 819             self._construct(args, kwargs)
820
821         self.device.reset()

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/jacobian.py in _construct(self, args, kwargs)
87         for each positional parameter.
88         """
---> 89         super()._construct(args, kwargs)
90         self.par_to_grad_method = {k: self._best_method(k) for k in self.variable_deps}
91

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/base.py in _construct(self, args, kwargs)
574
575         # check the validity of the circuit
--> 576         self._check_circuit(res)
577         del self.queue
578         del self.obs_queue

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/base.py in _check_circuit(self, res)
731         if self.device.operations:
732             # replace operations in the queue with any decompositions if required
--> 733             queue = decompose_queue(self.queue, self.device)
734
735         self.ops = queue + list(res)

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/base.py in decompose_queue(ops, device)
123     for op in ops:
124         try:
--> 125             new_ops.extend(_decompose_queue([op], device))
126         except NotImplementedError:
127             raise qml.DeviceError(

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/qnodes/base.py in _decompose_queue(ops, device)
98             new_ops.append(op)
99         else:
--> 100             decomposed_ops = op.decomposition(*op.data, wires=op.wires)
101             if op.inverse:
102                 decomposed_ops = qml.inv(decomposed_ops)

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/templates/decorator.py in wrapper(*args, **kwargs)
59     def wrapper(*args, **kwargs):
60         with OperationRecorder() as rec:
---> 61             func(*args, **kwargs)
62
63         return rec.queue

~/Software/anaconda3/envs/test-xanadu/lib/python3.8/site-packages/pennylane/ops/qubit.py in decomposition(theta, pauli_word, wires)
925     @template
926     def decomposition(theta, pauli_word, wires):
--> 927         active_wires, active_gates = zip(
928             *[(wire, gate) for wire, gate in zip(wires, pauli_word) if gate != "I"]
929         )

ValueError: not enough values to unpack (expected 2, got 0)

# Fixed code
def decomposition(theta, pauli_word, wires):
    # Catch cases when the wire is passed as a single int.
    if isinstance(wires, int):
        wires = [wires]

    # Check for identity and do nothing
    if pauli_word == "I" * len(wires):
        return

    active_wires, active_gates = zip(
        *[(wire, gate) for wire, gate in zip(wires, pauli_word) if gate != "I"]
    )

    for wire, gate in zip(active_wires, active_gates):
        if gate == "X":
            Hadamard(wires=[wire])
        elif gate == "Y":
            RX(np.pi / 2, wires=[wire])

    MultiRZ(theta, wires=list(active_wires))

    for wire, gate in zip(active_wires, active_gates):
        if gate == "X":
            Hadamard(wires=[wire])
        elif gate == "Y":
            RX(-np.pi / 2, wires=[wire])