classiq-library icon indicating copy to clipboard operation
classiq-library copied to clipboard

Controlled Increment and Decrement Gates

Open AbdullahKazi500 opened this issue 1 year ago • 8 comments

Description The current quantum computing framework lacks built-in functionalities for performing controlled increment and decrement operations on quantum registers. These operations are essential for various quantum algorithms and simulations.

Proposed Solution Introduce two new gates:

Controlled Increment Gate (increment function): This gate performs a controlled increment operation on a quantum register. Iterates over each qubit in the register, applying multi-controlled Toffoli gates to increment the binary number by 1. Controlled Decrement Gate (decrement function): This gate performs a controlled decrement operation on a quantum register. Iterates over each qubit in the register, applying multi-controlled Toffoli gates to decrement the binary number by 1. Operation Details Controlled Increment Gate (increment function):

Iterates over each qubit in the register qr (from least significant to second-to-last qubit). For each qubit qr[j]: Apply a multi-controlled Toffoli gate with controls from qr[0] to qr[j], targeting qr[j+1]. Controlled Decrement Gate (decrement function):

Iterates over each qubit in the register qr (from least significant to second-to-last qubit). For each qubit qr[i]: Apply a multi-controlled Toffoli gate with controls from qr[0] to qr[i], targeting qr[i+1]. Motivation These gates are fundamental for implementing quantum arithmetic operations and can significantly enhance the capabilities of the quantum computing framework for algorithm development and simulations.

Additional Notes Ensure the gates are implemented efficiently using multi-controlled Toffoli gates (mct gates). Consider compatibility with various quantum simulators and hardware platforms supported by the framework. Proposed Changes Implement the increment(qc, qr) function to perform a controlled increment operation on the quantum register qr. Implement the decrement(qc, qr) function to perform a controlled decrement operation on the quantum register qr.

AbdullahKazi500 avatar May 06 '24 10:05 AbdullahKazi500

Thank you @AbdullahKazi500 for this issue. If I understand correctly, you are suggesting an addition of several functions to our open-library. Could you please explicitly specify what are the qmod declarations of these functions? (see examples of declarations in classiq-library/blob/main/functions/function_declarations/open_lib_decls.qmod).

The Increment/Decrement functions are essentially referred to in-place modular addition/subtraction by 1. Why are you interested in the controlled version of these? If you implement these then the controlled-operation can be achieved by the usual control construct.

TomerGoldfriend avatar May 06 '24 20:05 TomerGoldfriend

I Think it would be qfunc _ctrl_x<ref: int>(ctrl: qbit, aux: qbit); I wanted to make a tutorial on Quantum walks using generalized CNOT or increment decrement Gates

AbdullahKazi500 avatar May 07 '24 08:05 AbdullahKazi500

OK @AbdullahKazi500 , shouldn't ctrl or aux be an array of qubits (qbit[]) and not just a single qbit? In the next version release we are going to have a tutorial on quantum walks, thus, I suggest that we wait for the release and then see what exactly can be added. In the upcoming tutorial we use a QFT-based implementation for the increment and decrement functions. It might be nice to add another implementation based on the idea you have mentioned.

TomerGoldfriend avatar May 08 '24 08:05 TomerGoldfriend

Yes you are correct here . Quipper, control (ctrl) and auxiliary (aux) qubits are typically represented as arrays or lists of qubits rather than single qubits. I will wait for the next version release then

AbdullahKazi500 avatar May 08 '24 09:05 AbdullahKazi500

Maybe something like this qfunc controlled_increment(register: qbit[]); qfunc controlled_decrement(register: qbit[]);

AbdullahKazi500 avatar May 08 '24 09:05 AbdullahKazi500

@AbdullahKazi500 our new tutorial on discrete quantum walks are now out, see here.

I see two orthogonal ways to proceed:

  1. We can leave this issue for adding an increment and a decrement functions to our open library. We shall see which implementation to choose, maybe we will do several ones.
  2. In the new tutorial you can see that the increment is implemented as a "qft adder". We can add an example to the notebook that uses a different implementation, using a cascade of multi-controlled-X gates (as you mentioned above). What do you think? would you like to contribute this by yourself (we will of-course provide guidance, if needed). If yes, then I will open a separate issue for such contribution.

TomerGoldfriend avatar May 13 '24 11:05 TomerGoldfriend

of course that would be great let me think of someway to add this new functions @TomerGoldfriend I think you can open a separate issue and assign it to me

AbdullahKazi500 avatar May 13 '24 13:05 AbdullahKazi500

Great @AbdullahKazi500 , I have opened an issue for the notebook modification: https://github.com/Classiq/classiq-library/issues/56. Let us start with it, and then we can discuss the addition of new functions.

TomerGoldfriend avatar May 15 '24 06:05 TomerGoldfriend