Skip to content

Commit

Permalink
Enhance config documentation with examples (#950)
Browse files Browse the repository at this point in the history
* Update config documentation

* Add example for set_config_option call

* Update src/ansys/dpf/core/dpf_operator.py

Co-authored-by: JennaPaikowsky <98607744+JennaPaikowsky@users.noreply.github.com>

* update doc string

* Update

* up

---------

Co-authored-by: JennaPaikowsky <98607744+JennaPaikowsky@users.noreply.github.com>
  • Loading branch information
anslpa and JennaPaikowsky authored May 31, 2023
1 parent b5804b7 commit d955fee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/ansys/dpf/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ class Config:
Server with the channel connected to the remote or local instance. The default is
``None``, in which case an attempt is made to use the global server.
Examples
--------
Create an operator configuration, instantiate the operator and
run it with the configuration.
>>> from ansys.dpf import core as dpf
>>> config_add = dpf.Config("add")
>>> config_add.set_work_by_index_option(True)
>>> op = dpf.operators.math.add(config=config_add)
Modify the copy of an operator's configuration and set it as current config
of the operator.
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.math.add()
>>> config_add = op.config
>>> config_add.set_work_by_index_option(True)
>>> op.config = config_add
"""

def __init__(self, operator_name=None, config=None, server=None, spec=None):
Expand Down Expand Up @@ -144,6 +163,18 @@ def set_config_option(self, config_name, config_value):
Value to give to a configuration option.
config_name : str
Name of the configuration option.
Examples
--------
Modify the copy of an operator's configuration and set it as current config
of the operator.
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.math.add()
>>> config_add = op.config
>>> config_add.set_config_option(config_name="work_by_index", config_value=True)
>>> op.config = config_add
"""
return self.__set_config_option__(config_value, config_name)

Expand Down
16 changes: 15 additions & 1 deletion src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,26 @@ def config(self):
"""Copy of the operator's current configuration.
You can modify the copy of the configuration and then use ``operator.config = new_config``
or create an operator with the new configuration as a parameter.
or instantiate an operator with the new configuration as a parameter.
For information on an operator's options, see the documentation for that operator.
Returns
----------
:class:`ansys.dpf.core.config.Config`
Copy of the operator's current configuration.
Examples
--------
Modify the copy of an operator's configuration and set it as current config
of the operator.
>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.math.add()
>>> config_add = op.config
>>> config_add.set_work_by_index_option(True)
>>> op.config = config_add
"""
config = self._api.operator_get_config(self)
return Config(config=config, server=self._server, spec=self._spec)
Expand Down

0 comments on commit d955fee

Please sign in to comment.