Skip to content

Change BasicGate __eq__ to test for matrix attribute#252

Merged
damiansteiger merged 2 commits into
developfrom
fix/make_basicgate_test_for_matrix
Aug 7, 2018
Merged

Change BasicGate __eq__ to test for matrix attribute#252
damiansteiger merged 2 commits into
developfrom
fix/make_basicgate_test_for_matrix

Conversation

@damiansteiger

Copy link
Copy Markdown
Contributor

In order that user can do:

custom_gate = BasicGate()
custom_gate.matrix = numpy.matrix(...)

And have a correct __eq__

Damian S. Steiger added 2 commits August 7, 2018 13:53

@thomashaener thomashaener left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯 great, thanks!

Comment thread projectq/ops/_basics.py
gate = BasicGate()
gate.matrix = numpy.matrix([[1,0],[0, -1]])
"""
if hasattr(self, 'matrix'):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To make these case distinctions more concise, one could use sum([hasattr(g, 'matrix') for g in [self, other]]) instead, but the current implementation is simpler to understand so either is fine with me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice trick, I will use it once I have more cases to compare.

@damiansteiger damiansteiger merged commit 4674e11 into develop Aug 7, 2018
@damiansteiger damiansteiger deleted the fix/make_basicgate_test_for_matrix branch August 7, 2018 12:30
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.

2 participants