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

add ctrl_state to MCMT gate #10698

Closed
Muzhou-Ma opened this issue Aug 23, 2023 · 11 comments
Closed

add ctrl_state to MCMT gate #10698

Muzhou-Ma opened this issue Aug 23, 2023 · 11 comments
Labels
type: feature request New feature or request

Comments

@Muzhou-Ma
Copy link

What should we add?

Add ctrl_state to multi-control multi-target gates

@Muzhou-Ma Muzhou-Ma added the type: feature request New feature or request label Aug 23, 2023
@diemilio
Copy link
Contributor

I think this would be a nice feature to add. Willing to help implement it if looking for help.

@Dpbm
Copy link
Contributor

Dpbm commented Aug 31, 2023

This is awesome, for any help, I'm here too!

@ShashiQubit
Copy link

Hi! I am interested in working on this issue. Can this be assigned to me? .I would like to make my first contribution to qiskit terra.

@Dpbm
Copy link
Contributor

Dpbm commented Oct 2, 2023

Yeah man, if @diemilio and @Marsmmz also agree, you can do this! And if during your task you find some issues, please tell us and we may help you😁

@diemilio
Copy link
Contributor

diemilio commented Oct 2, 2023

Sure! I had volunteered to take care of this a little while back cause I had the time, but I never got it assigned.

@ShashiQubit
Copy link

@diemilio Thanks for the opportunity. I have started working on the issue following the contribution guide.

@Muzhou-Ma
Copy link
Author

Sorry for getting here late, I'll try my best to help!

@ShashiQubit
Copy link

@Marsmmz I have a question. Does MCMT controls need to be custom state?. Meaning should user given freedom to specify whether the state of control is 0 or 1 or mix like '01...' control state targeting q_k number of qubits. If yes what's best way to take that input from user, dictionary or list??

@Muzhou-Ma
Copy link
Author

Muzhou-Ma commented Nov 26, 2023

@Marsmmz I have a question. Does MCMT controls need to be custom state?. Meaning should user given freedom to specify whether the state of control is 0 or 1 or mix like '01...' control state targeting q_k number of qubits. If yes what's best way to take that input from user, dictionary or list??

I personally think users should have the freedom to specify the control state. Like if a 2-C-2-T gate is needed, users can specify which of '00', '01', '10', '11' they want to be the control state. Perhaps taking a 01 binary string as input is enough? What do you think?@ShashiQubit @diemilio @Dpbm

@ShashiQubit
Copy link

ShashiQubit commented Dec 7, 2023

@Marsmmz @diemilio @Dpbm I want feed back on this modified implementation of control function from source code of MCMT gate:

def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None):
        """Return the controlled version of the MCMT circuit."""
        mcmt_circuit = QuantumCircuit(self.num_ctrl_qubits + num_target_qubits)
        if isinstance(ctrl_state, str):
            if ctrl_state == '0':  # If '0', apply X gates to all control qubits (0-controlled)
                for i in range(self.num_ctrl_qubits):
                    mcmt_circuit.x(i)
                mcmt_circuit.append(MCMT(self.gate, self.num_ctrl_qubits + num_ctrl_qubits, self.num_target_qubits), mcmt_circuit.qubits)
                for i in range(self.num_ctrl_qubits):
                    mcmt_circuit.x(i)
            elif ctrl_state == '1':  # If '1', do nothing special to MCMT (1-controlled)
                mcmt_circuit.append(MCMT(self.gate, self.num_ctrl_qubits + num_ctrl_qubits, self.num_target_qubits), mcmt_circuit.qubits)
            else:  # If string of '0's and '1's, handle accordingly
                for i in range(len(ctrl_state)):
                    if ctrl_state[i] == '0':
                        mcmt_circuit.x(i)
                mcmt_circuit.append(MCMT(self.gate, self.num_ctrl_qubits + num_ctrl_qubits, self.num_target_qubits), mcmt_circuit.qubits)
                for i in range(len(ctrl_state)):
                    if ctrl_state[i] == '0':
                        mcmt_circuit.x(i)

        return mcmt_circuit

In this version, if the ctrl_state is '0', X gates are applied to all the control qubits both before and after the MCMT gate, so we have a "0-controlled" MCMT. If ctrl_state is '1', the MCMT gate is implemented directly without any extra X gates, meaning it's a regular "1-controlled" MCMT. If ctrl_state is a string containing '0's and '1's, X gates are applied before and after the MCMT gate to the qubits corresponding to '0's in ctrl_state.

Also what additional test cases are needed apart from the default ones already present for MCMT ? One that I could think is to check length of ctrl_state string matches the length of control qubits if ctrl_state is not None.

@ShellyGarion
Copy link
Member

Close by #13150.
The new MCMTGate now has a ctrl_state parameter (and the original MCMT gate would be deprecated in Qiskit 2.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants