Detailed API documentation

pysmac.optimizer module

class pysmac.optimizer.SMAC_optimizer(t_limit_total_s=None, mem_limit_smac_mb=None, working_directory=None, persistent_files=False, debug=False)[source]

Bases: object

The main class of pysmac instanciated by the user.

This is the class a user instanciates to use SMAC. Constructing the object does not start the minimization immediately. The user has to call the method minimize for the actual optimization. This design choice enables easy enough usage for novice users, but allows experts to change many of SMAC’s parameters by editing the ‘smac_options’ dict

Parameters:
  • t_limit_total_s (float) – the total time budget (in seconds) for the optimization. None means that no wall clock time constraint is enforced.
  • mem_limit_smac_mb (int) – memory limit for the Java Runtime Environment in which SMAC will be executed. None means system default.
  • working_directory (str) – directory where SMACs output files are stored. None means a temporary directory will be created via the tempfile module.
  • persistent_files (bool) – whether or note these files persist beyond the runtime of the optimization.
  • debug (bool) – set this to true for debug information (pysmac and SMAC itself) logged to standard-out.
minimize(func, max_evaluations, parameter_dict, conditional_clauses=[], forbidden_clauses=[], deterministic=True, num_train_instances=None, num_test_instances=None, train_instance_features=None, num_runs=1, num_procs=1, seed=0, mem_limit_function_mb=None, t_limit_function_s=None)[source]

Function invoked to perform the actual minimization given all necessary information.

Parameters:
  • func (callable) – the function to be called
  • max_evaluations (int) – number of function calls allowed during the optimization (does not include optional validation).
  • parameter_dict (list) – parameter configuration space definition, see Defining the Parameter Configuration Space.
  • conditional_clauses – list of conditional dependencies between parameters, see Defining the Parameter Configuration Space.
  • forbidden_clauses – list of forbidden parameter configurations, see Defining the Parameter Configuration Space.
  • deterministic (bool) – whether the function to be minimized contains random components, see Non-determinstic Functions.
  • num_train_instances (int) – number of instances used during the configuration/optimization, see Optimizing on a Set of Instances.
  • num_test_instances (int) – number of instances used for testing/validation, see Validation.
  • num_runs (int) – number of independent SMAC runs.
  • num_procs (int) – number SMAC runs that can be executed in paralell
  • seed (int/list of ints) – seed for SMAC’s Random Number generator. If int, it is used for the first run, additional runs use consecutive numbers. If list, it specifies a seed for every run.
  • mem_limit_function_mb (int) – sets the memory limit for your function (value in MB). None means no restriction. Be aware that this limit is enforced for each SMAC run separately. So if you have 2 parallel runs, pysmac could use twice that value (and twice the value of mem_limit_smac_mb) in total. Note that due to the creation of the subprocess, the amount of memory available to your function is less than the value specified here. This option exists mainly to prevent a memory usage of 100% which will at least slow the system down.
  • t_limit_function_s – cutoff time for a single function call. None means no restriction. If optimizing run time, SMAC can choose a shorter cutoff than the provided one for individual runs. If None was provided, then there is no cutoff ever!
smac_options = {}

A dict associated with the optimizer object that controlls options mainly for SMAC

pysmac.remote_smac module

pysmac.remote_smac.process_parameter_definitions(parameter_dict)[source]

A helper function to process all parameter definitions conviniently with just one call.

This function takes the parametr definitions from the user, converts them into lines for SMAC’s PCS format, and also creates a dictionary later used in the comunication with the SMAC process.

Parameters:paramer_dict – The user defined parameter configuration space
pysmac.remote_smac.process_single_parameter_definition(name, specification)[source]

A helper function to process a single parameter definition for further communication with SMAC.

class pysmac.remote_smac.remote_smac(scenario_fn, additional_options_fn, seed, class_path, memory_limit, parser_dict, java_executable)[source]

Bases: object

The class responsible for the TCP/IP communication with a SMAC instance.

Starts SMAC in IPC mode. SMAC will wait for udp messages to be sent.

next_configuration()[source]

Method that queries the next configuration from SMAC.

Connects to the socket, reads the message from SMAC, and converts into a proper Python representation (using the proper types). It also checks whether the SMAC subprocess is still alive.

Returns:either a dictionary with a configuration, or None if SMAC has terminated
report_result(result_dict)[source]

Method to report the latest run results back to SMAC.

This method communicates the results from the last run back to SMAC.

Parameters:result_dict – dictionary with the keys ‘value’, ‘status’, and ‘runtime’.
udp_timeout = 5

The default value for a timeout for the socket

pysmac.remote_smac.remote_smac_function(only_arg)[source]

The function that every worker from the multiprocessing pool calls to perform a separate SMAC run.

This function is not part of the API that users should access, but rather part of the internals of pysmac. Due to the limitations of the multiprocessing module, it can only take one argument which is a list containing important arguments in a very specific order. Check the source code if you want to learn more.