From efa1dbb050df21c0a9363a9425d5508ccbb30935 Mon Sep 17 00:00:00 2001 From: jlnav Date: Mon, 9 Oct 2023 11:29:49 -0500 Subject: [PATCH] first pass on briefly mentioning decorators in generator function guide --- docs/function_guides/generator.rst | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/function_guides/generator.rst b/docs/function_guides/generator.rst index c8d0b3ef6..c8499b4a3 100644 --- a/docs/function_guides/generator.rst +++ b/docs/function_guides/generator.rst @@ -5,8 +5,13 @@ Generator Functions Generator and :ref:`Simulator functions` have relatively similar interfaces. +Writing a Generator +------------------- + .. code-block:: python + @input_fields(["f"]) + @output_data([("x", float)]) def my_generator(Input, persis_info, gen_specs, libE_info): batch_size = gen_specs["user"]["batch_size"] @@ -22,19 +27,23 @@ Most ``gen_f`` function definitions written by users resemble:: where: - * ``Input`` is a selection of the :ref:`History array` - * :ref:`persis_info` is a dictionary containing state information - * :ref:`gen_specs` is a dictionary of generator parameters, including which fields from the History array got sent - * ``libE_info`` is a dictionary containing libEnsemble-specific entries + * ``Input`` is a selection of the :ref:`History array`, a NumPy array. + * :ref:`persis_info` is a dictionary containing state information. + * :ref:`gen_specs` is a dictionary of generator parameters. + * ``libE_info`` is a dictionary containing miscellaneous entries. + +*Optional* ``input_fields`` and ``output_data`` decorators for the function describe the +fields to pass in and the output data format. Otherwise those fields +need to be specified in :class:`GenSpecs`. Valid generator functions can accept a subset of the above parameters. So a very simple generator can start:: def my_generator(Input): -If gen_specs was initially defined:: +If ``gen_specs`` was initially defined:: gen_specs = { - "gen_f": some_function, + "gen_f": my_generator, "in": ["f"], "out:" ["x", float, (1,)], "user": {