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

Refactor Config and Variables #142

Merged
merged 10 commits into from
Aug 5, 2021
Merged

Conversation

mkendler
Copy link
Collaborator

@mkendler mkendler commented Jul 8, 2021

@mkendler mkendler added enhancement New feature or request project labels Jul 8, 2021
@mkendler mkendler self-assigned this Jul 8, 2021
@mkendler mkendler marked this pull request as ready for review July 16, 2021 00:31
@mkendler mkendler requested review from krystophny and Rykath July 16, 2021 06:05
@mkendler
Copy link
Collaborator Author

@Rykath (maybe also @krystophny) please also check the zeromq interface and slurm runner.

@Rykath
Copy link
Collaborator

Rykath commented Jul 16, 2021

The zeromq error appeared already in the Fix tests commit but not in v0.4.
GitHub says, the test passed, but displays the two warnings (the error miraculously does not appear for python 3.7) as Annotations in the test overview and with dedicated messages when reviewing the code which triggered the errors.

Before refactoring the Variable configuration, spec['dtype'] was a string. ZeroMQ requires a string to be able to serialize the dtype for sending it to the Worker. With `__name__` we get a correct string which can be read by numpy correctly again.

Problems maybe requiring further action:
* The real error "TypeError: Object of type type is not JSON serializable" was not shown in the test
* The error within the thread did not cause the pytest to fail
@Rykath
Copy link
Collaborator

Rykath commented Jul 19, 2021

@Rykath (maybe also @krystophny) please also check the zeromq interface and slurm runner.

I just checked the mockup example on acluster, works well!

@@ -13,7 +13,7 @@
- .hdf5 output of single runs with custom interface
"""

from profit.config import Config
from profit.config import BaseConfig
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might have been easier to say

from profit.config import BaseConfig as Config

but this is cleaner anyways

break


@RunnerConfig.register("local")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would personally prefer it if the actual configurations are next to the relevant implementation. This would ensure that all relevant information of that component is just in one file.
But that's probably a discussion for another time...

vars.append(Variable.create_from_str(k, (config['ntrain'], 1), v))
else:
vars.append(Variable.create(**v))
variables.add(vars)
Copy link
Collaborator

Choose a reason for hiding this comment

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

That is a bit strange: While creating the BaseConfig the Variable objects were already built, but then replaced with a dictionary. Now the dictionary is converted into objects again.
I guess it's fine for now (as probably some other lines depend on the dictionary structure), but in the future we should consider completing the transformation into an object oriented config (see issue #143)

return cls.create(**v_dict)

@classmethod
def create(cls, name, kind, size, entries=(0, 1), value=np.array([[]]), dtype=np.float64):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using np.array([[]]) as a default value is dangerous, as the same value would be shared across all Variable objects. (similar to how a list as a default value works) In this case it might just work anyways.

Also, why do you use create instead of just __init__? I'm just curious.

Copy link
Collaborator

@krystophny krystophny left a comment

Choose a reason for hiding this comment

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

Great work, @mkendler !

@krystophny krystophny merged commit 66a3fbb into redmod-team:master Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor class and config structure warn user about unknown config options
3 participants