Skip to content

Commit e8784db

Browse files
committed
add dry_run docstring
1 parent 876506f commit e8784db

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/pymgrid/utils/dry_run.py

+25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88

99
@contextmanager
1010
def dry_run(pymgrid_object: Union['pymgrid.Microgrid', 'pymgrid.modules.base.BaseMicrogridModule']):
11+
"""
12+
A context manager to test modifications of a pymgrid object without modifying said object.
13+
14+
Parameters
15+
----------
16+
pymgrid_object : :class:`pymgrid.Microgrid` or :class:`pymgrid.modules.base.BaseMicrogridModule`
17+
Microgrid or module to try run
18+
19+
Returns
20+
-------
21+
test_object : copy of object to test usage of, without modifying original object.
22+
23+
Examples
24+
--------
25+
>>> from pymgrid.modules import BatteryModule
26+
>>> module = BatteryModule(0, 100, 50, 50, 0.9, init_soc=0.5)
27+
>>> with dry_run(module) as test_module:
28+
>>> test_module.step(test_module.max_act, normalized=False)
29+
>>> print(f'Current step: {test_module.current_step}; current charge: {test_module.current_charge}')
30+
Current step: 1; current charge: 0.0
31+
>>> print(f'Current step: {module.current_step}; current charge: {module.current_charge}')
32+
Current step: 0; current charge: 50.0
33+
34+
"""
35+
1136
serialized = yaml.safe_dump(pymgrid_object)
1237

1338
try:

0 commit comments

Comments
 (0)