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

How should multi-controlled gates be added? #4451

Open
Cryoris opened this issue May 14, 2020 · 2 comments
Open

How should multi-controlled gates be added? #4451

Cryoris opened this issue May 14, 2020 · 2 comments

Comments

@Cryoris
Copy link
Contributor

Cryoris commented May 14, 2020

Multi-controlled gates are currently partially objects (MCX MCU1) and partially functions monkey-patched to the circuit (mcr*). Some, as the MCX, moved to the circuit library as Gate objects. In principle library objects can be added to the circuit using compose, but all multi-controlled gates right now are accessible as circuit methods.

This raises two questions:

  1. Which multi-controlled gates should have their proper class?
  2. How should they be added to circuits?

Possible solution:

  1. The ones where we know of multiple implementations, such as MCX, or where more efficient implementations that the standard control mechanism are known.

  2. Two options:
    a. Don't allow circuit methods:

    circuit.append(RXGate(0.2).control(5), [0, 1, 2, 3, 4, 5])
    circuit.compose(MCX(5))

    Advantage: Less circuit methods
    Problem: Verbose and need to import each gate to control

    b. Allow the controlled circuit methods to accept lists of qubits:

    circuit.crx(0.2, [0, 1, 2, 3, 4], 5)  # goes and does RXGate(0.2).control(5)
    circuit.cx([0, 1, 2, 3, 4], 5)  # goes and does MCX(5)

    maybe the cx is still qualified to have mcx to also allow arguments such as mode.
    Advantage: easy adding of multi-controlled gates, no additional methods
    Problem: circuit.cx([0,1], 2) currently means apply two CX gates.

    c. Keep mcrx as circuit method and

    circuit.mcrx(0.2, [0, 1, 2, 3, 4], 5)  # goes and does RXGate(0.2).control(5)
    circuit.mcx([0, 1, 2, 3, 4], 5)  # goes and does MCX(5)

    Advantage: easy adding of multi-controlled gates,
    But: additional methods

Personally I'd prefer 2b, since it gives us the power of multi-controlled gates with an intuitive and somewhat expected syntax and I'm not aware of a use-case for the current interpretation where cx([0, 1], 2) constructs two CX gates. Also adding special variants of a gate can be done using a mode flag which is a little more convenient than importing the gate and appending it, i.e.
circuit.cx(..., mode='v-chain') over from ... import MCXVChain; circuit.append(MCXVChain(), ...).

Are there opinions that the multi-controlled gates should only be library objects and not offer circuit methods? (@ajavadia @jaygambetta)

@nonhermitian
Copy link
Contributor

I'm not aware of a use-case for the current interpretation where cx([0, 1], 2) constructs two CX gates

This is actually quite nice to have, and saves writing a for-loop just to add gates where you know they are going to go. Useful for cluster states, GHZ states etc.

@ajavadia
Copy link
Member

ajavadia commented Nov 9, 2021

@nonhermitian you are right but I think an internal poll indicated that most people expected this to create a multi-controlled gate.

@kdk kdk removed this from the 0.19 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants