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 readible 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 you wish to abruptly end this interface for whatever rease please raise the exception InterfaceInterrupt, which will then be safely caught.

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]}. Providing any extra keys will also be saved byt he 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

Exception that is raised when the interface is ended with the end event, or some other interruption.

class mloop.interfaces.ShellInterface(command='./run_exp', params_args_type='direct', **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. The same example as before would be

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

    Default ‘direct’.

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