Skip to content
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

Controlled Increment and Decrement Gates #43

Closed
AbdullahKazi500 opened this issue May 6, 2024 · 8 comments
Closed

Controlled Increment and Decrement Gates #43

AbdullahKazi500 opened this issue May 6, 2024 · 8 comments

Comments

@AbdullahKazi500
Copy link
Contributor

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.

@TomerGoldfriend
Copy link
Member

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.

@AbdullahKazi500
Copy link
Contributor Author

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

@TomerGoldfriend
Copy link
Member

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.

@AbdullahKazi500
Copy link
Contributor Author

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
Copy link
Contributor Author

AbdullahKazi500 commented May 8, 2024

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

@TomerGoldfriend
Copy link
Member

@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.

@AbdullahKazi500
Copy link
Contributor Author

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

@TomerGoldfriend
Copy link
Member

Great @AbdullahKazi500 , I have opened an issue for the notebook modification: #56. Let us start with it, and then we can discuss the addition of new functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants