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

Limiting fitness evaluations #238

Conversation

HenrikMettler
Copy link
Contributor

This PR draft is a suggestion for a solution to #224
It works by counting the calls of the objective function using a decorator (as suggested eg: https://stackoverflow.com/questions/21716940/is-there-a-way-to-track-the-number-of-times-a-function-is-called). I am not sure if this is a reasonable approach, mainly two things bother me:

  • the subtraction if fitness is not reevalutated (necessary since we don't want to count those)
  • if a caching decorator is used for the inner objective, the counts of the objective function calls might not correspond to full function evaluations anymore

@jakobj
Copy link
Member

jakobj commented Aug 27, 2020

thanks for working on this! didn't have time yet to check it in detail, but as i already mentioned we could think about introducing a general "objective" decorator, that would allow us to do such things like counting the number of objective evaluations in a simpler fashion. this would also remove the need to manually add the if individual.fitness is None statement to every objective. it would look something like:

@cgp.objective
def objective(individual):
    ....
    return individual

what do you think @mschmidt87?

@jakobj jakobj added this to the 0.3.0 milestone Aug 27, 2020
@mschmidt87
Copy link
Member

Totally agree, a general objective wrapper sounds awesome. So, what you're saying is that within this PR, we would use @HenrikMettler 's code and

  • add the if individual.fitness is None check to it
  • move the decorator from the example to utils.py
    , right?

@mschmidt87
Copy link
Member

Little activity on this PR, @HenrikMettler are you working on this PR?

@HenrikMettler
Copy link
Contributor Author

I moved the wrapper into utils.py. Since I am not sure this is the way you were thinking @jakobj I didn't adapt all the examples. Also many tests in test_hl_api.py and test_utils.py fail under the current, because their objectives have no attribute calls

@HenrikMettler HenrikMettler marked this pull request as ready for review September 22, 2020 14:50
@HenrikMettler HenrikMettler marked this pull request as draft September 22, 2020 14:52
Copy link
Member

@jakobj jakobj left a comment

Choose a reason for hiding this comment

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

thanks for the changes 👌 i've left some inline comments that should be addressed.

but before getting into that, we need to make sure this works in parallel contexts. would this implementation work there? how are the evaluations counted across different processes?

cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/utils.py Outdated Show resolved Hide resolved
cgp/utils.py Outdated Show resolved Hide resolved
cgp/utils.py Outdated Show resolved Hide resolved
cgp/utils.py Outdated Show resolved Hide resolved
examples/example_minimal.py Outdated Show resolved Hide resolved
@HenrikMettler
Copy link
Contributor Author

Should I introduce the objective decorator for all examples and tests within this PR, or in a separate PR?

@jakobj
Copy link
Member

jakobj commented Oct 27, 2020

Should I introduce the objective decorator for all examples and tests within this PR, or in a separate PR?

let's first figure out a suitable implementation that works with more than one process. we might end up with a different solution than the decorator after all.

@HenrikMettler
Copy link
Contributor Author

As suggested by @jakobj the counter for objective function calls is now moved to the evolutionary algorithm. Removing it from the objective decorator enables using it with multiple processes running in parallel. I left everything for the objective decorator within this PR, even though it doesn't really belong to this topic anymore

Copy link
Member

@jakobj jakobj left a comment

Choose a reason for hiding this comment

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

thanks for (re)implementing this so quickly! 🚀

i've added a few inline comments. also please add a unit test.

cgp/ea/mu_plus_lambda.py Outdated Show resolved Hide resolved
cgp/ea/mu_plus_lambda.py Outdated Show resolved Hide resolved
cgp/ea/mu_plus_lambda.py Outdated Show resolved Hide resolved
cgp/ea/mu_plus_lambda.py Outdated Show resolved Hide resolved
cgp/hl_api.py Outdated Show resolved Hide resolved
cgp/utils.py Outdated Show resolved Hide resolved
examples/example_minimal.py Outdated Show resolved Hide resolved
Copy link
Member

@jakobj jakobj left a comment

Choose a reason for hiding this comment

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

thanks for the update! 👌

some more inline comments, then it's ready to merge!

test/test_ea_mu_plus_lambda.py Outdated Show resolved Hide resolved
test/test_ea_mu_plus_lambda.py Outdated Show resolved Hide resolved
test/test_hl_api.py Outdated Show resolved Hide resolved
test/test_hl_api.py Outdated Show resolved Hide resolved
@jakobj jakobj marked this pull request as ready for review November 4, 2020 12:31
Copy link
Member

@jakobj jakobj left a comment

Choose a reason for hiding this comment

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

excellent, thanks a lot! 👍

as always, please reorganize the history before merging.

test/test_ea_mu_plus_lambda.py Outdated Show resolved Hide resolved
@HenrikMettler HenrikMettler merged commit 3cef980 into Happy-Algorithms-League:master Nov 5, 2020
@HenrikMettler HenrikMettler deleted the dev/n_fitness_evaluations branch November 5, 2020 08:11
@jakobj jakobj modified the milestones: 0.3.0, 0.2.0 Nov 5, 2020
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.

Controlling the Wallclock time by limiting the Number of individual evaluations
3 participants