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
Lazyflow logging and fix default operator naming #2850
base: main
Are you sure you want to change the base?
Changes from all commits
c47c5e9
7332dfe
91fa202
ec1d8ab
7fc421b
4b6c0d1
26fd121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,9 +173,6 @@ | |
|
||
""" | ||
|
||
loggerName = __name__ + ".Operator" | ||
logger = logging.getLogger(loggerName) | ||
|
||
# definition of inputs slots | ||
inputSlots = [] | ||
|
||
|
@@ -221,6 +218,9 @@ | |
) | ||
graph = parent.graph | ||
|
||
if self.name == Operator.name: | ||
self.name = type(self).__name__ # better default if subclass does not override self.name | ||
|
||
self._cleaningUp = False | ||
self.graph = graph | ||
self._children = collections.OrderedDict() | ||
|
@@ -266,9 +266,8 @@ | |
|
||
# continue initialization, when user overrides __init__ | ||
def _after_init(self): | ||
# provide simple default name for lazy users | ||
if self.name == Operator.name: | ||
self.name = type(self).__name__ | ||
self.name = type(self).__name__ # repeat in case subclass.__init__ does not call super().__init__() | ||
assert self.graph is not None, ( | ||
"Operator {}: self.graph is None, the parent ({})" | ||
" given to the operator must have a valid .graph attribute!".format(self, self._parent) | ||
|
@@ -301,6 +300,10 @@ | |
islot.notifyUnready(self.handleInputBecameUnready) | ||
|
||
self._initialized = True | ||
|
||
self.logger = logging.getLogger(f"lazyflow.op_debug.{type(self).__name__}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor issue, but it is conceivable to have operators with the same type names in different modules, which would lead to confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in a scenario where somehow having identically named operators in different modules seemed like a good idea, both of them writing to the same logger most likely isn't an issue... Would you rather use |
||
self.logger.debug(f"Instantiated {self.name} {id(self)} with parent={self.parent.name if self.parent else ''}") | ||
|
||
self._setupOutputs() | ||
|
||
def _instantiate_slots(self): | ||
|
@@ -393,6 +396,7 @@ | |
if self._parent is not None: | ||
del self._parent._children[self] | ||
|
||
self.logger.debug(f"Cleaning up {self.name} {id(self)}") | ||
# Disconnect ourselves and all children | ||
self._disconnect() | ||
|
||
|
@@ -489,6 +493,7 @@ | |
self._condition.wait() | ||
|
||
self._settingUp = True | ||
self.logger.debug(f"Starting setupOutputs on {self.name} {id(self)}") | ||
|
||
# Keep a copy of the old metadata for comparison. | ||
# We only trigger downstream changes if something really changed. | ||
|
@@ -498,6 +503,7 @@ | |
self.setupOutputs() | ||
self._setup_count += 1 | ||
|
||
self.logger.debug(f"Finished setupOutputs on {self.name} {id(self)}") | ||
self._settingUp = False | ||
self._condition.notifyAll() | ||
|
||
|
@@ -588,6 +594,7 @@ | |
# We are executing the operator. Incremement the execution | ||
# count to protect against simultaneous setupOutputs() | ||
# calls. | ||
self.logger.debug(f"Executing {self.name} {id(self)} slot={slot.name} for roi={str(roi)} with {kwargs=}") | ||
self._incrementOperatorExecutionCount() | ||
return self.execute(slot, subindex, roi, result, **kwargs) | ||
finally: | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -90,7 +90,7 @@ def __init__( | |||||||||||||||||||
|
||||||||||||||||||||
self._initialized = False | ||||||||||||||||||||
|
||||||||||||||||||||
if operatorClass.name == "": | ||||||||||||||||||||
if operatorClass.name == Operator.name: | ||||||||||||||||||||
self._name = "Wrapped " + operatorClass.__name__ | ||||||||||||||||||||
else: | ||||||||||||||||||||
self._name = "Wrapped " + operatorClass.name | ||||||||||||||||||||
Comment on lines
+93
to
96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because again I had to think here longer than I wanted, for the second time ;). It's too many
Suggested change
also - is this an issue anymore with your changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default naming of operators gives their instances the class name as their default The wrapper has The switch in Overall the value of all this logic is pretty limited anyway, we have maybe 5 or 6 custom names in our entire code base. Those few cases where it really seems to help could also be covered with creating an empty subclass with a unique name... |
||||||||||||||||||||
|
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 wouldn't want to enable/start supporting this kind of pattern where operators are created without calling
super().__init__
. I checked and all operators we currently have in code do the right thing. The operator base init is sufficiently complex that I would expect all subclasses to call it. Also this then adds a third place where.name
might be mutated (after the subclass definition andsuper().__init__
) during initialization which is a bit much.