Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
adaptive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Quantum Tinkerer
adaptive
Commits
99c80fe7
Commit
99c80fe7
authored
6 years ago
by
Joseph Weston
Browse files
Options
Downloads
Plain Diff
Merge branch '107-make-baserunner-an-abstract-base-class' into 'master'
Make BaseRunner an abstract base class Closes
#107
See merge request
!111
parents
16bf8ee9
98b22699
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!111
Resolve "Make BaseRunner an abstract base class"
Pipeline
#13030
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
adaptive/runner.py
+23
-6
23 additions, 6 deletions
adaptive/runner.py
with
23 additions
and
6 deletions
adaptive/runner.py
+
23
−
6
View file @
99c80fe7
...
...
@@ -8,6 +8,7 @@ import os
import
time
import
traceback
import
warnings
import
abc
from
.notebook_integration
import
live_plot
,
live_info
,
in_ipynb
from
.utils
import
timed
...
...
@@ -53,7 +54,7 @@ else:
_default_executor_kwargs
=
{}
class
BaseRunner
:
class
BaseRunner
(
metaclass
=
abc
.
ABCMeta
)
:
"""
Base class for runners that use `concurrent.futures.Executors`.
Parameters
...
...
@@ -241,6 +242,20 @@ class BaseRunner:
def
failed
(
self
):
"""
Set of points that failed ``runner.retries`` times.
"""
return
set
(
self
.
tracebacks
)
-
set
(
self
.
to_retry
)
@abc.abstractmethod
def
elapsed_time
(
self
):
"""
Return the total time elapsed since the runner
was started.
Is called in `overhead`.
"""
pass
@abc.abstractmethod
def
_submit
(
self
,
x
):
"""
Is called in `_get_futures`.
"""
pass
class
BlockingRunner
(
BaseRunner
):
...
...
@@ -444,11 +459,6 @@ class AsyncRunner(BaseRunner):
raise
RuntimeError
(
'
Cannot use an executor when learning an
'
'
async function.
'
)
self
.
executor
.
shutdown
()
# Make sure we don't shoot ourselves later
self
.
_submit
=
lambda
x
:
self
.
ioloop
.
create_task
(
self
.
function
(
x
))
else
:
self
.
_submit
=
functools
.
partial
(
self
.
ioloop
.
run_in_executor
,
self
.
executor
,
self
.
function
)
self
.
task
=
self
.
ioloop
.
create_task
(
self
.
_run
())
self
.
saving_task
=
None
...
...
@@ -458,6 +468,13 @@ class AsyncRunner(BaseRunner):
"
in a Jupyter notebook, remember to run
"
"'
adaptive.notebook_extension()
'"
)
def
_submit
(
self
,
x
):
ioloop
=
self
.
ioloop
if
inspect
.
iscoroutinefunction
(
self
.
learner
.
function
):
return
ioloop
.
create_task
(
self
.
function
(
x
))
else
:
return
ioloop
.
run_in_executor
(
self
.
executor
,
self
.
function
,
x
)
def
status
(
self
):
"""
Return the runner status as a string.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment