Skip to content

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Sep 6, 2025

Some of the code used type(X) == Y to compare types. Those constructs lead to warnings from flake8 because type comparisons should use isinstance.

Some of the code used `type(X) == Y` to compare types. Those constructs
lead to warnings from `flake8`. It is better to use `isinstance`.
@@ -596,7 +596,7 @@ def representative_parameters(self) -> 'FermiHubbardParameters':
def equals_for_rescaling(self, other: 'FermiHubbardParameters') -> bool:
if not isinstance(other, FermiHubbardParameters):
return False
if type(self.layout) != type(other.layout):
if not isinstance(self.layout, type(other.layout)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure about this one? This has different behavior for subclasses of other.layout.

Same thing with several cases below as well.

Copy link
Collaborator

@pavoljuhas pavoljuhas Sep 15, 2025

Choose a reason for hiding this comment

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

Looking at the code below, I think we can delete this if-block and update line 601 to

if isinstance(self.layout, ZigZagLayout) and isinstance(other.layout, ZigZagLayout):

Other updates below look OK to me.

@@ -601,7 +601,7 @@ def cnot_on_layer(
cirq.Moment(cirq.CZ.on(qc, qt) for qc, qt in pairs_list),
cirq.Moment(cirq.H.on_each(pair[1] for pair in pairs_list)),
]
elif type(depolarization_probability) == float:
elif isinstance(depolarization_probability, float):
Copy link
Collaborator

@pavoljuhas pavoljuhas Sep 15, 2025

Choose a reason for hiding this comment

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

(optional) consider changing to numbers.Real if we'd like to handle np.float32 values.

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Please address comments in recirq/fermi_hubbard/parameters.py before merging.

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.

3 participants