|
3 | 3 | Generator Specs |
4 | 4 | =============== |
5 | 5 |
|
6 | | -Used to specify the generator function, its inputs and outputs, and user data. |
7 | | - |
8 | | -Can be constructed and passed to libEnsemble as a Python class or a dictionary. |
9 | | - |
10 | | -.. tab-set:: |
11 | | - |
12 | | - .. tab-item:: class |
13 | | - |
14 | | - .. code-block:: python |
15 | | - :linenos: |
16 | | -
|
17 | | - ... |
18 | | - import numpy as np |
19 | | - from libensemble import GenSpecs |
20 | | - from generator import gen_random_sample |
21 | | -
|
22 | | - ... |
23 | | -
|
24 | | - gen_specs = GenSpecs( |
25 | | - gen_f=gen_random_sample, |
26 | | - outputs=[("x", float, (1,))], |
27 | | - user={ |
28 | | - "lower": np.array([-3]), |
29 | | - "upper": np.array([3]), |
30 | | - "gen_batch_size": 5, |
31 | | - }, |
32 | | - ) |
33 | | - ... |
34 | | -
|
35 | | - .. autopydantic_model:: libensemble.specs.GenSpecs |
36 | | - :model-show-json: False |
37 | | - :model-show-config-member: False |
38 | | - :model-show-config-summary: False |
39 | | - :model-show-validator-members: False |
40 | | - :model-show-validator-summary: False |
41 | | - :field-list-validators: False |
42 | | - |
43 | | - .. tab-item:: dict |
44 | | - |
45 | | - .. code-block:: python |
46 | | - :linenos: |
47 | | -
|
48 | | - ... |
49 | | - import numpy as np |
50 | | - from generator import gen_random_sample |
51 | | -
|
52 | | - ... |
53 | | -
|
54 | | - gen_specs = { |
55 | | - "gen_f": gen_random_sample, |
56 | | - "out": [("x", float, (1,))], |
57 | | - "user": { |
58 | | - "lower": np.array([-3]), |
59 | | - "upper": np.array([3]), |
60 | | - "gen_batch_size": 5, |
61 | | - }, |
62 | | - } |
63 | | -
|
64 | | - .. seealso:: |
65 | | - |
66 | | - .. _gen-specs-example1: |
67 | | - |
68 | | - - test_uniform_sampling.py_: |
69 | | - the generator function ``uniform_random_sample`` in sampling.py_ will generate 500 random |
70 | | - points uniformly over the 2D domain defined by ``gen_specs["ub"]`` and |
71 | | - ``gen_specs["lb"]``. |
72 | | - |
73 | | - .. literalinclude:: ../../libensemble/tests/functionality_tests/test_uniform_sampling.py |
74 | | - :start-at: gen_specs |
75 | | - :end-before: end_gen_specs_rst_tag |
76 | | - |
77 | | - .. seealso:: |
78 | | - |
79 | | - - test_persistent_aposmm_nlopt.py_ shows an example where ``gen_specs["in"]`` is empty, but |
80 | | - ``gen_specs["persis_in"]`` specifies values to return to the persistent generator. |
81 | | - |
82 | | - - test_persistent_aposmm_with_grad.py_ shows a similar example where an ``H0`` is used to |
83 | | - provide points from a previous run. In this case, ``gen_specs["in"]`` is populated to provide |
84 | | - the generator with data for the initial points. |
85 | | - |
86 | | - - In some cases you might be able to give different (perhaps fewer) fields in ``"persis_in"`` |
87 | | - than ``"in"``; you may not need to give ``x`` for example, as the persistent generator |
88 | | - already has ``x`` for those points. See `more example uses`_ of ``persis_in``. |
| 6 | +Used to specify the generator, its inputs and outputs, and user data. |
| 7 | + |
| 8 | +.. code-block:: python |
| 9 | + :linenos: |
| 10 | +
|
| 11 | + ... |
| 12 | + import numpy as np |
| 13 | + from libensemble import GenSpecs |
| 14 | + from generator import gen_random_sample |
| 15 | +
|
| 16 | + ... |
| 17 | +
|
| 18 | + gen_specs = GenSpecs( |
| 19 | + gen_f=gen_random_sample, |
| 20 | + outputs=[("x", float, (1,))], |
| 21 | + user={ |
| 22 | + "lower": np.array([-3]), |
| 23 | + "upper": np.array([3]), |
| 24 | + "gen_batch_size": 5, |
| 25 | + }, |
| 26 | + ) |
| 27 | + ... |
| 28 | +
|
| 29 | +.. autopydantic_model:: libensemble.specs.GenSpecs |
| 30 | + :model-show-json: False |
| 31 | + :model-show-config-member: False |
| 32 | + :model-show-config-summary: False |
| 33 | + :model-show-validator-members: False |
| 34 | + :model-show-validator-summary: False |
| 35 | + :field-list-validators: False |
89 | 36 |
|
90 | 37 | .. note:: |
91 | 38 |
|
|
0 commit comments