Multi-Control-X¶
The multi-control-X gate applies X gate to one target qubit bit if and 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 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]]
One has to pass 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. First we
load a uniform superposition over 3 qubits using StatePreparation
. In order to mark a
single state, e.g '011', within this superposition, we apply the
multi-control-X gate on a target qubit where the 3-qubit register serves as the control
register. We 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' if and only if the
control register is in state '011'.
{
"constraints": {
"max_width": 20,
"max_depth": 50
},
"logic_flow": [
{
"function": "StatePreparation",
"function_params": {
"num_qubits": 3,
"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 ModelDesigner, QReg
from classiq.builtin_functions import Mcx, StatePreparation
QUBIT_COUNT = 20
MAX_DEPTH = 50
model_designer = ModelDesigner()
x = QReg(size=3)
probabilities = (0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125)
sp_params = StatePreparation(probabilities=probabilities, num_qubits=x.size)
model_designer.StatePreparation(sp_params, out_wires=x)
mcx_params = Mcx(num_ctrl_qubits=x.size, ctrl_state="011")
model_designer.Mcx(mcx_params, in_wires={"CTRL_IN": x})
circuit = model_designer.synthesize()
circuit.show()
Different constraints for the circuit depth and number of qubits results in different implementations selected for the Mcx function, as can be seen in the image below.
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, On the advantages of using relative phase Toffolis with an application to multiple control Toffoli optimization, Phys. Rev. A 93 (2016). https://journals.aps.org/pra/abstract/10.1103/PhysRevA.93.022311