Skip to content

Commit

Permalink
Merge pull request #231 from bessagroup/november-9th
Browse files Browse the repository at this point in the history
November-9th
  • Loading branch information
mpvanderschelling committed Nov 9, 2023
2 parents a474d15 + a7b8d84 commit 7ef3b54
Show file tree
Hide file tree
Showing 34 changed files with 975 additions and 830 deletions.
2 changes: 1 addition & 1 deletion docs/source/_templates/custom-class-template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
{% endif %}
{% endblock %}

.. rubric:: {{ _('Methods') }}
.. rubric:: {{ _('Public and private methods') }}
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('../../src'))
src_dir = [f.path for f in os.scandir(os.path.abspath('../../src/')) if f.is_dir()]
src_dir = [f.path for f in os.scandir(
os.path.abspath('../../src/')) if f.is_dir()]
for path in src_dir:
sys.path.insert(0, path)

Expand Down Expand Up @@ -82,7 +83,7 @@
# napoleon: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True
napoleon_include_private_with_doc = False
napoleon_include_private_with_doc = True

# autosummary: https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html#module-sphinx.ext.autosummary
autosummary_generate = True
Expand Down
119 changes: 62 additions & 57 deletions docs/source/rst_doc_files/classes/design/domain.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
Domain and parameters
=====================

This section will give you information on how to set up your search space with the :ref:`domain <domain>` class and the :ref:`parameter classes <parameters>`
This section will give you information on how to set up your search space with the :ref:`domain <domain>` class and the :ref:`parameters <parameters>`


Domain
------

.. _domain:

The :class:`~f3dasm.design.Domain` is a set of :class:`f3dasm.design.Parameter` instances that make up the feasible search space.

.. image:: ../../../img/f3dasm-domain.png
:width: 100%
:align: center
:alt: Domain

|

To start, we instantiate an empty domain object:

.. code-block:: python
from f3dasm import Domain
domain = Domain()
Now we can gradually add some parameters!

.. _parameters:

Expand All @@ -17,107 +44,85 @@ Parameters are singular features of the input search space. They are used to def

|
There are four types of parameters that can be created: :class:`~f3dasm.design.ContinuousParameter`, :class:`~f3dasm.design.DiscreteParameter`, :class:`~f3dasm.design.CategoricalParameter` and :class:`~f3dasm.design.ConstantParameter`:

Continuous Parameter
^^^^^^^^^^^^^^^^^^^^

* We can create **continous** parameters with a :attr:`~f3dasm.design.ContinuousParameter.lower_bound` and :attr:`~f3dasm.design.ContinuousParameter.upper_bound` with the :class:`~f3dasm.design.ContinuousParameter` class
There are four types of parameters that can be created: :ref:`float <continuous-parameter>`, :ref:`int <discrete-parameter>`, :ref:`categorical <categorical-parameter>` and :ref:`constant <constant-parameter>` parameters.

.. code-block:: python
x1 = f3dasm.ContinuousParameter(lower_bound=0.0, upper_bound=100.0)
x2 = f3dasm.ContinuousParameter(lower_bound=0.0, upper_bound=4.0)
.. _continuous-parameter:

Discrete Parameter
^^^^^^^^^^^^^^^^^^
Floating point parameters
^^^^^^^^^^^^^^^^^^^^^^^^^

* We can create **discrete** parameters with a :attr:`~f3dasm.design.DiscreteParameter.lower_bound` and :attr:`~f3dasm.design.DiscreteParameter.upper_bound` with the :class:`~f3dasm.design.DiscreteParameter` class
* We can create **continous** parameters with a :code:`low` and :code:`high` boundary with the :meth:`~f3dasm.design.Domain.add_float` method:

.. code-block:: python
x3 = f3dasm.DiscreteParameter(lower_bound=2, upper_bound=4)
x4 = f3dasm.DiscreteParameter(lower_bound=74, upper_bound=99)
domain.add_float(name='x1', low=0.0, high=100.0)
domain.add_float(name='x2', low=0.0, high=4.0)
Categorical Parameter
^^^^^^^^^^^^^^^^^^^^^
.. _discrete-parameter:

* We can create **categorical** parameters with a list of items (:attr:`~f3dasm.design.CategoricalParameter.categories`) with the :class:`~f3dasm.design.CategoricalParameter` class
Discrete parameters
^^^^^^^^^^^^^^^^^^^

.. code-block:: python
x5 = f3dasm.CategoricalParameter(categories=['test1','test2','test3','test4'])
x6 = f3dasm.CategoricalParameter(categories=[0.9, 0.2, 0.1, -2])
Constant Parameter
^^^^^^^^^^^^^^^^^^

* We can create **constant** parameters with any value (:attr:`~f3dasm.design.ConstantParameter.value`) with the :class:`~f3dasm.design.ConstantParameter` class
* We can create **discrete** parameters with a :code:`low` and :code:`high` boundary with the :meth:`~f3dasm.design.Domain.add_int` method:

.. code-block:: python
x7 = f3dasm.ConstantParameter(value=0.9)
domain.add_int(name='x3', low=2, high=4)
domain.add_int(name='x4', low=74, high=99)
.. _categorical-parameter:

Domain
------
Categorical parameters
^^^^^^^^^^^^^^^^^^^^^^

.. _domain:
* We can create **categorical** parameters with a list of items (:code:`categories`) with the :meth:`~f3dasm.design.Domain.add_category` method:

The :class:`~f3dasm.design.Domain` is a set of :class:`f3dasm.design.Parameter` instances that make up the feasible search space.
.. code-block:: python
.. image:: ../../../img/f3dasm-domain.png
:width: 100%
:align: center
:alt: Domain
domain.add_category(name='x5', categories=['test1','test2','test3','test4'])
domain.add_category(name='x6', categories=[0.9, 0.2, 0.1, -2])
|
.. _constant-parameter:

Domain from a dictionary
^^^^^^^^^^^^^^^^^^^^^^^^
Constant parameters
^^^^^^^^^^^^^^^^^^^

The domain can be constructed by initializing the :class:`~f3dasm.design.Domain` class and
providing an attribute (:attr:`~f3dasm.design.Domain.input_space`) containing string names as keys and parameters as values.
* We can create **constant** parameters with any value (:code:`value`) with the :meth:`~f3dasm.design.Domain.add_constant` method:

.. code-block:: python
from f3dasm import Domain, ContinuousParameter, DiscreteParameter, CategoricalParameter, ConstantParameter
param_1 = f3dasm.ContinuousParameter(lower_bound=-1.0, upper_bound=1.0)
param_2 = f3dasm.DiscreteParameter(lower_bound=1, upper_bound=10)
param_3 = f3dasm.CategoricalParameter(categories=['red', 'blue', 'green', 'yellow', 'purple'])
param_4 = f3dasm.ConstantParameter(value='some_value')
domain = f3dasm.Domain(input_space={'param_1': param_1, 'param_2': param_2, 'param_3': param_3, 'param_4': param_4})
domain.add_constant(name='x7', value=0.9)
.. _domain-from-yaml:

Domain from a `hydra <https://hydra.cc/>`_ configuration file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------

If you are using `hydra <https://hydra.cc/>`_ to manage your configuration files, you can create a domain from a configuration file. Your config needs to have the following key:
If you are using `hydra <https://hydra.cc/>`_ to manage your configuration files, you can create a domain from a configuration file.
Your config needs to have a key (e.g. :code:`domain`) that has a dictionary with the parameter names (e.g. :code:`param_1`) as keys
and a dictionary with the parameter type (:code:`type`) and the corresponding arguments as values:

.. code-block:: yaml
:caption: config.yaml
domain:
param_1:
_target_: f3dasm.ContinuousParameter
type: float
lower_bound: -1.0
upper_bound: 1.0
param_2:
_target_: f3dasm.DiscreteParameter
type: int
lower_bound: 1
upper_bound: 10
param_3:
_target_: f3dasm.CategoricalParameter
type: category
categories: ['red', 'blue', 'green', 'yellow', 'purple']
param_4:
_target_: f3dasm.ConstantParameter
type: constant
value: some_value
The same domain can now be created by calling the :func:`~f3dasm.design.Domain.from_yaml` method:
The domain can now be created by calling the :func:`~f3dasm.design.Domain.from_yaml` method:

.. code-block:: python
Expand Down
2 changes: 0 additions & 2 deletions docs/source/rst_doc_files/classes/optimization/optimizers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ Next, we have to create initial samples. We can use the Latin-hypercube sampler

.. code-block:: python
from f3dasm.sampling import LatinHypercube
data.from_sampling(sampler='latin', domain=domain, n_samples=10, seed=42)
We will use the ``"L-BFGS-B"`` optimizer to find the minimum. For built-in optimizer we can use the name of the optimizer:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/rst_doc_files/classes/workflow/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ main.py

The `main.py` file is the main entry point of the project. It contains the :mod:`f3dasm` classes and acts on these interfaces.
It imports :mod:`f3dasm` and the `my_function` from `my_script.py`.
In the main function, we create the :class:`~f3dasm.design.domain.Domain`, sample from the :class:`~f3dasm.sampling.latinhypercube.LatinHypercube` sampler , and executes the data generation function (`my_function`) using the :meth:`~f3dasm.design.experimentdata.Experiment.evaluate` method with the specified execution mode.
In the main function, we create the :class:`~f3dasm.design.domain.Domain`, sample from the Latin Hypercube sampler , and executes the data generation function (`my_function`) using the :meth:`~f3dasm.design.experimentdata.Experiment.evaluate` method with the specified execution mode.

Additionally, the `main.py` file handles which node takes which role.

Expand Down
15 changes: 7 additions & 8 deletions docs/source/rst_doc_files/classes/workflow/hydra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ You can create configurations for each of the :mod:`f3dasm` classes:
Class Section referencing how to create the `hydra`_ config
============================================================= ======================================================
:class:`~f3dasm.design.domain.Domain` :ref:`domain-from-yaml`
:class:`~f3dasm.sampling.Sampler` :ref:`sampler-hydra`
:class:`~f3dasm.design.experimentdata.ExperimentData` :ref:`experimentdata-hydra`
:class:`~f3dasm.optimization.optimizer.Optimizer` to be implemented!
:class:`~f3dasm.datageneration.datagenerator.DataGenerator` to be implemented!
Expand All @@ -74,13 +73,13 @@ Class Section referencin
domain:
x0:
_target_: f3dasm.ContinuousParameter
lower_bound: 0.0
upper_bound: 1.0
type: float
low: 0.0
high: 1.0
x1:
_target_: f3dasm.ContinuousParameter
lower_bound: 0.0
upper_bound: 1.0
type: float
low: 0.0
high: 1.0
experimentdata:
from_sampling:
Expand All @@ -105,7 +104,7 @@ The `main.py` file is the main entry point of the project.

* It imports the necessary modules (`f3dasm`, `hydra`) and the `my_function` from `my_script.py`.
* Inside `main.py` script defines a :code:`main` function decorated with :code:`@hydra.main`, which reads the configuration from :code:`config.yaml`.
* Within the :code:`main` function, we instantiate the :class:`~f3dasm.design.domain.Domain`, sample from the :class:`~f3dasm.sampling.latinhypercube.LatinHypercube` sampler , and executes the data generation function (`my_function`) using the :meth:`~f3dasm.design.experimentdata.Experiment.run` method with the specified execution mode.
* Within the :code:`main` function, we instantiate the :class:`~f3dasm.design.domain.Domain`, sample from the Lating Hypercube sampler , and executes the data generation function (`my_function`) using the :meth:`~f3dasm.design.experimentdata.Experiment.run` method with the specified execution mode.



Expand Down
18 changes: 1 addition & 17 deletions src/f3dasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
from ._src import _imports as _imports
from ._src._argparser import HPC_JOBID
from ._src._imports import try_import
from ._src.design.domain import Domain, make_nd_continuous_domain
from ._src.design.parameter import (CategoricalParameter, ConstantParameter,
ContinuousParameter, DiscreteParameter)
from ._src.experimentdata.experimentdata import ExperimentData
from ._src.experimentdata.experimentsample import ExperimentSample
from ._src.logger import DistributedFileHandler, logger
from ._src.optimization.optimizer import Optimizer
from ._src.run_optimization import (OptimizationResult, calculate_mean_std,
run_multiple_realizations,
run_optimization)
Expand All @@ -47,28 +43,16 @@
__all__ = [
'datageneration',
'design',
'machinelearning',
'optimization',
'sampling',
'Domain',
'make_nd_continuous_domain',
'ExperimentData',
'CategoricalParameter',
'ConstantParameter',
'ContinuousParameter',
'DiscreteParameter',
'ExperimentSample',
'DistributedFileHandler',
'logger',
'Optimizer',
'run_on_experimentdata',
'run_operation_on_experiments',
'OptimizationResult',
'run_multiple_realizations',
'run_multiple_realizations_to_disk',
'run_optimization',
'run_optimization_to_disk',
'Sampler',
'ExperimentSample',
'HPC_JOBID',
'try_import',
'calculate_mean_std',
Expand Down
4 changes: 2 additions & 2 deletions src/f3dasm/_src/datageneration/abaqus/abaqus_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, name: str = "job", num_cpus: int = 1,
Set true if you want to delete the temporary files after
post-processing, by default True
Notes
-----
Note
----
The kwargs are saved as attributes to the class. This is useful for the
simulation script to access the parameters.
"""
Expand Down
Loading

0 comments on commit 7ef3b54

Please sign in to comment.