# MultiControlledX not working

**URL:** <https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182>\
**Category:** PennyLane Help\
**Created:** [September 12, 2024, 9:20pm UTC](https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182 "2024-09-12T21:20:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![therealsqueezingpand](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@therealsqueezingpand](https://discuss.pennylane.ai/u/therealsqueezingpand)\
**Post date:** [September 12, 2024, 9:20pm UTC](https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182/1 "2024-09-12T21:20:13Z")

</div>

Hi there!

I’m working on a circuit in PennyLane with `qml.MultiControlledX` and I’m unable to get it to work without error. Maybe there’s a bug here, but I’m confused, so not 100% confident.

Example code:

```import
dev = qml.device("default.qubit", wires=3)
@qml.qnode(dev)
def circuit(x):
    qml.Hadamard(0)
    qml.Hadamard(1)
    qml.RX(x, 0)
    qml.MultiControlledX([0,1], [0,1,2], [1,1])
    return qml.expval(qml.PauliZ(1) @ qml.PauliZ(2))

circuit(0.5)

```

When I run it, it says “ValueError: MultiControlledX accepts a single target wire.”

I also tried calling with the argument names (`qml.MultiControlledX(control_wires=[0,1], wires=[0,1,2], control_values=[1,1])`) and it also didn’t work.

Any help would be very nice 🙂

---

<div class="post-metadata">

**Author:** ![maldoalberto](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maldoalberto/32/2835_2.png) [@maldoalberto](https://discuss.pennylane.ai/u/maldoalberto)\
**Post date:** [September 17, 2024, 4:07pm UTC](https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182/2 "2024-09-17T16:07:57Z")

</div>

Hi @therealsqueezingpand !

Thank you for raising this point! Is a very particular situation and may help others 😄 .

Implementing `qml.MultiControlledX` works a bit differently. You can find more details in this [link](https://docs.pennylane.ai/en/stable/code/api/pennylane.MultiControlledX.html) if you’d like to explore further. Essentially, the `control_wires` parameter is not necessary. In the `wires` parameter, the last value corresponds to the target qubit, while the preceding values represent the control qubits.

```auto
dev = qml.device("default.qubit", wires=3)
@qml.qnode(dev)
def circuit(x):
    qml.Hadamard(0)
    qml.Hadamard(1)
    qml.RX(x, 0)
    qml.MultiControlledX(None,[0,1,2],[1,1])
    return qml.expval(qml.PauliZ(1) @ qml.PauliZ(2))

circuit(0.5)

```

You can avoid the parameter with the value `None`, or you can use this other way:

```auto
dev = qml.device("default.qubit", wires=3)
@qml.qnode(dev)
def circuit(x):
    qml.Hadamard(0)
    qml.Hadamard(1)
    qml.RX(x, 0)
    qml.MultiControlledX(wires=[0,1,2], control_values=[1,1])
    return qml.expval(qml.PauliZ(1) @ qml.PauliZ(2))

circuit(0.5)

```

in both case we avoid the parameter `control_wires`, and the result if is correct is the following image

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

I hope my answer was helpful 😃

In case it wasn’t clearer, or you need more information, let me know.

---

<div class="post-metadata">

**Author:** ![therealsqueezingpand](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@therealsqueezingpand](https://discuss.pennylane.ai/u/therealsqueezingpand)\
**Post date:** [September 18, 2024, 8:15pm UTC](https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182/3 "2024-09-18T20:15:05Z")

</div>

@maldoalberto Thanks for your answer! Your suggested code worked perfectly. I don’t know why I didn’t spot that before 🤦

---

<div class="post-metadata">

**Author:** ![maldoalberto](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maldoalberto/32/2835_2.png) [@maldoalberto](https://discuss.pennylane.ai/u/maldoalberto)\
**Post date:** [September 20, 2024, 12:23am UTC](https://discuss.pennylane.ai/t/multicontrolledx-not-working/5182/4 "2024-09-20T00:23:23Z")

</div>

@therealsqueezingpand, I’m glad it has helped you, as a recommendation is important read the documentation of the methods and if there is not something clear for that is the forum, or if you think you do not understand the text you can help to contribute to improve it with a PR 😃
