Skip to content

WIP: Add Runner callbacks and option to cancel points - #385

Open
basnijholt wants to merge 4 commits into
mainfrom
runner-callbacks
Open

WIP: Add Runner callbacks and option to cancel points#385
basnijholt wants to merge 4 commits into
mainfrom
runner-callbacks

Conversation

@basnijholt

@basnijholtbasnijholt commented Nov 23, 2022

Copy link
Copy Markdown
Member

Description

cc @tlaeven

This allows to add periodic callbacks to the Runner and adds a way to cancel points that are currently being calculated.

importadaptiveadaptive.notebook_extension()
defdepletion_voltage(x):
"""Calculates a depletion voltage curve. Whenever the result is below 0, we know that for all points to the left of that, the result is also zero. """fromtimeimportsleepfromrandomimportrandomsleep(random())
ifx<-0.3:
# Make some negative points really slowsleep(10)
returnmax(0, x)
learner=adaptive.Learner1D(depletion_voltage, bounds=(-1, 1))
runner=adaptive.Runner(learner, npoints_goal=50)
defcancel_depleted_futures(runner):
ifnotrunner.learner.data:
returnzeros= [xforx, yinsorted(learner.data.items()) ify<=0]
ifnotzeros:
returnforfut, xinrunner.pending_points:
ifx<zeros[-1]:
print(f"cancelling {x=} because f(x={zeros[-1]})=0")
runner.cancel_point(fut)
runner.start_periodic_callback(cancel_depleted_futures, 3)
runner.live_info()

Checklist

  • Fixed style issues using pre-commit run --all (first install using pip install pre-commit)
  • pytest passed

Type of change

Check relevant option(s).

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • (Code) style fix or documentation update
  • This change requires a documentation update

@codecov-commenter

codecov-commenter commented Nov 23, 2022

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 12.50000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.73%. Comparing base (28d4c35) to head (a1821f9).
⚠️ Report is 74 commits behind head on main.

Files with missing linesPatch %Lines
adaptive/runner.py12.50%20 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@## main #385 +/- ##
==========================================
- Coverage 77.88% 77.73% -0.15% 
==========================================
Files 37 37 Lines 5508 5525 +17 Branches 989 995 +6 ==========================================
+ Hits 4290 4295 +5 - Misses 1066 1078 +12 
Partials 152 152 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@basnijholtbasnijholt changed the title Add Runner callbacks and option to cancel pointsWIP: Add Runner callbacks and option to cancel pointsNov 23, 2022
@basnijholtbasnijholt changed the title WIP: Add Runner callbacks and option to cancel pointsAdd Runner callbacks and option to cancel pointsNov 23, 2022
@basnijholtbasnijholt changed the title Add Runner callbacks and option to cancel pointsWIP: Add Runner callbacks and option to cancel pointsNov 24, 2022
Sign up for freeto 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

@basnijholt@codecov-commenter