interfaces

Module of the interfaces used to connect the controller to the experiment.

class mloop.interfaces.FileInterface(interface_out_filename='exp_input', interface_in_filename='exp_output', interface_file_type='txt', **kwargs)

Bases: mloop.interfaces.Interface

Interfaces between the files produced by the experiment and the queues accessed by the controllers.

Parameters:
  • params_out_queue (queue) – Queue for parameters to next be run by experiment.
  • costs_in_queue (queue) – Queue for costs (and other details) that have been returned by experiment.
Keyword Arguments:
 
  • interface_out_filename (Optional [string]) – filename for file written with parameters.
  • interface_in_filename (Optional [string]) – filename for file written with parameters.
  • interface_file_type (Optional [string]) – file type to be written either ‘mat’ for matlab or ‘txt’ for readable text file. Defaults to ‘txt’.
get_next_cost_dict(params_dict)

Implementation of file read in and out. Put parameters into a file and wait for a cost file to be returned.

class mloop.interfaces.Interface(interface_wait=1, **kwargs)

Bases: threading.Thread

A abstract class for interfaces which populate the costs_in_queue and read from the params_out_queue. Inherits from Thread

Parameters:
  • interface_wait (Optional [float]) – Time between polling when needed in interface.
  • params_out_queue (queue) – Queue for parameters to next be run by experiment.
  • costs_in_queue (queue) – Queue for costs (and other details) that have been returned by experiment.
  • end_event (event) – Event which triggers the end of the interface.
Keyword Arguments:
 

interface_wait (float) – Wait time when polling for files or queues is needed.

get_next_cost_dict(params_dict)

Abstract method.

This is the only method that needs to be implemented to make a working interface.

Given the parameters the interface must then produce a new cost. This may occur by running an experiment or program. If an error is raised by this method, the optimization will halt.

Parameters:params_dict (dictionary) – A dictionary containing the parameters. Use params_dict[‘params’] to access them.
Returns:
The cost and other properties derived from
the experiment when it was run with the parameters. If just a cost was produced provide {‘cost’: [float]}, if you also have an uncertainty provide {‘cost’: [float], ‘uncer’: [float]}. If the run was bad you can simply provide {‘bad’: True}. For completeness you can always provide all three using {‘cost’: [float], ‘uncer’:[float], ‘bad’: [bool]}. Any extra keys provided will also be saved by the controller.
Return type:cost_dict (dictionary)
run()

The run sequence for the interface.

This method does NOT need to be overloaded create a working interface.

exception mloop.interfaces.InterfaceInterrupt

Bases: Exception

The InterfaceInterrupt is now deprecated.

The Interface class can now handle arbitrary errors, so there is no need for Interface.get_next_cost_dict() to raise an InterfaceInterrupt in particular. Instead raise an appropriate error given the situation.

class mloop.interfaces.ShellInterface(command='./run_exp', params_args_type='direct', param_names=None, **kwargs)

Bases: mloop.interfaces.Interface

Interface for running programs from the shell.

Parameters:
  • params_out_queue (queue) – Queue for parameters to next be run by experiment.
  • costs_in_queue (queue) – Queue for costs (and other details) that have been returned by experiment.
Keyword Arguments:
 
  • command (Optional [string]) – The command used to run the experiment. Default ‘./run_exp’.
  • params_args_type (Optional [string]) –

    The style used to pass parameters. Can be ‘direct’ or ‘named’. If ‘direct’ it is assumed the parameters are fed directly to the program. For example if I wanted to run the parameters [7,5,9] with the command ‘./run_exp’ I would use the syntax:

    ./run_exp 7 5 9
    

    ’named’ on the other hand requires an option for each parameter. The options should be name –param1, –param2 etc (unless param_names is specified, see below)). The same example as before would be

    ./run_exp --param1 7 --param2 5 --param3 9
    

    Default ‘direct’.

  • param_names (Optional [string]) – List of names for parameters to be passed as options to the shell command, replacing –param1, –param2, etc. If set to None then the default parameter names will be used. Default None.
get_next_cost_dict(params_dict)

Implementation of running a command with parameters on the command line and reading the result.

class mloop.interfaces.TestInterface(test_landscape=None, **kwargs)

Bases: mloop.interfaces.Interface

Interface for testing. Returns fake landscape data directly to learner.

Parameters:
  • params_out_queue (queue) – Parameters to be used to evaluate fake landscape.
  • costs_in_queue (queue) – Queue for costs (and other details) that have been calculated from fake landscape.
Keyword Arguments:
 
  • test_landscape (Optional [TestLandscape]) – Landscape that can be given a set of parameters and a cost and other values. If None creates a the default landscape. Default None
  • out_queue_wait (Optional [float]) – Time in seconds to wait for queue before checking end flag.
get_next_cost_dict(params_dict)

Test implementation. Gets the next cost from the test_landscape.

mloop.interfaces.create_interface(interface_type='file', **interface_config_dict)

Start a new interface with the options provided.

Parameters:
  • interface_type (Optional [str]) – Defines the type of interface, can be ‘file’, ‘shell’ or ‘test’. Default ‘file’.
  • **interface_config_dict – Options to be passed to interface.
Returns:

An interface as defined by the keywords

Return type:

interface