Multi-Control-X¶
The multi-control-X gate 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.
Syntax¶
Function: Mcx
Parameters:
num_ctrl_qubits: Optional[int]
ctrl_state: Optional[str]
arguments: Optional[List[RegisterUserInput]]
The function requires passing either num_ctrl_qubits
or arguments
.
When the function is called with arguments
, the last qubit of the last argument
is taken to be the target (the qubit on which the X gate is applied).
All other qubits are the control qubits.
The following two calls are equivalent.
{
"function": "Mcx",
"function_params": {
"num_ctrl_qubits": 3,
"ctrl_state": "011"
}
}
{
"function": "Mcx",
"function_params": {
"arguments": [{ "size": 4, "name": "reg" }],
"ctrl_state": "011"
}
}
Example¶
The following example shows how to "mark" a single state in a superposition:
- Load a uniform superposition over 3 qubits using
StatePreparation
. - To mark a single state, e.g., '011', within this superposition, apply the multi-control-X gate on a target qubit where the 3-qubit register serves as the control register.
- Specify the state '011' in the
ctrl_state
field of the multi-control-X gate. Thus, an X gate is applied to the target qubit only for the control state '011'.
As a result, the target qubit is in state '1' only if the control register is in state '011'.
{
"functions": [
{
"name": "main",
"body": [
{
"function": "StatePreparation",
"function_params": {
"probabilities": [0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125],
"error_metric": { "KL": {"upper_bound": 0.3}}
},
"outputs": "sp_out"
},
{
"function": "Mcx",
"function_params": {"num_ctrl_qubits": 3, "ctrl_state": "011"},
"inputs": {
"CTRL_IN": "sp_out"
}
}
]
}
]
}
from classiq import Model, QReg, synthesize, show
from classiq.builtin_functions import Mcx, StatePreparation
model = Model()
probabilities = (0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125)
sp_params = StatePreparation(probabilities=probabilities)
x = model.StatePreparation(sp_params)["OUT"]
mcx_params = Mcx(num_ctrl_qubits=len(x), ctrl_state="011")
model.Mcx(mcx_params, in_wires={"CTRL_IN": x})
quantum_program = synthesize(model.get_model())
show(quantum_program)
Different constraints for the circuit depth and number of qubits result in different
implementations selected for the Mcx
function, as shown.
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