Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f363e7b
updated iosys class/factory function documentation + docstring unit t…
murrayrm Dec 16, 2024
5076298
update state space system repr() to include signal/system names
murrayrm Dec 7, 2024
6f7cbfa
update transfer function repr() + signal/system names
murrayrm Dec 7, 2024
4cedb6c
update FRD repr() + copy signal/system names on sampling
murrayrm Dec 7, 2024
b0397e0
add unit tests for consistent systems repr() processing
murrayrm Dec 7, 2024
85772f5
add iosys_repr and set default __repr__ to short form
murrayrm Dec 15, 2024
9897ab2
use NumPy printoptions in LaTeX representations
murrayrm Dec 17, 2024
376c28e
refactor I/O system repr() processing via iosys_repr and _repr_<fmt>
murrayrm Dec 20, 2024
42eaff9
small docstring and comment updates
murrayrm Dec 20, 2024
964c3aa
expanded __str__ for IC systems (subsys list + connection map)
murrayrm Dec 22, 2024
9ca6833
add Parameters to NonlinearIOSystem.__str__() + avoid double empty lines
murrayrm Dec 22, 2024
ea7d3ed
Update split_tf and combine_tf docstrings + combine_tf kwargs
murrayrm Dec 28, 2024
1434540
add repr_gallery + update formatting for style and consistency
murrayrm Dec 31, 2024
b083212
add context manager functionality to config.defaults
murrayrm Dec 31, 2024
8402605
update latex processing + repr_gallery.ipynb
murrayrm Dec 31, 2024
7863690
update unit tests + tweak formatting for consistency
murrayrm Dec 31, 2024
e0a612f
change default repr to 'eval' + adjust HTML formatting
murrayrm Dec 31, 2024
5ae33b0
add iosys.repr_show_count and defualt to True
murrayrm Jan 4, 2025
32f65d6
add params to sys_nl in repr_gallery; fix combine/split_tf outputs
murrayrm Jan 4, 2025
41d92d3
address @murrayrm and preliminary @slivingston review comments
murrayrm Jan 8, 2025
0f0fad0
address final (?) @slivingston comments
murrayrm Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add context manager functionality to config.defaults
  • Loading branch information
murrayrm committed Jan 13, 2025
commit b08321268accf6daf50cee22b23934e2bb1b8b51
22 changes: 22 additions & 0 deletions control/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ def _check_deprecation(self, key):
else:
return key

#
# Context manager functionality
#

def __call__(self, mapping):
self.saved_mapping = dict()
self.temp_mapping = mapping.copy()
return self

def __enter__(self):
for key, val in self.temp_mapping.items():
if not key in self:
raise ValueError(f"unknown parameter '{key}'")
self.saved_mapping[key] = self[key]
self[key] = val
return self

def __exit__(self, exc_type, exc_val, exc_tb):
for key, val in self.saved_mapping.items():
self[key] = val
del self.saved_mapping, self.temp_mapping
return None

defaults = DefaultDict(_control_defaults)

Expand Down
17 changes: 17 additions & 0 deletions control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,20 @@ def test_legacy_repr_format(self):
new = eval(repr(sys))
for attr in ['A', 'B', 'C', 'D']:
assert getattr(sys, attr) == getattr(sys, attr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert getattr(sys, attr) == getattr(sys, attr)
assert getattr(sys, attr) == getattr(new, attr)



def test_config_context_manager():
# Make sure we can temporarily set the value of a parameter
default_val = ct.config.defaults['statesp.latex_repr_type']
with ct.config.defaults({'statesp.latex_repr_type': 'new value'}):
assert ct.config.defaults['statesp.latex_repr_type'] != default_val
assert ct.config.defaults['statesp.latex_repr_type'] == 'new value'
assert ct.config.defaults['statesp.latex_repr_type'] == default_val

# OK to call the context manager and not do anything with it
ct.config.defaults({'statesp.latex_repr_type': 'new value'})
assert ct.config.defaults['statesp.latex_repr_type'] == default_val

with pytest.raises(ValueError, match="unknown parameter 'unknown'"):
with ct.config.defaults({'unknown': 'new value'}):
pass