IntelLabs / matsciml

Open MatSci ML Toolkit is a framework for prototyping and scaling out deep learning models for materials discovery supporting widely used materials science datasets, and built on top of PyTorch Lightning, the Deep Graph Library, and PyTorch Geometric.
MIT License
144 stars 20 forks source link

[Feature request]: Support `*args` unpacking when creating classes in the experiment CLI #290

Closed laserkelvin closed 1 month ago

laserkelvin commented 1 month ago

Feature/behavior summary

Some classes unpack a list of arguments (*args) as part of the instantiation process, namely matsciml.lightning.callbacks.LossScalingSchedule. Essentially, what we want to be able to do in the trainer configuration is this:

callbacks:
    - class_path: matsciml.lightning.callbacks.LossScalingScheduler
      init_args:
          - class_path: matsciml.lightning.loss_scaling.SigmoidScalingSchedule
            init_args:
                key: "energy"
                initial_value: 1.0

The idea is to allow init_args be a list of arguments, each of which are specs to create objects from; the API version would look like this:

LossScalingScheduler(
    SigmoidScalingSchedule("energy", 1.0, ...)
)

Right now if the above configuration is used, we get the following error:

TypeError: LossScalingScheduler.__init__() got an unexpected keyword argument 'class_path'

Request attributes

Related issues

No response

Solution description

Potentially modify experiments.utils.utils.instantiate_arg_dict to support unpacking a list of class specifications. Trouble is this might need a bit more complexity since you might need to actually inspect the arguments (i.e. with argspec).

Additional notes

No response