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 get_inverse features #249

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Youngcius
Copy link

@Youngcius Youngcius commented Jun 3, 2024

  1. Add get_inverse and get_inverse_params features for all single-qubit and two-qubit constant and parameterized gates
  2. Add necessary gate definitions and corresponding OpenQASM definitions
  3. Remedy a format-string line in "passes/mapping/placement/trivial.py" that leads to testing errors
    fixes Add missing get_inverse definitions #227

Copy link
Member

@edyounis edyounis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Thanks for doing this!

Address the comments, then I will do a final check on all the math, and we will be good to go!

Let me know if you have any concerns or questions.

@@ -8,6 +8,7 @@
from bqskit.ir.gates.constant.clock import ClockGate
from bqskit.ir.gates.constant.cpi import CPIGate
from bqskit.ir.gates.constant.cs import CSGate
from bqskit.ir.gates.constant.csdg import CSDGGate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep convention and have the dg be lower case. This applies everywhere and to all new gates.

'ZGate',
'ZZGate',
'ZZDGGate',
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to add the new gates to the autodoc in bqskit.ir.gates.__init__.py

If you can automate that, that would be awesome!

from bqskit.qis.unitary.unitarymatrix import UnitaryMatrix


class CSDGGate(ConstantGate, QubitGate):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the CTGate?

"""This module implements the CSDGGate."""
from __future__ import annotations

from bqskit.ir.gate import Gate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import should be under a TYPE_CHECKING clause everywhere unless necessary for code execution

from bqskit.qis.permutation import PermutationMatrix
from bqskit.utils.typing import is_integer


class SwapGate(ConstantGate):
class SwapGate(ConstantGate, QubitGate):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swap gate is only qubit by default. You can do SwapGate(3) for a qutrit swap, please revert.

radixes: Sequence[int] = [],
self,
utry: UnitaryLike,
radixes: Sequence[int] = [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert formatting, there's a few spots where this comes up

def get_inverse(self) -> Gate:
"""Return the inverse of this gate."""
from bqskit.ir.gates.constant.xxdg import XXDGGate
return XXDGGate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove XXDG, YYDG, and ZZDG, and just have the inverses of these go to RXX, RYY, and RZZ with the correct inverted angle.

supposed_to_be_iden = (
inv_gate.get_unitary() @ gate.get_unitary()
)
dist = supposed_to_be_iden.get_distance_from(iden, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is get_distance_from the correct way to test here? This will ignore global phase, I have to think we should allow this. If you make the test more strict and just check the norm to identity, for example, do you have any issues?

Also, we should test multiplication both ways, A@B=I and B@A=I.

iden = np.identity(gate.dim)
supposed_to_be_iden = (inv_op.get_unitary() @ op.get_unitary())
dist = supposed_to_be_iden.get_distance_from(iden, 1)
assert dist < 1e-10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also do another test for the qasm definitions you added? I think we wrote that test before we even had qasm fully working, so it just checks that its a string. We should ensure that a circuit containing these gates (one at a time) can be saved to and loaded from qasm, while also maintaining the same unitary definition before and after.

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

Successfully merging this pull request may close these issues.

Add missing get_inverse definitions
2 participants