-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decompose CnXGate grows exponentially in terms of CX, instead of linear #5872
Comments
How to decompose a gate in SU(2) into A, B, C : https://arxiv.org/abs/quant-ph/9503016 |
For a general unitary, not in SU(2), (i.e X gate) Theorem 4[1] seems to be applicable that gives a CNOT count that scales quadratic. According to the upper bound they give, it's beneficial to use their scheme only when n > 10. (however the bound they give seems not to be tight and i can think it can be improved). Even ancilla decompositions of
Can i work on this? |
Sure! |
Hi @georgios-ts ! Any news? |
I'm cleaning the assignees so it can be back to the pool of available |
Hi @1ucian0 , Can I work on this? |
Sounds good! @mtreinish should a synthesis interface be used for this? |
Hi @1ucian0 , We have been working on this issue. Instead of using theorem 5 in https://arxiv.org/abs/1501.06911 , this issue motivated us to develop a new decomposition that requires a smaller number of gates for SU(2) multi-controlled gates https://arxiv.org/abs/2302.06377. PR #8710 is the first step to solve this issue and reduces the number of gates in the MCXRecursive (that now is not recursive). |
@AlexisRalli: this issue and all the PRs that link to it above are what I was trying to find when you asked me about them the other day. For others' reference: Alexis had also had some ideas about the generalised MCU constructions (see #9574 for one part, but I think he had more in the works as well), who I then told @alexanderivrii and @ShellyGarion about. I don't have much to contribute myself to the discussion, just trying to link up all the folks I know about working on this, or things adjacent to this. |
Thanks @jakelishman, We intend to contribute with an n-qubit multi-controlled su(2) decomposition that requires ~16n cx if the gate has one real diagonal and ~20n for any other su2 gate. |
Hi everyone, I am reporting what we have done up until now about this issue. We found some problems that need a fix concerning multi-controlled gates: multi-controlled rotations grow exponentially #9741; MCXVChain with dirty ancilla not optimal #9740; and MCXRecursive not optimal #9743. We fixed the MCXVChain with dirty auxiliary qubits #9687 and the MCXRecursive #8710. We also fixed mcry and mcrx #9688. There is a conflict PR about multi-controlled rotations #9574. However, #9688 produces circuits with fewer cx gates because it implements our recent work about su(2) multi-controlled gates. We did not fix mcrz because the actual implementation of mcrz applies an mcp gate (not su(2)) #9202. I do not know if we should open a PR with a fix to mcrz because this will impact several test cases and other users. We would also like to contribute to #7505. |
@adjs @rafaella-vale - I looked again at your PRs #9688 and #9836.
gives:
|
@adjs @rafaella-vale - according to your paper [1] and to the function [1] https://arxiv.org/abs/2302.06377 However, this decomposition does not work properly, since it does not provide the expected operator:
gives Moreover,
produces a wrong matrix for the Toffoli gate (in the last line it should be
(*) Actually |
Another synthesis method for MCX gates: if we also allow ancillas, then I think that the best method appears here: |
Hi @ShellyGarion, in this PR #9687 the mcx requires 8k-6 cnots (and k-2 ancillary qubits) to implement a k-controlled mcx. PR #8710 improves the number of cx gates with one auxiliary qubit (lemma 9 of https://arxiv.org/pdf/1501.06911.pdf). It is also possible to decompose a multi controlled U(2) gate with linear circuit depth [1] and also with linear circuit size if we allow an approximation [2] . [1] https://journals.aps.org/pra/abstract/10.1103/PhysRevA.106.042602 |
The approximated multi controlled U(2) without ancillary qubits is implemented in qclib. pip install qclib import numpy as np
import qiskit
from qiskit.quantum_info import Operator
from qclib.gates.mcu import MCU
tol = 10**-2
n_controls = 11
X = np.array([[0, 1], [1, 0]])
qc = qiskit.QuantumCircuit(n_controls)
MCU.mcu(qc, X, list(range(n_controls-1)), n_controls-1, tol)
tqc = qiskit.transpile(qc, basis_gates=['u', 'cx'])
print('mcu # operations', tqc.count_ops())
qiskit_circuit = qiskit.QuantumCircuit(n_controls)
qiskit_circuit.mcx(list(range(n_controls-1)), n_controls-1)
qiskit_circuit.draw()
t_qiskit_circuit = qiskit.transpile(qiskit_circuit, basis_gates=['u', 'cx'])
print('qiskit # operations', t_qiskit_circuit.count_ops())
qc_matrix = Operator(qc).to_matrix()
qiskit_matrix = Operator(qiskit_circuit).to_matrix()
print(np.allclose(qc_matrix, qiskit_matrix, atol=tol)) will return
|
Thank you @adjs for referring us to your recent manuscripts [1] and [2]. Would you be interested in contributing the code to Qiskit? |
@thiagom123 and @JeffersonDeyvis can you implement approximate multi-controlled gate in qiskit? |
The primary focus of this issue is to decompose an However, I prefer to keep this issue open, as it discusses many algorithms to decompose an |
I am very happy to finally close this issue as all the PRs mentioned here have finally been merged! |
@anedumla noticed that theorem 5 in https://arxiv.org/abs/1501.06911 bounds the amount of CNOTs needed to decompose a SU(2) gate when (n-1)-controlled.
The bound of resulting CNOTs in the decomposition grows linearly with respect to the amount of controlled qubits. However, the decomposition of MCX groups exponentially:
What is the expected enhancement?
A non-ancilla decomposition of
QuantumCircuit.mcx()
should result in a linear amount of CNOTs. https://arxiv.org/abs/1501.06911 refers to https://arxiv.org/abs/quant-ph/9503016 for calculating A-B-C, that can be precomputed.In it's generic form, Theorem 5 can be applied any multi-controlled-W, where W \in SU(2). Therefore, I assume is can be generalised to fix the example #5840 by creating a possible decomposition.
The text was updated successfully, but these errors were encountered: