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

Change BasicGate __eq__ to test for matrix attribute #252

Merged
merged 2 commits into from Aug 7, 2018

Conversation

damiansteiger
Copy link
Contributor

In order that user can do:

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

And have a correct __eq__

Copy link
Contributor

@thomashaener thomashaener left a comment

Choose a reason for hiding this comment

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

💯 great, thanks!

gate = BasicGate()
gate.matrix = numpy.matrix([[1,0],[0, -1]])
"""
if hasattr(self, 'matrix'):
Copy link
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
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.

None yet

2 participants