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

Abstract provides defaults #1528

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

Christian-B
Copy link
Member

@Christian-B Christian-B commented Jan 22, 2025

In master there are two ways that the decorators @default_parameters and @default_initial_values are converted to a mapping of the values in the init. Making these properties

@defaults
This calculated the mappings when the class is imported (even if not used)
The resulting mapping replace the calculate functions so the calculation is only done once!
This style also did not have properties for mypy to find

AbstractPyNNModel
This calculated the mapping every time the property was called
Only worked for classes that extended AbstractPyNNModel

This PR merges the best of both solutions into AbstractProvidesDefaults
AbstractPyNNModel and any class which used to be decorated by @defaults now extends AbstractPyNNModel

The calculation of the mappings is delayed until either property is used.
Then BOTH properties are filled in (as the calculation uses a lot of sharable work)

Tested by:
SpiNNakerManchester/IntegrationTests#307

question.
Which should we do:

  1. Keep @defaults but deprecate warning as now
  2. Keep defaults but only to raise an error how to change

Comment on lines +207 to +208
while hasattr(init, "_method"):
init = getattr(init, "_method")
Copy link
Member

Choose a reason for hiding this comment

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

Does this terminate? How does the attribute get removed?

Copy link
Member

Choose a reason for hiding this comment

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

I assume it does terminate as it is the same code as before... sometimes my own code confuses me!

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see now, it is essentially recusing the init until it finds the real init

Copy link
Member

@rowleya rowleya left a comment

Choose a reason for hiding this comment

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

Looks good to me if it works!

@rowleya
Copy link
Member

rowleya commented Jan 22, 2025

Which should we do:

  1. Keep @defaults but deprecate warning as now
  2. Keep defaults but only to raise an error how to change

I would probably say deprecate as otherwise people might have things broken at the last minute by accidentally updating...

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.

2 participants