From 0a96da5e7deadbc206bb04b02a5e948248acdbbe Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 28 Oct 2019 11:39:06 -0500 Subject: [PATCH 01/19] intro --- source/cep/cep27.rst | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 source/cep/cep27.rst diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst new file mode 100644 index 000000000..44c75164b --- /dev/null +++ b/source/cep/cep27.rst @@ -0,0 +1,96 @@ +CEP 27 - Agent Toolkit Capabilities +*********************************** + +:CEP: 27 +:Title: Agent Toolkit Capabilities +:Last-Modified: 2019-10-28 +:Author: Baptiste Mouginot +:Status: Pending +:Type: Standards Track +:Created: Baptiste Mouginot + +Abstract +======== + +|Cyclus| toolkit is designed to easily implement specific capabilities in newly +developed archetypes, such as trading policy, commodity producers... To add +characteristics to archetypes such as Position or Metadata, the actual +implementation method is very verbosy where in each archetypes we need to add +the added specification in the header, assign it and use it in the cpp file, +without guaranty on the consistency in the variables naming and implementation +between multiple archetypes. +This CEP explains how to use snippets to simplify and maintain consistency +between the different implementation and usage across the implementation of toolkit +feature inside multiple archetypes. + +.. _agent-spec-docs: + +Agent Spec +=========== + +Agents will be uniquely identified by 3 components together referred to as an +"agent spec": + +1. path: e.g. ``my/module/path`` + + A slash-delimited, valid filesystem path relative to CYCLUS_PATH (see + Module Discovery below). + +2. library: e.g. ``MyModule`` + + Name of the compiled shared object library file without the "lib" prefix + and without the file extension. If empty, is expanded to the agent class. + The example above would correspond to a library file named "libMyModule.so" + (linux), "libMyModule.dylib" (darwin), etc. + +3. agent class: e.g. ``MyAgent`` + + The name of the agent's c++ class as compiled into the shared library file. + +An agent spec also has a single-string form composed of the three components +separated by colons:: + + [path]:[library]:[agent-class] + + e.g. "my/module/path:MyModule:MyAgent" + +Example linux agent specs with corresponding filepath expansions:: + + my/path:MyModule:MyAgent -> my/path/libMyModule.so + my/path::MyAgent -> my/path/libMyAgent.so + :MyModule:MyAgent -> libMyModule.so + ::MyAgent -> libMyAgent.so + +Module Discovery +================ + +When running a simulation, |Cyclus| will search the following candidate +directories (in order) for each given agent spec: + +1. Each colon-separated directory in the CYCLUS_PATH environment variable. + +2. The default |cyclus| module install directory: ``[install-dir]/lib/cyclus``. + +|Cyclus| will check for the library by building consecutive paths with the +following composition:: + + [candidate-dir]/[path]/lib[library][extension] + +|Cyclus| uses the first matching shared library file found and assumes the +specified agent class exists inside it. + +Conventions +============ + +The path should consist of only alpha-numeric characters, slashes, +underscores, and dashes. **No** spaces. If there are resource files that must +be installed with the shared library file, the library and resources should be +placed in their own directory. + +The shared library name should consist of only alpha-numeric characters, +slashes, underscores. **No** spaces. If the shared library only has a +single agent in it, the library should be the same as the agent class. For +example, if my agent was named ``MyAgent``, then the library file should be +named ``libMyAgent.so`` on a linux system. This allows the defaults to +prevent stuttering in the agent's module spec. + From 9ea0df2fef1c4b3679499dde01ed50b71cf1317e Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 29 Oct 2019 18:46:36 -0500 Subject: [PATCH 02/19] update --- source/cep/cep27.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 44c75164b..825540e24 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -26,7 +26,7 @@ feature inside multiple archetypes. .. _agent-spec-docs: Agent Spec -=========== +========== Agents will be uniquely identified by 3 components together referred to as an "agent spec": From 6686d606d2f25d022fb722e3dfff0f740aa81f55 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 30 Oct 2019 10:33:41 -0500 Subject: [PATCH 03/19] done with first draft --- source/cep/cep27.rst | 101 +++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 825540e24..df2b8fbc0 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -5,7 +5,7 @@ CEP 27 - Agent Toolkit Capabilities :Title: Agent Toolkit Capabilities :Last-Modified: 2019-10-28 :Author: Baptiste Mouginot -:Status: Pending +:Status: Active :Type: Standards Track :Created: Baptiste Mouginot @@ -25,72 +25,71 @@ feature inside multiple archetypes. .. _agent-spec-docs: -Agent Spec -========== +Toolkit Implementation +====================== -Agents will be uniquely identified by 3 components together referred to as an -"agent spec": +The |Cyclus| toolkit will contain 3 different files: i2 for the definition of +the snippet class element (``cpp`` and header) that allows to use the +capabilities, and optionally to register its values in the output database, a +snippet simplifying the integration of the feature in a newly develop +archetypes. -1. path: e.g. ``my/module/path`` +The snippet file with then be included in the header part of the archetypes +class declaration as": ``#include toolkit/my_snippet.cycpp.h`` - A slash-delimited, valid filesystem path relative to CYCLUS_PATH (see - Module Discovery below). +(The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and +inform developers that this is not a standard C++ header) +The snippet file, will contain all the declaration of all the variable required +to use the capabilities class: -2. library: e.g. ``MyModule`` +- the definition of the capability class as a member variable - Name of the compiled shared object library file without the "lib" prefix - and without the file extension. If empty, is expanded to the agent class. - The example above would correspond to a library file named "libMyModule.so" - (linux), "libMyModule.dylib" (darwin), etc. +- (optional) if the capability requires/allows variable input from users, + standard |Cyclus| member variable declaration with variable ``#pragma`` is + required. In addition, to the standard variable declaration and the + ``#pragma`` the method also require a ``std::vector + cycpp_shape_myvariable0`` to be declared for each of the decorated variable. + ``cycpp preprocessor`` is not able at the time to add them automatically for + included files. -3. agent class: e.g. ``MyAgent`` +The main interest of this include method would be to insure consistency across +archetypes using the same toolkit capability requiring user input.i, avoiding 1 +set of input syntax per archetypes for the same capability. - The name of the agent's c++ class as compiled into the shared library file. +If the toolkit features needs to capabilities to write in the output database a +``RecordSnippet(Agent* agent)`` method will be implemented to avoid +multiplication of implementation in the archetypes. -An agent spec also has a single-string form composed of the three components -separated by colons:: - [path]:[library]:[agent-class] - - e.g. "my/module/path:MyModule:MyAgent" +Archetypes Integration +====================== -Example linux agent specs with corresponding filepath expansions:: +When the capability is integrated in an Archetype the following implementation +have to be done: - my/path:MyModule:MyAgent -> my/path/libMyModule.so - my/path::MyAgent -> my/path/libMyAgent.so - :MyModule:MyAgent -> libMyModule.so - ::MyAgent -> libMyAgent.so +1. Include the snippet in the class header core: ``#include + toolkit/my_snippet.cycpp,h`` -Module Discovery -================ +2. Add the proper default initialisation of the variable required for the + snippet -When running a simulation, |Cyclus| will search the following candidate -directories (in order) for each given agent spec: +3. In the ``Archetype::EnterNotify()``, assign the Snippet with value + corresponding to the user input. -1. Each colon-separated directory in the CYCLUS_PATH environment variable. +4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the + Archetype operation. -2. The default |cyclus| module install directory: ``[install-dir]/lib/cyclus``. +Class member vs Inheritance +=========================== -|Cyclus| will check for the library by building consecutive paths with the -following composition:: +The main issue with inheriting of the capability class is that one will need to +also modify the archetype class declaration in addition to simply including the +snippet at the right place. - [candidate-dir]/[path]/lib[library][extension] +This may also lead to confusion, as one can believe that the user input value +for variable are passed in the constructor of the class and might lead the +develop to skip the assignation of the value in the inherited class in the +``EnterNotify``... -|Cyclus| uses the first matching shared library file found and assumes the -specified agent class exists inside it. - -Conventions -============ - -The path should consist of only alpha-numeric characters, slashes, -underscores, and dashes. **No** spaces. If there are resource files that must -be installed with the shared library file, the library and resources should be -placed in their own directory. - -The shared library name should consist of only alpha-numeric characters, -slashes, underscores. **No** spaces. If the shared library only has a -single agent in it, the library should be the same as the agent class. For -example, if my agent was named ``MyAgent``, then the library file should be -named ``libMyAgent.so`` on a linux system. This allows the defaults to -prevent stuttering in the agent's module spec. +Otherwise behavior would be similar. From 1c75d2bb1fe81567d21386d25c9dbdc8e83d9164 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 30 Oct 2019 10:40:34 -0500 Subject: [PATCH 04/19] some review --- source/cep/cep27.rst | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index df2b8fbc0..d86e01dd7 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -7,7 +7,8 @@ CEP 27 - Agent Toolkit Capabilities :Author: Baptiste Mouginot :Status: Active :Type: Standards Track -:Created: Baptiste Mouginot +:Created: Baptiste Mouginot + Abstract ======== @@ -15,34 +16,31 @@ Abstract |Cyclus| toolkit is designed to easily implement specific capabilities in newly developed archetypes, such as trading policy, commodity producers... To add characteristics to archetypes such as Position or Metadata, the actual -implementation method is very verbosy where in each archetypes we need to add -the added specification in the header, assign it and use it in the cpp file, +implementation method is very verbosy where in each archetypes one need to add +the inew specification in the header, assign it and use it in the cpp file, without guaranty on the consistency in the variables naming and implementation -between multiple archetypes. -This CEP explains how to use snippets to simplify and maintain consistency -between the different implementation and usage across the implementation of toolkit -feature inside multiple archetypes. +across multiple archetypes. +This CEP explains how to use snippets would simplify and maintain consistency +in the implementation and the usage, across multiple archetypes. -.. _agent-spec-docs: Toolkit Implementation ====================== -The |Cyclus| toolkit will contain 3 different files: i2 for the definition of -the snippet class element (``cpp`` and header) that allows to use the -capabilities, and optionally to register its values in the output database, a -snippet simplifying the integration of the feature in a newly develop -archetypes. +The |Cyclus| toolkit will contain 3 different files: 2 for the definition of the +snippet C++ class (``cpp`` and header) that allows to use the capabilities, and +optionally to register its values in the output database, a snippet simplifying +the integration of the feature in a newly develop archetypes. The snippet file with then be included in the header part of the archetypes class declaration as": ``#include toolkit/my_snippet.cycpp.h`` (The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and inform developers that this is not a standard C++ header) -The snippet file, will contain all the declaration of all the variable required +The snippet file, will contain the declaration of all the variables required to use the capabilities class: -- the definition of the capability class as a member variable +- the definition of the capability class as a member variable. - (optional) if the capability requires/allows variable input from users, standard |Cyclus| member variable declaration with variable ``#pragma`` is @@ -52,8 +50,9 @@ to use the capabilities class: ``cycpp preprocessor`` is not able at the time to add them automatically for included files. + The main interest of this include method would be to insure consistency across -archetypes using the same toolkit capability requiring user input.i, avoiding 1 +archetypes using the same toolkit capability requiring user input, avoiding 1 set of input syntax per archetypes for the same capability. If the toolkit features needs to capabilities to write in the output database a @@ -64,14 +63,14 @@ multiplication of implementation in the archetypes. Archetypes Integration ====================== -When the capability is integrated in an Archetype the following implementation +When the capability is integrated in an Archetype the following implementations have to be done: 1. Include the snippet in the class header core: ``#include - toolkit/my_snippet.cycpp,h`` + toolkit/my_snippet.cycpp,h``. 2. Add the proper default initialisation of the variable required for the - snippet + snippet. 3. In the ``Archetype::EnterNotify()``, assign the Snippet with value corresponding to the user input. @@ -79,17 +78,17 @@ have to be done: 4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the Archetype operation. + Class member vs Inheritance =========================== -The main issue with inheriting of the capability class is that one will need to -also modify the archetype class declaration in addition to simply including the -snippet at the right place. - +With inheritance of the capability class, one will need to also modify the +archetype class declaration in addition to simply including the snippet at the +right place. This may also lead to confusion, as one can believe that the user input value for variable are passed in the constructor of the class and might lead the develop to skip the assignation of the value in the inherited class in the ``EnterNotify``... -Otherwise behavior would be similar. +Otherwise behavior would be very similar. From a5bc8d8b1d2af8469a103ef6cb0c03eee460e74e Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Mon, 18 Nov 2019 13:59:08 -0600 Subject: [PATCH 05/19] Apply suggestions from code review Co-Authored-By: Paul Wilson --- source/cep/cep27.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index d86e01dd7..c5a830e8b 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -13,27 +13,27 @@ CEP 27 - Agent Toolkit Capabilities Abstract ======== -|Cyclus| toolkit is designed to easily implement specific capabilities in newly +The |Cyclus| toolkit is designed to easily implement specific capabilities in newly developed archetypes, such as trading policy, commodity producers... To add characteristics to archetypes such as Position or Metadata, the actual -implementation method is very verbosy where in each archetypes one need to add -the inew specification in the header, assign it and use it in the cpp file, -without guaranty on the consistency in the variables naming and implementation +implementation method is very verbose, where in each archetypes one needs to add +the new specification in the header, assign it and use it in the cpp file, +with no guarantee on the consistency in the variable naming and implementation across multiple archetypes. -This CEP explains how to use snippets would simplify and maintain consistency +This CEP explains how to use snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. Toolkit Implementation ====================== -The |Cyclus| toolkit will contain 3 different files: 2 for the definition of the -snippet C++ class (``cpp`` and header) that allows to use the capabilities, and +Each |Cyclus| toolkit component will contain 3 different files: 2 for the definition of the +snippet C++ class (``cpp`` and header) that allows the use of the capabilities, and optionally to register its values in the output database, a snippet simplifying the integration of the feature in a newly develop archetypes. The snippet file with then be included in the header part of the archetypes -class declaration as": ``#include toolkit/my_snippet.cycpp.h`` +class declaration as: ``#include toolkit/my_snippet.cycpp.h`` (The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and inform developers that this is not a standard C++ header) @@ -51,11 +51,11 @@ to use the capabilities class: included files. -The main interest of this include method would be to insure consistency across +The main purpose of this include method would be to ensure consistency across archetypes using the same toolkit capability requiring user input, avoiding 1 set of input syntax per archetypes for the same capability. -If the toolkit features needs to capabilities to write in the output database a +If the toolkit features needs the capabilities to write in the output database a ``RecordSnippet(Agent* agent)`` method will be implemented to avoid multiplication of implementation in the archetypes. @@ -69,7 +69,7 @@ have to be done: 1. Include the snippet in the class header core: ``#include toolkit/my_snippet.cycpp,h``. -2. Add the proper default initialisation of the variable required for the +2. Add the proper default initialization of the variable required for the snippet. 3. In the ``Archetype::EnterNotify()``, assign the Snippet with value From 3fcb4a7cdf38e1404c0dc27c384afda0cc6a9a59 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 18 Nov 2019 16:27:45 -0600 Subject: [PATCH 06/19] some improvement and addition of an implementation example --- source/cep/cep27.rst | 73 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index c5a830e8b..8db29276e 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -27,16 +27,18 @@ in the implementation and the usage, across multiple archetypes. Toolkit Implementation ====================== -Each |Cyclus| toolkit component will contain 3 different files: 2 for the definition of the -snippet C++ class (``cpp`` and header) that allows the use of the capabilities, and -optionally to register its values in the output database, a snippet simplifying -the integration of the feature in a newly develop archetypes. - -The snippet file with then be included in the header part of the archetypes +Each |Cyclus| toolkit component will contain 3 different files: +- 2 for the definition of the snippet C++ class (``cpp`` and header) that allows + the use of the capabilities, and optionally to register its values in the + output database, +- a snippet definition file used to simplify the implementation and ensure + consistency accross its integration in the different archetypes. + +The snippet definition file will then be included in the header part of the archetypes class declaration as: ``#include toolkit/my_snippet.cycpp.h`` - (The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and inform developers that this is not a standard C++ header) + The snippet file, will contain the declaration of all the variables required to use the capabilities class: @@ -72,8 +74,8 @@ have to be done: 2. Add the proper default initialization of the variable required for the snippet. -3. In the ``Archetype::EnterNotify()``, assign the Snippet with value - corresponding to the user input. +3. In the ``Archetype::EnterNotify()``, initialise the toolkit class member + variables with variables. 4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the Archetype operation. @@ -92,3 +94,56 @@ develop to skip the assignation of the value in the inherited class in the Otherwise behavior would be very similar. +Exemple: +======== + +``toolkit/my_snippet.cycpp.h``: +.. highlight:: c + cyclus::toolkit::Position coordinates; + + #pragma cyclus var { \ + "default": 0.0, \ + "uilabel": "Geographical latitude in degrees as a double", \ + "doc": "Latitude of the agent's geographical position. The value should " \ + "be expressed in degrees as a double." } + double latitude; + // required for compilation but not added by the cycpp preprocessor... + std::vector cycpp_shape_latitude; + + #pragma cyclus var { \ + "default": 0.0, \ + "uilabel": "Geographical longitude in degrees as a double", \ + "doc": "Longitude of the agent's geographical position. The value should" \ + "be expressed in degrees as a double." } + double longitude; + // required for compilation but not added by the cycpp preprocessor... + std::vector cycpp_shape_longitude; + + +``my_archetype_example.h``: +.. highlight:: c + class fun_archetype : public cyclus::facility{ + public: + [...] + private: + [...] + #include "toolkit/my_snippet.cycpp.h" + +``my_archetype_example.cpp``: +.. highlight:: c + fun_archetype::fun_archetype(cyclus::Context* ctx): + cyclus::facility(ctx), + var1(0.0), + var2(0.0), + ..., + coordinates(0,0), //coordinates constructor (toolkit feature class) + longitude(0), //snippet variables added with "my_snippet.cycpp.h" + latitude(0) //snippet variables added with "my_snippet.cycpp.h" + {} + [..] + void Storage::EnterNotify() { + coordinates.set_position(latitude, longitude); + coordinates.RecordPosition(this); + [...] + } + From 2f09ba246c63af3be81275e3da64bd5b56ff21d4 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 18 Nov 2019 16:31:22 -0600 Subject: [PATCH 07/19] removing trailing space --- source/cep/cep27.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 8db29276e..dac7a2c2b 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -100,7 +100,7 @@ Exemple: ``toolkit/my_snippet.cycpp.h``: .. highlight:: c cyclus::toolkit::Position coordinates; - + #pragma cyclus var { \ "default": 0.0, \ "uilabel": "Geographical latitude in degrees as a double", \ @@ -131,7 +131,7 @@ Exemple: ``my_archetype_example.cpp``: .. highlight:: c - fun_archetype::fun_archetype(cyclus::Context* ctx): + fun_archetype::fun_archetype(cyclus::Context* ctx): cyclus::facility(ctx), var1(0.0), var2(0.0), From 2e7967870941732c61efa47cdefae8695e11fb97 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Mon, 18 Nov 2019 16:39:23 -0600 Subject: [PATCH 08/19] some text improvement --- source/cep/cep27.rst | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index dac7a2c2b..62867b48b 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -13,13 +13,13 @@ CEP 27 - Agent Toolkit Capabilities Abstract ======== -The |Cyclus| toolkit is designed to easily implement specific capabilities in newly -developed archetypes, such as trading policy, commodity producers... To add -characteristics to archetypes such as Position or Metadata, the actual +The |Cyclus| toolkit is designed to easily implement specific capabilities in +newly developed archetypes, such as trading policy, commodity producers... To +add characteristics to archetypes such as Position or Metadata, the actual implementation method is very verbose, where in each archetypes one needs to add -the new specification in the header, assign it and use it in the cpp file, -with no guarantee on the consistency in the variable naming and implementation -across multiple archetypes. +the new specification in the arcehtype header, then assign it and use it in the +cpp file, with no guarantee on the consistency in the variable naming and +implementation across multiple archetypes. This CEP explains how to use snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. @@ -28,16 +28,16 @@ Toolkit Implementation ====================== Each |Cyclus| toolkit component will contain 3 different files: -- 2 for the definition of the snippet C++ class (``cpp`` and header) that allows +- 2 for the definition of the feature C++ class (``cpp`` and header) that allows the use of the capabilities, and optionally to register its values in the output database, - a snippet definition file used to simplify the implementation and ensure consistency accross its integration in the different archetypes. -The snippet definition file will then be included in the header part of the archetypes -class declaration as: ``#include toolkit/my_snippet.cycpp.h`` -(The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and -inform developers that this is not a standard C++ header) +The snippet definition file will be included in the ``private`` section of the +archetype header as: ``#include toolkit/my_snippet.cycpp.h``. (The use of the +``cycpp.h`` has been chosen to allow syntax highlighting and inform developers +that this is not a standard C++ header.) The snippet file, will contain the declaration of all the variables required to use the capabilities class: @@ -47,10 +47,9 @@ to use the capabilities class: - (optional) if the capability requires/allows variable input from users, standard |Cyclus| member variable declaration with variable ``#pragma`` is required. In addition, to the standard variable declaration and the - ``#pragma`` the method also require a ``std::vector - cycpp_shape_myvariable0`` to be declared for each of the decorated variable. - ``cycpp preprocessor`` is not able at the time to add them automatically for - included files. + ``#pragma`` the method also require a ``std::vector cycpp_shape_myvariable`` + to be declared for each of the decorated variable. (``cycpp preprocessor`` is not able + at the time to add them automatically for included files.) The main purpose of this include method would be to ensure consistency across @@ -58,8 +57,8 @@ archetypes using the same toolkit capability requiring user input, avoiding 1 set of input syntax per archetypes for the same capability. If the toolkit features needs the capabilities to write in the output database a -``RecordSnippet(Agent* agent)`` method will be implemented to avoid -multiplication of implementation in the archetypes. +``RecordSnippet(Agent* agent)`` method will be implemented in the toolkit class to avoid +multiplication of implementation in the each archetype using the feature. Archetypes Integration @@ -68,13 +67,13 @@ Archetypes Integration When the capability is integrated in an Archetype the following implementations have to be done: -1. Include the snippet in the class header core: ``#include - toolkit/my_snippet.cycpp,h``. +1. Include the snippet in the class header core: + ``#include toolkit/my_snippet.cycpp,h``. 2. Add the proper default initialization of the variable required for the snippet. -3. In the ``Archetype::EnterNotify()``, initialise the toolkit class member +3. (optional) In the ``Archetype::EnterNotify()``, initialise the toolkit class member variables with variables. 4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the From 3afaa9208d3d54882fa300718ba38f06dbb83b28 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 26 Nov 2019 09:40:40 -0600 Subject: [PATCH 09/19] upadte tittle --- source/cep/cep27.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 62867b48b..82fd32ae7 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -1,5 +1,5 @@ -CEP 27 - Agent Toolkit Capabilities -*********************************** +CEP 27 - Toolkit Capabilities Injection into an Archetype +********************************************************* :CEP: 27 :Title: Agent Toolkit Capabilities From 26b7515ddf38c2d6c49ae3938508ea6dff924ee1 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Tue, 26 Nov 2019 09:41:13 -0600 Subject: [PATCH 10/19] Apply suggestions from code review Co-Authored-By: Paul Wilson --- source/cep/cep27.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 62867b48b..680df58a6 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -14,11 +14,11 @@ Abstract ======== The |Cyclus| toolkit is designed to easily implement specific capabilities in -newly developed archetypes, such as trading policy, commodity producers... To -add characteristics to archetypes such as Position or Metadata, the actual +newly developed archetypes, such as trading policy, commodity producers. To +add characteristics to archetypes such as `Position` or `Metadata`, the actual implementation method is very verbose, where in each archetypes one needs to add the new specification in the arcehtype header, then assign it and use it in the -cpp file, with no guarantee on the consistency in the variable naming and +cpp file, and the developer must ensure the consistency in the variable naming and implementation across multiple archetypes. This CEP explains how to use snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. @@ -93,7 +93,7 @@ develop to skip the assignation of the value in the inherited class in the Otherwise behavior would be very similar. -Exemple: +Example: ======== ``toolkit/my_snippet.cycpp.h``: @@ -145,4 +145,3 @@ Exemple: coordinates.RecordPosition(this); [...] } - From d0457494b18fe5592ca0e90e00aee290948abdcf Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 26 Nov 2019 09:43:53 -0600 Subject: [PATCH 11/19] add information about where to put the preprocessor additional line --- source/cep/cep27.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index a3571e63e..44237fc6d 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -47,9 +47,10 @@ to use the capabilities class: - (optional) if the capability requires/allows variable input from users, standard |Cyclus| member variable declaration with variable ``#pragma`` is required. In addition, to the standard variable declaration and the - ``#pragma`` the method also require a ``std::vector cycpp_shape_myvariable`` - to be declared for each of the decorated variable. (``cycpp preprocessor`` is not able - at the time to add them automatically for included files.) + ``#pragma`` the method also require a ``std::vector + cycpp_shape_myvariable`` to be declared for each of the decorated variable + that are in the `toolkit/my_snippet.cycpp.h` file. (``cycpp preprocessor`` is + not able at the time to add them automatically for included files.) The main purpose of this include method would be to ensure consistency across From 5d09ded5e498a84c04b623650b5808bd8825d520 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 26 Nov 2019 09:48:48 -0600 Subject: [PATCH 12/19] Add inheritance example --- source/cep/cep27.rst | 53 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 44237fc6d..6d81860b1 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -97,6 +97,9 @@ Otherwise behavior would be very similar. Example: ======== + +Without Inheritance: +-------------------- ``toolkit/my_snippet.cycpp.h``: .. highlight:: c cyclus::toolkit::Position coordinates; @@ -119,7 +122,6 @@ Example: // required for compilation but not added by the cycpp preprocessor... std::vector cycpp_shape_longitude; - ``my_archetype_example.h``: .. highlight:: c class fun_archetype : public cyclus::facility{ @@ -146,3 +148,52 @@ Example: coordinates.RecordPosition(this); [...] } +Wit Inheritance: +-------------------- +``toolkit/my_snippet.cycpp.h``: +.. highlight:: c + #pragma cyclus var { \ + "default": 0.0, \ + "uilabel": "Geographical latitude in degrees as a double", \ + "doc": "Latitude of the agent's geographical position. The value should " \ + "be expressed in degrees as a double." } + double latitude; + // required for compilation but not added by the cycpp preprocessor... + std::vector cycpp_shape_latitude; + + #pragma cyclus var { \ + "default": 0.0, \ + "uilabel": "Geographical longitude in degrees as a double", \ + "doc": "Longitude of the agent's geographical position. The value should" \ + "be expressed in degrees as a double." } + double longitude; + // required for compilation but not added by the cycpp preprocessor... + std::vector cycpp_shape_longitude; + +``my_archetype_example.h``: +.. highlight:: c + class fun_archetype : public cyclus::facility, public Position { + public: + [...] + private: + [...] + #include "toolkit/my_snippet.cycpp.h" + +``my_archetype_example.cpp``: +.. highlight:: c + fun_archetype::fun_archetype(cyclus::Context* ctx): + cyclus::facility(ctx), + var1(0.0), + var2(0.0), + ..., + coordinates(0,0), //coordinates constructor (toolkit feature class) + longitude(0), //snippet variables added with "my_snippet.cycpp.h" + latitude(0), //snippet variables added with "my_snippet.cycpp.h" + Position(0, 0) + {} + [..] + void Storage::EnterNotify() { + this.set_position(latitude, longitude); + this.RecordPosition(this); + [...] + } From 5770f22b4d3cc4e852de5bba6800659a4ebe6fd3 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Tue, 26 Nov 2019 09:52:06 -0600 Subject: [PATCH 13/19] some syntax change --- source/cep/cep27.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 6d81860b1..b2a29f076 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -130,6 +130,7 @@ Without Inheritance: private: [...] #include "toolkit/my_snippet.cycpp.h" + } ``my_archetype_example.cpp``: .. highlight:: c @@ -148,8 +149,9 @@ Without Inheritance: coordinates.RecordPosition(this); [...] } -Wit Inheritance: --------------------- + +With Inheritance: +----------------- ``toolkit/my_snippet.cycpp.h``: .. highlight:: c #pragma cyclus var { \ @@ -178,6 +180,7 @@ Wit Inheritance: private: [...] #include "toolkit/my_snippet.cycpp.h" + } ``my_archetype_example.cpp``: .. highlight:: c From 0507887c6f7163dcd73b696835b59c2024104a49 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Wed, 27 Nov 2019 11:23:20 -0600 Subject: [PATCH 14/19] Apply suggestions from code review Co-Authored-By: Paul Wilson --- source/cep/cep27.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index b2a29f076..c2d2af9b0 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -14,13 +14,13 @@ Abstract ======== The |Cyclus| toolkit is designed to easily implement specific capabilities in -newly developed archetypes, such as trading policy, commodity producers. To +newly developed archetypes, such as a trading policy, commodity producers, etc. To add characteristics to archetypes such as `Position` or `Metadata`, the actual implementation method is very verbose, where in each archetypes one needs to add the new specification in the arcehtype header, then assign it and use it in the cpp file, and the developer must ensure the consistency in the variable naming and implementation across multiple archetypes. -This CEP explains how to use snippets to simplify and maintain consistency +This CEP explains introduces the concept of snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. From d895250fe7e3860e34ace6cc8c78c5f74be94cc7 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 27 Nov 2019 11:45:53 -0600 Subject: [PATCH 15/19] calling default construct should be the default when inheriting --- source/cep/cep27.rst | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index b2a29f076..a628e6fe5 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -44,6 +44,8 @@ to use the capabilities class: - the definition of the capability class as a member variable. +- initialisation of the added variables. + - (optional) if the capability requires/allows variable input from users, standard |Cyclus| member variable declaration with variable ``#pragma`` is required. In addition, to the standard variable declaration and the @@ -71,13 +73,10 @@ have to be done: 1. Include the snippet in the class header core: ``#include toolkit/my_snippet.cycpp,h``. -2. Add the proper default initialization of the variable required for the - snippet. - -3. (optional) In the ``Archetype::EnterNotify()``, initialise the toolkit class member +2. (optional) In the ``Archetype::EnterNotify()``, initialise the toolkit class member variables with variables. -4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the +3. (optional) If required, call the ``RecordSnippet()`` method when necessary during the Archetype operation. @@ -102,14 +101,14 @@ Without Inheritance: -------------------- ``toolkit/my_snippet.cycpp.h``: .. highlight:: c - cyclus::toolkit::Position coordinates; + cyclus::toolkit::Position coordinates(0,0); #pragma cyclus var { \ "default": 0.0, \ "uilabel": "Geographical latitude in degrees as a double", \ "doc": "Latitude of the agent's geographical position. The value should " \ "be expressed in degrees as a double." } - double latitude; + double latitude = 0; // required for compilation but not added by the cycpp preprocessor... std::vector cycpp_shape_latitude; @@ -118,7 +117,7 @@ Without Inheritance: "uilabel": "Geographical longitude in degrees as a double", \ "doc": "Longitude of the agent's geographical position. The value should" \ "be expressed in degrees as a double." } - double longitude; + double longitude = 0; // required for compilation but not added by the cycpp preprocessor... std::vector cycpp_shape_longitude; @@ -134,17 +133,7 @@ Without Inheritance: ``my_archetype_example.cpp``: .. highlight:: c - fun_archetype::fun_archetype(cyclus::Context* ctx): - cyclus::facility(ctx), - var1(0.0), - var2(0.0), - ..., - coordinates(0,0), //coordinates constructor (toolkit feature class) - longitude(0), //snippet variables added with "my_snippet.cycpp.h" - latitude(0) //snippet variables added with "my_snippet.cycpp.h" - {} - [..] - void Storage::EnterNotify() { + void fun_archetype::EnterNotify() { coordinates.set_position(latitude, longitude); coordinates.RecordPosition(this); [...] @@ -159,7 +148,7 @@ With Inheritance: "uilabel": "Geographical latitude in degrees as a double", \ "doc": "Latitude of the agent's geographical position. The value should " \ "be expressed in degrees as a double." } - double latitude; + double latitude = 0; // required for compilation but not added by the cycpp preprocessor... std::vector cycpp_shape_latitude; @@ -168,7 +157,7 @@ With Inheritance: "uilabel": "Geographical longitude in degrees as a double", \ "doc": "Longitude of the agent's geographical position. The value should" \ "be expressed in degrees as a double." } - double longitude; + double longitude = 0; // required for compilation but not added by the cycpp preprocessor... std::vector cycpp_shape_longitude; @@ -184,18 +173,7 @@ With Inheritance: ``my_archetype_example.cpp``: .. highlight:: c - fun_archetype::fun_archetype(cyclus::Context* ctx): - cyclus::facility(ctx), - var1(0.0), - var2(0.0), - ..., - coordinates(0,0), //coordinates constructor (toolkit feature class) - longitude(0), //snippet variables added with "my_snippet.cycpp.h" - latitude(0), //snippet variables added with "my_snippet.cycpp.h" - Position(0, 0) - {} - [..] - void Storage::EnterNotify() { + void fun_archetype::EnterNotify() { this.set_position(latitude, longitude); this.RecordPosition(this); [...] From 7c4c0c402748eae464c47a633efafc42298ea39d Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 27 Nov 2019 17:02:23 -0600 Subject: [PATCH 16/19] simplifying motivation sentences, adding missing include --- source/cep/cep27.rst | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 341823ee7..04d686bb4 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -14,12 +14,12 @@ Abstract ======== The |Cyclus| toolkit is designed to easily implement specific capabilities in -newly developed archetypes, such as a trading policy, commodity producers, etc. To -add characteristics to archetypes such as `Position` or `Metadata`, the actual -implementation method is very verbose, where in each archetypes one needs to add -the new specification in the arcehtype header, then assign it and use it in the -cpp file, and the developer must ensure the consistency in the variable naming and -implementation across multiple archetypes. +newly developed archetypes, such as a trading policy, commodity producers, etc. +To add characteristics to archetypes such as `Position` or `Metadata`, the +actual implementation method is very verbose. It relies on adding the new +specification in the arcehtype header, assignng it and use it in the cpp +file. The developers have to manually ensure the consistency in the variable naming and +implementation across multiple archetypes/files. This CEP explains introduces the concept of snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. @@ -123,7 +123,9 @@ Without Inheritance: ``my_archetype_example.h``: .. highlight:: c - class fun_archetype : public cyclus::facility{ + #include 'toolkit/Position.h' + + class fun_archetype : public cyclus::facility{ public: [...] private: @@ -163,6 +165,8 @@ With Inheritance: ``my_archetype_example.h``: .. highlight:: c + #include 'toolkit/Position.h' + class fun_archetype : public cyclus::facility, public Position { public: [...] From 2b066c2dd0d4984ec253f6ecaf9dedb52ca87489 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot Date: Wed, 27 Nov 2019 17:05:13 -0600 Subject: [PATCH 17/19] adding instruction for toolkit feature header include in arcehtype header, and renameing my_snippet into my_feature_snippet --- source/cep/cep27.rst | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 04d686bb4..5b909a68b 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -35,7 +35,7 @@ Each |Cyclus| toolkit component will contain 3 different files: consistency accross its integration in the different archetypes. The snippet definition file will be included in the ``private`` section of the -archetype header as: ``#include toolkit/my_snippet.cycpp.h``. (The use of the +archetype header as: ``#include toolkit/my_feature_snippet.cycpp.h``. (The use of the ``cycpp.h`` has been chosen to allow syntax highlighting and inform developers that this is not a standard C++ header.) @@ -51,7 +51,7 @@ to use the capabilities class: required. In addition, to the standard variable declaration and the ``#pragma`` the method also require a ``std::vector cycpp_shape_myvariable`` to be declared for each of the decorated variable - that are in the `toolkit/my_snippet.cycpp.h` file. (``cycpp preprocessor`` is + that are in the `toolkit/my_feature_snippet.cycpp.h` file. (``cycpp preprocessor`` is not able at the time to add them automatically for included files.) @@ -70,13 +70,16 @@ Archetypes Integration When the capability is integrated in an Archetype the following implementations have to be done: -1. Include the snippet in the class header core: - ``#include toolkit/my_snippet.cycpp,h``. +1. Include toolkit class header in in the class header: + ``#include 'toolkit/my_feature.h'``. -2. (optional) In the ``Archetype::EnterNotify()``, initialise the toolkit class member +2. Include the snippet in the class header core: + ``#include toolkit/my_feature_snippet.cycpp,h``. + +3. (optional) In the ``Archetype::EnterNotify()``, initialise the toolkit class member variables with variables. -3. (optional) If required, call the ``RecordSnippet()`` method when necessary during the +4. (optional) If required, call the ``RecordSnippet()`` method when necessary during the Archetype operation. @@ -99,7 +102,7 @@ Example: Without Inheritance: -------------------- -``toolkit/my_snippet.cycpp.h``: +``toolkit/my_feature_snippet.cycpp.h``: .. highlight:: c cyclus::toolkit::Position coordinates(0,0); @@ -130,7 +133,7 @@ Without Inheritance: [...] private: [...] - #include "toolkit/my_snippet.cycpp.h" + #include "toolkit/my_feature_snippet.cycpp.h" } ``my_archetype_example.cpp``: @@ -143,7 +146,7 @@ Without Inheritance: With Inheritance: ----------------- -``toolkit/my_snippet.cycpp.h``: +``toolkit/my_feature_snippet.cycpp.h``: .. highlight:: c #pragma cyclus var { \ "default": 0.0, \ @@ -172,7 +175,7 @@ With Inheritance: [...] private: [...] - #include "toolkit/my_snippet.cycpp.h" + #include "toolkit/my_feature_snippet.cycpp.h" } ``my_archetype_example.cpp``: From fdfa326091df075aae9a020da5538e8599f8fc71 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Wed, 27 Nov 2019 17:05:29 -0600 Subject: [PATCH 18/19] Update source/cep/cep27.rst Co-Authored-By: Paul Wilson --- source/cep/cep27.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 5b909a68b..6a8fabf93 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -17,7 +17,7 @@ The |Cyclus| toolkit is designed to easily implement specific capabilities in newly developed archetypes, such as a trading policy, commodity producers, etc. To add characteristics to archetypes such as `Position` or `Metadata`, the actual implementation method is very verbose. It relies on adding the new -specification in the arcehtype header, assignng it and use it in the cpp +specification in the arcehtype header, assigning it and use it in the cpp file. The developers have to manually ensure the consistency in the variable naming and implementation across multiple archetypes/files. This CEP explains introduces the concept of snippets to simplify and maintain consistency From 03f4ca9745a0a174905725e12614c103eb2657cc Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <15145274+bam241@users.noreply.github.com> Date: Mon, 27 Jan 2020 16:33:32 -0600 Subject: [PATCH 19/19] Apply suggestions from code review Co-Authored-By: Katy Huff --- source/cep/cep27.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/cep/cep27.rst b/source/cep/cep27.rst index 6a8fabf93..153d4a21d 100644 --- a/source/cep/cep27.rst +++ b/source/cep/cep27.rst @@ -17,8 +17,8 @@ The |Cyclus| toolkit is designed to easily implement specific capabilities in newly developed archetypes, such as a trading policy, commodity producers, etc. To add characteristics to archetypes such as `Position` or `Metadata`, the actual implementation method is very verbose. It relies on adding the new -specification in the arcehtype header, assigning it and use it in the cpp -file. The developers have to manually ensure the consistency in the variable naming and +specification in the archetype header, assigning it and use it in the cpp +file. The developers have to manually ensure the consistency in variable naming and implementation across multiple archetypes/files. This CEP explains introduces the concept of snippets to simplify and maintain consistency in the implementation and the usage, across multiple archetypes. @@ -44,7 +44,7 @@ to use the capabilities class: - the definition of the capability class as a member variable. -- initialisation of the added variables. +- initialization of the added variables. - (optional) if the capability requires/allows variable input from users, standard |Cyclus| member variable declaration with variable ``#pragma`` is