<jupyter_start><jupyter_text>Xopt class, TNK test functionThis is the class method for running Xopt.TNK function$n=2$ variables:$x_i \in [0, \pi], i=1,2$Objectives:- $f_i(x) = x_i$Constraints:- $g_1(x) = -x_1^2 -x_2^2 + 1 + 0.1 \cos\left(16 \arctan \frac{x_1}{x_2}\right) \le 0$- $g_2(x) = (x_1 - 1/2)^2 + (x_2-1/2)^2 \le 0.5$<jupyter_code>from xopt import Xopt

import matplotlib.pyplot as plt
from botorch.utils.multi_objective.pareto import is_non_dominated
%matplotlib inline

import os
SMOKE_TEST = os.environ.get('SMOKE_TEST')

# To see log messages
from xopt import output_notebook
output_notebook()<jupyter_output><empty_output><jupyter_text>The `Xopt` object can be instantiated from a JSON or YAML file, or a dict, with the proper structure.Here we will make one<jupyter_code>import yaml
# Make a proper input file. 
YAML="""
xopt: {output_path: null}

algorithm:
  name:  mobo
  options: 
    ref: [1.4, 1.4]
    n_initial_samples: 5
    n_steps: 10
    generator_options:
        batch_size: 4
  
simulation: 
  name: test_TNK
  evaluate: xopt.tests.evaluators.TNK.evaluate_TNK
  
vocs:
  name: TNK_test
  description: null
  simulation: test_TNK
  templates: null
  variables:
    x1: [0, 3.14159]
    x2: [0, 3.14159]
  objectives: {y1: MINIMIZE, y2: MINIMIZE}
  constraints:
    c1: [GREATER_THAN, 0]
    c2: ['LESS_THAN', 0.5]
  linked_variables: {}
  constants: {a: dummy_constant}

"""
config = yaml.safe_load(YAML)
# Optional: Connect the function directly
#from xopt.evaluators.test_TNK import evaluate_TNK 
#config['simulation']['evaluate'] = evaluate_TNK 
if SMOKE_TEST:
    config['algorithm']['options']['n_steps'] = 3
    config['algorithm']['options']['generator_options']['num_restarts'] = 2
    config['algorithm']['options']['generator_options']['raw_samples'] = 2


X = Xopt(config)
X<jupyter_output>Loading config from dict.
Loading config from dict.
Loading config from dict.
Loading config from dict.
Loading config from dict.
`name` keyword no longer allowed in vocs config, removing
`description` keyword no longer allowed in vocs config, removing
`simulation` keyword no longer allowed in vocs config, removing
`templates` keyword no longer allowed in vocs config, moving to simulation `options`
Warning: No path set for key xopt : output_path<jupyter_text>Run MOBOMOBO is designed to run in serial or parallel<jupyter_code># Pick one of these
from concurrent.futures import ThreadPoolExecutor as PoolExecutor
#from concurrent.futures import ProcessPoolExecutor as PoolExecutor

executor = PoolExecutor()
# This will also work. 
#executor=None
%%time
X.run(executor=executor)<jupyter_output>Starting at time 2022-03-03T15:10:38-08:00
started running optimization with generator: <xopt.bayesian.generators.mobo.MOBOGenerator object at 0x11ec52f70>
submitting initial candidates
starting optimization loop
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
submitting candidates
CPU times: user 21min 31s, sys: 57.1 s, total: 22min 28s
Wall time: 6min 2s<jupyter_text>Plot<jupyter_code>fig, ax = plt.subplots()

# get results and get valid observations
results = X.results
train_y = results['objectives']
valid_y = train_y[results['feasibility'].flatten()]

# plot results
ax.plot(train_y[:, 0], train_y[:, 1], '.')
ax.set_ylabel('$f_2$')
ax.set_xlabel('$f_1$')

# highlight Pareto front, ONLY using valid observations (note botorch assumes maximization when determing dominant points)
non_dom = is_non_dominated(-valid_y)
ax.plot(valid_y[:,0][non_dom],valid_y[:,1][non_dom],'C1o')

plt.show()
# Cleanup
!rm results.json<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1090860359153042, 'fraction_numerical': 0.028678638434735997, 'mean_word_length': 5.5473684210526315, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '23425', 'license': 'Apache-2.0', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1286, 'n_words': 366, 'path': 'examples/mobo/mobo.ipynb', 'repo_name': 'ChristopherMayes/Xopt', 'size': '3731'}