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

Allow custom functions to be used for computing cache keys #284

Merged

Conversation

jakobj
Copy link
Member

@jakobj jakobj commented Jan 13, 2021

Currently the user can choose between computing a key for the disk cache all arguments and keyword arguments to the decorated function or from the result of evaluating an individual on random numpy arrays and the remaining arguments and keyword arguments.

This PR allows users to specify a function that is used to compute the key for the cache. Two functions are provided by the library: one uses the sympy expression of an individual and the remaining arguments, one the results of evaluating the individual on random numpy arrays and the remaining arguments. In addition the user can define any custom function they like provided its first argument is an individual instance and its return value is a float.

@jakobj jakobj added enhancement New feature or request API change The label that should be avoided labels Jan 13, 2021
@jakobj jakobj added this to the 0.3.0 milestone Jan 13, 2021
@coveralls
Copy link
Collaborator

coveralls commented Jan 13, 2021

Coverage Status

Coverage decreased (-0.07%) to 94.823% when pulling 4e23405 on jakobj:enh/custom-hash-function-cache into 3b74803 on Happy-Algorithms-League:master.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.07%) to 94.823% when pulling c2de328 on jakobj:enh/custom-hash-function-cache into 3b74803 on Happy-Algorithms-League:master.

@mschmidt87
Copy link
Member

This is pretty nice. However, in the spirit of trying to not add functionality without a real need: Is there a real need for this? What would be a case where the default option does not work?

@jakobj
Copy link
Member Author

jakobj commented Jan 22, 2021

This is pretty nice. However, in the spirit of trying to not add functionality without a real need: Is there a real need for this? What would be a case where the default option does not work?

one use case arises in connection with hurdles: assume that you have two objectives which both measure performance of a plasticity rule over a number of trials (small and large respectively). you want to use the disk cache for both objectives. for the first, you use the normal numpy evaluation check. but then for the second you might actually assign identical fitness values to those individuals which achieve identical fitness on the first objective, since it's very likely that they will have identical fitness on the second as well. this is a less strict equivalence check than numpy evaluation and hence catches more functionally (in terms of fitness on objective) identical individuals.

@jakobj
Copy link
Member Author

jakobj commented Jan 28, 2021

ping @mschmidt87

Copy link
Member

@mschmidt87 mschmidt87 left a comment

Choose a reason for hiding this comment

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

Did you add a test with a custom function? I can't see it, but perhaps I just missed it?

@jakobj
Copy link
Member Author

jakobj commented Feb 1, 2021

Did you add a test with a custom function? I can't see it, but perhaps I just missed it?

now i have ;) pls have another look

@mschmidt87
Copy link
Member

Thanks. I will approve, but I am thinking that if this implies an API change, shouldn't we change the milestone to 1.0?

@jakobj
Copy link
Member Author

jakobj commented Feb 8, 2021

Thanks. I will approve, but I am thinking that if this implies an API change, shouldn't we change the milestone to 1.0?

well, many PRs have changed to API without us bumping to 1.0, and likely many future ones will (see issues). as far as i understand prior to release 1.0 we're technically still in the beta phase, and semantic versioning doesn't require us to bump major version upon API change:

Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.
(from https://semver.org/)

@jakobj jakobj force-pushed the enh/custom-hash-function-cache branch from cc71442 to 4e23405 Compare February 8, 2021 13:33
@jakobj
Copy link
Member Author

jakobj commented Feb 8, 2021

thx! squashed and waiting for travis

@jakobj jakobj merged commit b471d4f into Happy-Algorithms-League:master Feb 9, 2021
@jakobj jakobj deleted the enh/custom-hash-function-cache branch February 9, 2021 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change The label that should be avoided enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants