Skip to content

Conversation

@sid-mungale
Copy link
Collaborator

The aim here was to remove dependence on globals() so we can stop caring about scope.
i have done this by adding a classdict() function that queries a class for all it's subclasses.
CLASS_MAPPING has also been removed, so classes must be requested using their python names

New

  • assemblies/classdict(): Queries a class for its subclasses recursively

Updated

  • assemblies.construct()
  • geometry_maker.GeometryMaker.make_geometry()

Removed

  • geometry_maker.make_everything()

@sid-mungale sid-mungale linked an issue Nov 14, 2024 that may be closed by this pull request
Copy link
Collaborator

@lukethehuman lukethehuman left a comment

Choose a reason for hiding this comment

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

A really nice refactor, a lot was simplified and made much easier to read here. Having a single base class for components is a great move. I think we may just need a test adding to cover the functionality previously covered by test_make_everything. We may also want to consider improving the efficiency of the recursive for loop, but that could be a separate issue.

Comment on lines -107 to -127
def test_make_everything():
# this should make a pin assembly
geom_list = make_everything(PIN)
geom = geom_list[0]
assert len(geom_list) == 1
assert isinstance(geom, PinAssembly)

# make sure it contains all the components we want
comp_classes = [type(comp) for comp in geom.components]
for pin_comp in PIN_COMPS:
assert pin_comp in comp_classes

fake_json_obj = [PIN]
json_list = make_everything(fake_json_obj)
assert len(json_list) == 1
assert isinstance(json_list[0], PinAssembly)

with pytest.raises(CubismError):
make_everything(1)


Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we lose any coverage by removing this? If so, could we add a test for the new approach?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should have only been testing for whether that function worked as intended. Geometry creation is now being tested for (implicitly?) when using GeometryMakers make_geometry so I think we should be fine?

Comment on lines +1194 to +1207
# it take so long to run :(
def classdict(cls):
'''Find all subclasses recursively.
Returns
-------
dict
{"Class": Class}
'''
return_dict = {}
for subcls in cls.__subclasses__():
return_dict[subcls.__name__] = subcls
return_dict.update(classdict(subcls))
return return_dict
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is taking a long time to run, maybe let's put in an issue to consider ways to make it more efficient. Python for loops are notoriously slow, but that said it's unlikely to be the bottleneck in the high fidelity simulation workflows hypnos is supporting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not actually sure it's that slow, it just feels inefficient. Will add an issue just to keep note though.

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.

Overhaul json parsing approach

3 participants