track.persistence package

Submodules

track.persistence.cockroach module

track.persistence.cometml module

track.persistence.local module

exception track.persistence.local.ConcurrentWrite(msg)[source]

Bases: Exception

class track.persistence.local.FileProtocol(uri, strict=True, eager=True)[source]

Bases: track.persistence.protocol.Protocol

Local File storage to manage experiments

Parameters:
uri: str

resource to use to store the experiment file://my_file.json

strict: bool

forces the storage to be correct. if we use the file protocol as an in-memory storage we might get some inconsistencies we can use this flag to ignore them

eager: bool

eagerly update the underlying files. This is necessary if multiple processes are reading from the file

Methods

commit(self[, file_name_override]) Forces to persist the change
add_group_trial  
add_project_trial  
add_trial_tags  
fetch_and_update_group  
fetch_and_update_trial  
fetch_groups  
fetch_projects  
fetch_trials  
get_project  
get_trial  
get_trial_group  
log_trial_arguments  
log_trial_chrono_finish  
log_trial_chrono_start  
log_trial_finish  
log_trial_metadata  
log_trial_metrics  
log_trial_start  
new_project  
new_trial  
new_trial_group  
set_group_metadata  
set_trial_status  
add_group_trial(self, *args, **kwargs)[source]
add_project_trial(self, *args, **kwargs)[source]
add_trial_tags(self, *args, **kwargs)[source]
commit(self, file_name_override=None, **kwargs)[source]

Forces to persist the change

fetch_and_update_group(self, *args, **kwargs)[source]
fetch_and_update_trial(self, *args, **kwargs)[source]
fetch_groups(self, *args, **kwargs)[source]
fetch_projects(self, *args, **kwargs)[source]
fetch_trials(self, *args, **kwargs)[source]
get_project(self, *args, **kwargs)[source]
get_trial(self, *args, **kwargs)[source]
get_trial_group(self, *args, **kwargs)[source]
log_trial_arguments(self, *args, **kwargs)[source]
log_trial_chrono_finish(self, *args, **kwargs)[source]
log_trial_chrono_start(self, *args, **kwargs)[source]
log_trial_finish(self, *args, **kwargs)[source]
log_trial_metadata(self, *args, **kwargs)[source]
log_trial_metrics(self, *args, **kwargs)[source]
log_trial_start(self, *args, **kwargs)[source]
new_project(self, *args, **kwargs)[source]
new_trial(self, *args, **kwargs)[source]
new_trial_group(self, *args, **kwargs)[source]
set_group_metadata(self, *args, **kwargs)[source]
set_trial_status(self, *args, **kwargs)[source]
class track.persistence.local.LockFileRemover(filename)[source]

Bases: track.utils.signal.SignalHandler

Methods

atexit  
remove  
sigint  
sigterm  
atexit(self)[source]
remove(self)[source]
sigint(self, signum, frame)[source]
sigterm(self, signum, frame)[source]
class track.persistence.local.MultiLock(obj)[source]

Bases: object

track.persistence.local.execute_query(obj, query)[source]

Check if the object obj matches the query.

The query is a dictionary specifying constraint on each of the object attributes

track.persistence.local.lock_atomic_write(fun)
track.persistence.local.lock_guard(readonly, atomic=False)[source]

Protect a function call with a lock. reload the database before the action and save it afterwards

track.persistence.local.lock_read(fun)
track.persistence.local.lock_write(fun)
track.persistence.local.make_lock(name, eager)[source]
track.persistence.local.query_gt(obj, attrs, val)[source]
track.persistence.local.query_in(obj, attrs, choices)[source]
track.persistence.local.query_lte(obj, attrs, val)[source]
track.persistence.local.query_ne(obj, attrs, val)[source]

track.persistence.multiplexer module

class track.persistence.multiplexer.ProtocolMultiplexer(*backends)[source]

Bases: object

Methods

get_project(self, \*args, \*\*kwargs)
add_group_trial  
add_project_trial  
add_trial_tags  
commit  
fetch_and_update_group  
fetch_and_update_trial  
fetch_groups  
fetch_projects  
fetch_trials  
get_trial  
get_trial_group  
log_trial_arguments  
log_trial_chrono_finish  
log_trial_chrono_start  
log_trial_finish  
log_trial_metadata  
log_trial_metrics  
log_trial_start  
new_project  
new_trial  
new_trial_group  
set_trial_status  
add_group_trial(self, *args, **kwargs)[source]
add_project_trial(self, *args, **kwargs)[source]
add_trial_tags(self, *args, **kwargs)[source]
commit(self, *args, **kwargs)[source]
fetch_and_update_group(self, *args, **kwargs)[source]
fetch_and_update_trial(self, *args, **kwargs)[source]
fetch_groups(self, *args, **kwargs)[source]
fetch_projects(self, *args, **kwargs)[source]
fetch_trials(self, *args, **kwargs)[source]
get_project(self, *args, **kwargs)[source]
get_trial(self, *args, **kwargs)[source]
get_trial_group(self, *args, **kwargs)[source]
log_trial_arguments(self, *args, **kwargs)[source]
log_trial_chrono_finish(self, *args, **kwargs)[source]
log_trial_chrono_start(self, *args, **kwargs)[source]
log_trial_finish(self, *args, **kwargs)[source]
log_trial_metadata(self, *args, **kwargs)[source]
log_trial_metrics(self, *args, **kwargs)[source]
log_trial_start(self, *args, **kwargs)[source]
new_project(self, *args, **kwargs)[source]
new_trial(self, *args, **kwargs)[source]
new_trial_group(self, *args, **kwargs)[source]
set_trial_status(self, *args, **kwargs)[source]

track.persistence.protocol module

class track.persistence.protocol.Protocol[source]

Bases: object

Methods

add_group_trial(self, group, trial) Add a trial to a group
add_project_trial(self, project, trial) Add a trial to a project
add_trial_tags(self, trial, \*\*kwargs) Add tags to a trial
commit(self, \*\*kwargs) Forces to persist the change
fetch_and_update_group(self, query, attr, …) Fetch and update a single group
fetch_and_update_trial(self, query, attr, …) Fetch and update a single trial
fetch_groups(self, query) Fetch groups according to a given query
fetch_projects(self, query) Fetch projects according to a given query
fetch_trials(self, query) Fetch trials according to a given query
get_project(self, project) Fetch a project according to the given definition
get_trial(self, trial) Fetch trials according to a given definition
get_trial_group(self, group) Fetch a group according to a given definition
log_trial_arguments(self, trial, \*\*kwargs) Save the arguments a trail
log_trial_chrono_finish(self, trial, name, …) Send the end signal for an event
log_trial_chrono_start(self, trial, name, …) Send the start signal for an event
log_trial_finish(self, trial, exc_type, …) Send the trial end signal
log_trial_metadata(self, trial, aggregator, …) Save metadata for a given trials
log_trial_metrics(self, trial, step, …) Save metrics for a given trials
log_trial_start(self, trial) Send the trial start signal
new_project(self, project) Insert a new project
new_trial(self, trial[, auto_increment]) Insert a new trial
new_trial_group(self, group) Create a new group
set_trial_status(self, trial, status[, error]) Change trial status
add_group_trial(self, group: track.structure.TrialGroup, trial: track.structure.Trial)[source]

Add a trial to a group

add_project_trial(self, project: track.structure.Project, trial: track.structure.Trial)[source]

Add a trial to a project

add_trial_tags(self, trial, **kwargs)[source]

Add tags to a trial

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

commit(self, **kwargs)[source]

Forces to persist the change

fetch_and_update_group(self, query, attr, *args, **kwargs)[source]

Fetch and update a single group

Parameters:
query: Dict

dictionary to fetch groups

attr: str

name of the update function to call on each selected group

*args:

additional positional arguments for the attr function

**kwargs:

addtional keyword arguments for the attr function

Returns:
returns the modified group
fetch_and_update_trial(self, query, attr, *args, **kwargs)[source]

Fetch and update a single trial

Parameters:
query: Dict

dictionary to fetch trials

attr: str

name of the update function to call on each selected trials

*args:

additional positional arguments for the attr function

**kwargs:

addtional keyword arguments for the attr function

Returns:
returns the modified trial
fetch_groups(self, query)[source]

Fetch groups according to a given query

fetch_projects(self, query)[source]

Fetch projects according to a given query

fetch_trials(self, query) → List[track.structure.Trial][source]

Fetch trials according to a given query

get_project(self, project: track.structure.Project) → Union[track.structure.Project, NoneType][source]

Fetch a project according to the given definition

Parameters:
project: Project

project definition used for the lookup

Returns:
returns a project object or None
get_trial(self, trial: track.structure.Trial) → List[track.structure.Trial][source]

Fetch trials according to a given definition

Parameters:
trial: Trial

trial definition used for the lookup

get_trial_group(self, group: track.structure.TrialGroup) → Union[track.structure.TrialGroup, NoneType][source]

Fetch a group according to a given definition

Parameters:
group: TrialGroup

group definition used for the lookup

Returns:
returns a grouo
log_trial_arguments(self, trial: track.structure.Trial, **kwargs)[source]

Save the arguments a trail

Parameters:
trial: Trial

trial for which the arguments are for

kwargs:

key value pair of arguments

log_trial_chrono_finish(self, trial, name, exc_type, exc_val, exc_tb)[source]

Send the end signal for an event

Parameters:
trial: Trial

trial sending the event

name: str

name of the event

exc_type:

Exception object

exec_val

Exception value

exc_tb:

Traceback

log_trial_chrono_start(self, trial, name: str, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = <function StatAggregator.lazy.<locals>.<lambda> at 0x7fc3f639bf28>, start_callback=None, end_callback=None)[source]

Send the start signal for an event

Parameters:
trial: Trial

trial sending the event

name: str

name of the event

aggregator: Aggregator

container used to accumulate elapsed time

start_callback: Callable

function called at start time

end_callback: Callable

function called at the end

log_trial_finish(self, trial, exc_type, exc_val, exc_tb)[source]

Send the trial end signal

Parameters:
trial: Trial

reference to the trial that finished

log_trial_metadata(self, trial: track.structure.Trial, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = <function ValueAggregator.lazy.<locals>.<lambda> at 0x7fc3f639bd08>, **kwargs)[source]

Save metadata for a given trials

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

log_trial_metrics(self, trial: track.structure.Trial, step: <built-in function any> = None, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = None, **kwargs)[source]

Save metrics for a given trials

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

log_trial_start(self, trial)[source]

Send the trial start signal

Parameters:
trial: Trial

reference to the trial being started

new_project(self, project: track.structure.Project)[source]

Insert a new project

Parameters:
project: Project

project definition used for the insert

new_trial(self, trial: track.structure.Trial, auto_increment=False)[source]

Insert a new trial

Parameters:
trial: Trial

trial definition used for the insert

auto_increment: bool

If trial exist increment revision number

Returns:
Returns None if Trial already exists and auto_increment is False
new_trial_group(self, group: track.structure.TrialGroup)[source]

Create a new group

Parameters:
group: TrialGroup

group definition used for the insert

set_trial_status(self, trial: track.structure.Trial, status, error=None)[source]

Change trial status

Parameters:
trial: Trial

trial reference

status:

new status to update the trial too

error:

in case the user is changing to a state representing an error it can also provide an error identification string

track.persistence.socketed module

Implement a Remote Logger.
Client forwards all the user’s request down to the server that executes them one by one.
exception track.persistence.socketed.RPCCallFailure(message, trace=None)[source]

Bases: Exception

class track.persistence.socketed.ServerSignalHandler(server)[source]

Bases: track.utils.signal.SignalHandler

Methods

atexit  
sigint  
sigterm  
sigint(self, signum, frame)[source]
sigterm(self, signum, frame)[source]
class track.persistence.socketed.SocketClient(uri)[source]

Bases: track.persistence.protocol.Protocol

Forwards all the local track requests to the track server that execute the requests and send back the results

Clients can provide a username and password for authentication

Methods

add_group_trial(self, group, trial) Add a trial to a group
add_project_trial(self, project, trial) Add a trial to a project
add_trial_tags(self, trial, \*\*kwargs) Add tags to a trial
authenticate(self, uri) returns the username and password used for authentication purposes you can override this function to implement a custom authentication method
commit(self, \*\*kwargs) Forces to persist the change
fetch_and_update_group(self, query, attr, …) Fetch and update a single group
fetch_and_update_trial(self, query, attr, …) Fetch and update a single trial
fetch_groups(self, query) Fetch groups according to a given query
fetch_projects(self, query) Fetch projects according to a given query
fetch_trials(self, query) Fetch trials according to a given query
get_project(self, project) Fetch a project according to the given definition
get_trial(self, trial) Fetch trials according to a given definition
get_trial_group(self, group) Fetch a group according to a given definition
log_trial_arguments(self, trial, \*\*kwargs) Save the arguments a trail
log_trial_chrono_finish(self, trial, name, …) Send the end signal for an event
log_trial_chrono_start(self, trial, name, …) Send the start signal for an event
log_trial_finish(self, trial, exc_type, …) Send the trial end signal
log_trial_metadata(self, trial, aggregator, …) Save metadata for a given trials
log_trial_metrics(self, trial, step, …) Save metrics for a given trials
log_trial_start(self, trial) Send the trial start signal
new_project(self, project) Insert a new project
new_trial(self, trial) Insert a new trial
new_trial_group(self, group) Create a new group
set_trial_status(self, trial, status[, error]) Change trial status
add_group_trial(self, group: track.structure.TrialGroup, trial: track.structure.Trial)[source]

Add a trial to a group

add_project_trial(self, project: track.structure.Project, trial: track.structure.Trial)[source]

Add a trial to a project

add_trial_tags(self, trial, **kwargs)[source]

Add tags to a trial

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

authenticate(self, uri)[source]

returns the username and password used for authentication purposes you can override this function to implement a custom authentication method

commit(self, **kwargs)[source]

Forces to persist the change

get_project(self, project: track.structure.Project)[source]

Fetch a project according to the given definition

Parameters:
project: Project

project definition used for the lookup

Returns:
returns a project object or None
get_trial(self, trial: track.structure.Trial)[source]

Fetch trials according to a given definition

Parameters:
trial: Trial

trial definition used for the lookup

get_trial_group(self, group: track.structure.TrialGroup)[source]

Fetch a group according to a given definition

Parameters:
group: TrialGroup

group definition used for the lookup

Returns:
returns a grouo
log_trial_arguments(self, trial: track.structure.Trial, **kwargs)[source]

Save the arguments a trail

Parameters:
trial: Trial

trial for which the arguments are for

kwargs:

key value pair of arguments

log_trial_chrono_finish(self, trial, name, exc_type, exc_val, exc_tb)[source]

Send the end signal for an event

Parameters:
trial: Trial

trial sending the event

name: str

name of the event

exc_type:

Exception object

exec_val

Exception value

exc_tb:

Traceback

log_trial_chrono_start(self, trial, name: str, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = <function StatAggregator.lazy.<locals>.<lambda> at 0x7fc3f4102378>, start_callback=None, end_callback=None)[source]

Send the start signal for an event

Parameters:
trial: Trial

trial sending the event

name: str

name of the event

aggregator: Aggregator

container used to accumulate elapsed time

start_callback: Callable

function called at start time

end_callback: Callable

function called at the end

log_trial_finish(self, trial, exc_type, exc_val, exc_tb)[source]

Send the trial end signal

Parameters:
trial: Trial

reference to the trial that finished

log_trial_metadata(self, trial: track.structure.Trial, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = None, **kwargs)[source]

Save metadata for a given trials

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

log_trial_metrics(self, trial: track.structure.Trial, step: <built-in function any> = None, aggregator: Callable[[], track.aggregators.aggregator.Aggregator] = None, **kwargs)[source]

Save metrics for a given trials

Parameters:
trial: Trial

trial reference

kwargs:

key value pair of the data to save

log_trial_start(self, trial)[source]

Send the trial start signal

Parameters:
trial: Trial

reference to the trial being started

new_project(self, project: track.structure.Project)[source]

Insert a new project

Parameters:
project: Project

project definition used for the insert

new_trial(self, trial: track.structure.Trial)[source]

Insert a new trial

Parameters:
trial: Trial

trial definition used for the insert

auto_increment: bool

If trial exist increment revision number

Returns:
Returns None if Trial already exists and auto_increment is False
new_trial_group(self, group: track.structure.TrialGroup)[source]

Create a new group

Parameters:
group: TrialGroup

group definition used for the insert

set_trial_status(self, trial: track.structure.Trial, status, error=None)[source]

Change trial status

Parameters:
trial: Trial

trial reference

status:

new status to update the trial too

error:

in case the user is changing to a state representing an error it can also provide an error identification string

class track.persistence.socketed.SocketServer(uri)[source]

Bases: track.persistence.protocol.Protocol

Start a track server inside a asyncio loop

Parameters:
uri: str

socket://{hostname}:{port}?security_layer={}&backend={protocol} with

Users inherit this class to implement their own custom authentication

Methods

add_group_trial(self, group, trial) Add a trial to a group
add_project_trial(self, project, trial) Add a trial to a project
add_trial_tags(self, trial, \*\*kwargs) Add tags to a trial
authenticate(self, reader, username, password) User defined authentication function
commit(self, \*\*kwargs) Forces to persist the change
fetch_and_update_group(self, query, attr, …) Fetch and update a single group
fetch_and_update_trial(self, query, attr, …) Fetch and update a single trial
fetch_groups(self, query) Fetch groups according to a given query
fetch_projects(self, query) Fetch projects according to a given query
fetch_trials(self, query) Fetch trials according to a given query
get_project(self, project) Fetch a project according to the given definition
get_trial(self, trial) Fetch trials according to a given definition
get_trial_group(self, group) Fetch a group according to a given definition
log_trial_arguments(self, trial, \*\*kwargs) Save the arguments a trail
log_trial_chrono_finish(self, trial, name, …) Send the end signal for an event
log_trial_chrono_start(self, trial, name, …) Send the start signal for an event
log_trial_finish(self, trial, exc_type, …) Send the trial end signal
log_trial_metadata(self, trial, aggregator, …) Save metadata for a given trials
log_trial_metrics(self, trial, step, …) Save metrics for a given trials
log_trial_start(self, trial) Send the trial start signal
new_project(self, project) Insert a new project
new_trial(self, trial[, auto_increment]) Insert a new trial
new_trial_group(self, group) Create a new group
process_args(self, args[, cache]) replace ids by their object reference so the backend modifies the objects and not a copy
run_server(self)
set_trial_status(self, trial, status[, error]) Change trial status
close  
close_connection  
exec  
get_username  
handle_client  
is_authenticated  
wait_closed  
authenticate(self, reader, username, password)[source]

User defined authentication function

Parameters:
reader: StreamReader

client socket / reader, can be used to link client socket -> username

username: str

client username

password: str

client password

close(self)[source]
static close_connection(writer)[source]
commit(self, **kwargs)[source]

Forces to persist the change

exec(self, reader, writer, proc_name, proc, args, cache=None)[source]
get_username(self, reader)[source]
handle_client(self, reader, writer)[source]
is_authenticated(self, reader)[source]
process_args(self, args, cache=None)[source]

replace ids by their object reference so the backend modifies the objects and not a copy

run_server(self)[source]
static wait_closed(writer)[source]
track.persistence.socketed.read(reader, timeout=None)[source]
track.persistence.socketed.recv(socket, timeout=None)[source]
track.persistence.socketed.send(socket, msg)[source]
track.persistence.socketed.start_track_server(protocol, hostname, port, security_layer=None)[source]

Start a track server inside a asyncio loop

Parameters:
protocol: str

URI that defines which backend to forward the request to

hostname: str

server host name

port: int

server port to listen to

security_layer: str

backend used for encryption (only AES is supported)

track.persistence.socketed.to_bytes(message) → bytes[source]
track.persistence.socketed.to_obj(message: bytes) → <built-in function any>[source]
track.persistence.socketed.write(writer, msg)[source]

track.persistence.storage module

class track.persistence.storage.LocalStorage(target_file: str = None, _objects: Dict[uuid.UUID, <built-in function any>] = <factory>, _projects: Set[uuid.UUID] = <factory>, _groups: Set[uuid.UUID] = <factory>, _trials: Set[uuid.UUID] = <factory>, _project_names: Dict[str, uuid.UUID] = <factory>, _group_names: Dict[str, uuid.UUID] = <factory>, _trial_names: Dict[str, uuid.UUID] = <factory>, _old_rev_tags: Dict[str, int] = <factory>)[source]

Bases: object

Attributes:
group_names
groups
objects
project_names
projects
target_file
trials

Methods

reload(self[, filename]) Reload storage and discard current objects
smart_reload(self[, filename]) Updates current objects with new data
commit  
get_current_version_tag  
get_previous_version_tag  
commit(self, file_name_override=None, **kwargs)[source]
get_current_version_tag(self, obj)[source]
get_previous_version_tag(self, obj)[source]
group_names
groups
objects
project_names
projects
reload(self, filename=None)[source]

Reload storage and discard current objects

smart_reload(self, filename=None)[source]

Updates current objects with new data

target_file = None
trials
track.persistence.storage.load_database(json_name)[source]

track.persistence.utils module

track.persistence.utils.parse_options(options)[source]
track.persistence.utils.parse_uri(uri)[source]

Parse a URI and returns a dictionary from it

scheme:[//authority]path[?query][#fragment] with authority = [userinfo@]host[:port]

Module contents

track.persistence.get_protocol(backend_name)[source]

proto://arg

track.persistence.make_cockroach_protocol(uri)[source]
track.persistence.make_comet_ml(uri)[source]
track.persistence.make_ephemeral_protocol(uri)[source]
track.persistence.make_local(uri, strict=True, eager=True)[source]
track.persistence.make_mongodb_protocol(uri)[source]
track.persistence.make_pickled_protocol(uri)[source]
track.persistence.make_socket_protocol(uri)[source]
track.persistence.register(name, proto)[source]