-
Notifications
You must be signed in to change notification settings - Fork 23
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
[Bind2] Refactor XMR references #1255
Conversation
2a6d9f0
to
65940f6
Compare
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #1255 +/- ##
=======================================
Coverage 85.67% 85.67%
=======================================
Files 161 161
Lines 17410 17416 +6
=======================================
+ Hits 14916 14922 +6
Misses 2494 2494
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@leonardt my main concern is the performance cost of doing this lookup every time |
magma/circuit.py
Outdated
return only(filter(lambda i: i.name == attr, self.instances)) | ||
except IterableException: | ||
pass | ||
return object.__getattribute__(self, attr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we invert this, do __getattribute__
by default, and check instances list on AttributeError? That would optimize the common case (save a level of indirection in the function call stack)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we invert this, do
__getattribute__
by default, and check instances list on AttributeError? That would optimize the common case (save a level of indirection in the function call stack)
I like this option more. In general though, there is a problem about aliasing/colliding names, e.g.
class Foo(m.Circuit):
Bar(name="bar")
bar = 100
print (Foo.bar) # prints "100"...
We should have a clear spec on what we want to do in this case, that is ideally independent of implementation concerns. Not sure I have a strong opinion on what we should do in this case. Alternatively, we could add a separate instance getter API, like Foo.get_instance(..)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above behavior is expected given normal Python class/object semantics so I'd advocate for preserving that and having a get API specifically for instances when there is this issue of collisions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. See #1262
Alternatively, we could try patching the instance name attributes at close time? Assuming the .open() pattern is used for modifications, this should be safe? |
b72d76b
to
6b060f1
Compare
Updates XMR tests to avoid setting instances as attributes on top-level circuits.
6b060f1
to
9f7d7bc
Compare
@leonardt ended up going with your suggestion of defaulting to |
Avoids requiring setting instances as attributes on circuits to refer to them (similarly with
self.
for Generator2's). Instead getting the attribute will retrieve the instance by name.For example,