Skip to content

Multi-Control-X

The multi-control-X applies X gate to one target qubit bit only if the logical AND of all control qubits is satisfied. The multi-control-X function incorporates numerous implementations for the multi-control-X gate, each with a different depth and number of auxiliary qubits. These implementations generically outperform the Gray-code, V-chain and recursive implementations of Ref. [1], as well as the relative-phase Toffoli implementation of Ref. [2]. Given a sufficient number of auxiliary qubits, some implementations allow for logarithmic depth and linear CX-count. The synthesis process selects the appropriate implementation depending on the defined constraints.

Operator: control

Arguments:

  • ctrl: Union[QBit, QArray[QBit]]
  • operand: QCallable

Operator control takes a qubit array of length one or more as ctrl, and applies the operand if all qubits are in the 1 state

Example

The following example shows how to use the control operator to implement a Multi-Control-X where a 7-qubit quantum variable serves as the control

from classiq import (
    Output,
    QArray,
    QBit,
    X,
    allocate,
    control,
    create_model,
    prepare_bell_state,
    qfunc,
)


@qfunc
def main(cntrl: Output[QArray[QBit]], target: Output[QBit]) -> None:
    allocate(7, cntrl)
    allocate(1, target)
    control(ctrl=cntrl, operand=lambda: X(target))
qmod = create_model(main)
from classiq import synthesize, write_qmod

write_qmod(qmod, "mcx_example")
qprog = synthesize(qmod)

References

[1] A. Barenco et al, Elementary gates for quantum computation, Phys. Rev. A 52 (1995). https://journals.aps.org/pra/abstract/10.1103/PhysRevA.52.3457

[2] D. Maslov, Advantages of using relative-phase Toffoli gates with an application to multiple control Toffoli optimization, Phys. Rev. A 93 (2016). https://journals.aps.org/pra/abstract/10.1103/PhysRevA.93.022311