Python Command Reference

The module jcmwave.optimizer allows for controlling the optimization server and for creating new optimization studies. In the most cases it is sufficient to create a new Study instance by calling create_study(). For example:

domain = [
   {'name': 'x1', 'type': 'continuous', 'domain': (-1.5,1.5)}, 
   {'name': 'x2', 'type': 'continuous', 'domain': (-1.5,1.5)},
]
study = jcmwave.optimizer.create_study(domain=domain, name='example')

Note

The study object allows for setting up the optimization itself. For more information, see jcmwave.client.Study.

jcmwave.optimizer.client(port=None)

Creates a jcmwave.client.Client instance, that can communicate with an optimization server. If no server is running, it will be started automatically.

Note

This function is useful if you want to start the optimization server on another computer. In this case you can do the following:

  1. Login to the other computer
  2. Start the optimization server manually by calling $JCMROOT/ThirdPartySupport/Python/bin/JCMoptimizer.
  3. Forward the ports of the optimizer and the dahsboard to your local computer, e.g. by calling ssh -NL 4554:localhost:4554 -NL 4555:localshost:4555 user@remotehost
  4. Create a jcmwave.client.Client instance: c=jcmwave.optimizer.client(port=4554).
  5. Create a new study by calling c.create_study() (see jcmwave.client.Client.create_study()).
Parameters:port – The port that the optimization server is listening on. If no port is specified, the client communicates with the server that was started by calling startup().
jcmwave.optimizer.create_benchmark(**kwargs)

Creates a new Benchmark object for benchmarking different optimization studies against each other. Example:

benchmark = jcmwave.optimizer.create_benchmark(num_average=6);
Parameters:
  • benchmark_id (str) – A unique identifier of the benchmark.
  • num_average (int) – Number of study runs to determine average study performance
jcmwave.optimizer.create_study(**kwargs)

Creates a new Study instance. Example:

study = jcmwave.optimizer.create_study(domain=domain, name='example')
Parameters:
  • domain (list) –

    List of domain definitions for each parameter. A domain definition consists of a dictionary with the entries

    name:Name of the parameter. E.g. ‘x1’. The name should contain no spaces and must not be equal to function names like ‘sin’, ‘cos’, ‘exp’ etc.
    type:Type of the parameter. Either ‘continuous’, ‘discrete’, or ‘fixed’. Fixed parameters are not optimized, but can be used in the constraint functions.
    domain:The domain of the parameter. For continuous parameters this is a tuple (min, max). For discrete parameters this is a list of values, e.g. [1,2,3,4,5]. Note that it is assumed, that the objective values are correlated not only for continuous but also for discrete values. For uncorrelated values (i.e. categorial values) one should rather setup independent studies. For fixed parameters the domain is a single parameter value.

    Example:

    domain = [{'name': 'x1', 'type': 'continuous', 'domain': (-2.0,2.0)}, 
              {'name': 'x2', 'type': 'continuous', 'domain': (-2.0,2.0)},
              {'name': 'x3', 'type': 'discrete', 'domain': (-1.0,0.0,1.0)},
              {'name': 'x4', 'type': 'fixed', 'domain': 2.0}]
    
  • constraints (list) –

    List of constraints on the domain. Each list element is a dictionary with the entries

    name:Name of the constraint.
    constraint:A string defining a function that is smaller zero if and only if the constraint is met. The following operations and functions may be used: +,-,*,/,^,sqrt,sin,cos,tan,abs,round, sgn, tunc. E.g. 'x1^2 + x2^2 + sin(x1+x2)'

    Example:

    constraints = [
        {'name': 'circle', 'constraint': 'x1^2+x2^2-4'},
        {'name': 'triangle', 'constraint': 'x1-x2'},
    ]
    
  • study_id (str) – A unique identifier of the study. All relevant information on the study are saved in a file named study_id+’.mpk’ If the study already exists, the domain and constraints do not need to be provided. If not set, the study_id is set to a random unique string.
  • name (str) – The name of the study that will be shown in the dashboard.
  • save_dir (str) – The path to a directory, where the study file (mpk-file) is saved. If False, no study file is saved.
  • driver (str) – Driver used for the study (default: ‘BayesOptimization’). For a list of drivers, see the Analysis and Optimization Toolkit/Driver Reference.
  • output_precision (float) –

    Precision level for ouput of parameters. (Default: 1e-10)

    Note

    Rounding the output can potentially lead to a slight breaking of constraints.

  • dashboard (bool) – If true, a dashboard server will be started for the study. (Default: True)
  • open_browser (bool) – If true, a browser window with the dashboard is started. (Default: True)
jcmwave.optimizer.shutdown(port=None, force=False)

Shuts down the optimization server

Parameters:
  • port – The port where the optimization server is running. If not port is provided, the server started by calling startup() is closed.
  • force (bool) – If True the optimization server is closed even if a study is not yet finished.
jcmwave.optimizer.startup(port=None, dashboard_port=None, persistent=False)

Starts the optimizer on a specific host and port

Parameters:
  • port (str) – The port that the optimization server is listening on.
  • dashboard_port (str) – The port that the dashboard server is listening on.
  • persistent (bool) – In persistent mode the optimization server will stay alive after Python has closed. Otherwise the server will shut down automatically.