Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Make `Identity` an `n` qubit bloq

Open anurudhp opened this issue 1 year ago • 6 comments

fixes #1207

  • Identity now accepts a bitsize, and has a single register q of QAny(bitsize).
  • Identity(n).controlled(m) is Identity(n + m).

more discussion: https://github.com/quantumlib/Qualtran/pull/1322#issuecomment-2299989824

anurudhp avatar Aug 21 '24 03:08 anurudhp

I'm still a little confused about why the Identity being a single qubit bloq is problematic, doesOnEach(Identity(), n).controlled(m) not do the same thing?

fdmalone avatar Aug 21 '24 18:08 fdmalone

I think OnEach(Identity(), n).controlled(m) would probably do the same thing; but I think it's nicer and cleaner to have an n-bit Identity operation that returns itself when controlled.

tanujkhattar avatar Aug 21 '24 18:08 tanujkhattar

Ok, should this still be a basic gate? I think the justification for moving it back to basic gates from #1322 was that it was more logically consistent to be among $I$, $X$, $Y$ and $Z$ and basic gates should probably be restricted to one and two qubit gates maybe? Please ignore me if it makes things easier / better / cleaner it's just the identity after all.

fdmalone avatar Aug 21 '24 18:08 fdmalone

Another subtle issue with OnEach(Identity(), n).controlled(m) is that it would produce m bloqs of OnEach(Identity(), n + 1) (because the control qubits are common), and therefore m * (n + 1) Identity() bloqs. Having a single Identity(n) makes it cleaner imo.

It also matches cirq.IdentityGate which accepts n qubits (with cirq.I being the one qubit specialization)

anurudhp avatar Aug 21 '24 18:08 anurudhp

SGTM. Do we need to have both? Probably not right?

fdmalone avatar Aug 21 '24 19:08 fdmalone

both as in?

anurudhp avatar Aug 21 '24 19:08 anurudhp

I'm still a little confused about why the Identity being a single qubit bloq is problematic, doesOnEach(Identity(), n).controlled(m) not do the same thing?

The motivation is that we have an identity bloq (that is somewhat out of our control; e.g. passed as a class attribute; e.g. in applyLthgate) that we want to control. We could return OnEach; but the spirit of qualtran is to give names to things

mpharrigan avatar Aug 21 '24 21:08 mpharrigan

SGTM. Do we need to have both? Probably not right?

Not 100% sure what's being asked here, but this PR keeps one Identity bloq that has a bitsize that defaults to 1, so there's only one thing to contend with.

mpharrigan avatar Aug 21 '24 21:08 mpharrigan