Skip to content

Add regularization features#79

Merged
lilyminium merged 10 commits intoopenforcefield:mainfrom
fjclark:feature-regularization
Feb 13, 2026
Merged

Add regularization features#79
lilyminium merged 10 commits intoopenforcefield:mainfrom
fjclark:feature-regularization

Conversation

@fjclark
Copy link
Contributor

@fjclark fjclark commented Dec 11, 2025

Description

This adds optional regularization information to AttributeConfig and Trainable. Specifically, AttributeConfig gets:

    regularize: dict[str, float] = pydantic.Field(
        {},
        description="The regularization strength to apply to each parameter, e.g. "
        "'k': 0.01, 'epsilon': 0.001. Parameters not listed are not regularized.",
    )

and Trainable gets regularized_idxs (where the idxs are within the values returned by to_values) and regularization_weights properties, which allow you to apply regularization with e.g.

initial_parameters = trainable.to_values() 
# Copy and train to get trained_parameters

regularized_idxs = trainable.regularized_idxs
regularization_weights = trainable.regularization_weights

l2_reg_loss = (
        ((trained_parameters[regularized_idxs] - initial_parameters[regularized_idxs]) ** 2)
        * regularization_weights
    ).sum()

Status

  • Ready to go

jthorton
jthorton previously approved these changes Jan 27, 2026
Copy link
Collaborator

@jthorton jthorton left a comment

Choose a reason for hiding this comment

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

LGTM the tests look good, it would be great if coverage was working to know if anything was missed though!

@fjclark
Copy link
Contributor Author

fjclark commented Jan 28, 2026

Thanks Josh! Yes, don't think I have permissions to fix this though (thanks for raising the issue). I've checked coverage locally, and everything inside Trainable is covered. Uncovered lines are either in pydantic 1 blocks or weren't covered previously.

@lilyminium
Copy link
Contributor

Just closing and re-opening to kick CI, since it looks like that never ran.

@lilyminium lilyminium closed this Feb 11, 2026
@lilyminium lilyminium reopened this Feb 11, 2026
@fjclark
Copy link
Contributor Author

fjclark commented Feb 11, 2026

Thanks Lily. Merging in #78 to get the CI running.

lilyminium
lilyminium previously approved these changes Feb 12, 2026
Copy link
Contributor

@lilyminium lilyminium left a comment

Choose a reason for hiding this comment

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

LGTM, at some point it would be good generate some tutorials/docs on how to use this, but not in scope atm. Just one question about Interchange!

@lilyminium
Copy link
Contributor

Thanks Finlay!

@lilyminium lilyminium merged commit 15101d0 into openforcefield:main Feb 13, 2026
1 check passed
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.

3 participants