Skip to content

Commit f0fcc08

Browse files
committed
make iosys_test.py compatible with current source code state
revert this commit when merging into or with python-control#400 and python-control#431
1 parent 411467e commit f0fcc08

1 file changed

Lines changed: 18 additions & 135 deletions

File tree

control/tests/iosys_test.py

Lines changed: 18 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class TSys:
2929
"""Return some test systems"""
3030
# Create a single input/single output linear system
3131
T.siso_linsys = ct.StateSpace(
32-
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[0]])
32+
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[0]], 0)
3333

3434
# Create a multi input/multi output linear system
3535
T.mimo_linsys1 = ct.StateSpace(
3636
[[-1, 1], [0, -2]], [[1, 0], [0, 1]],
37-
[[1, 0], [0, 1]], np.zeros((2, 2)))
37+
[[1, 0], [0, 1]], np.zeros((2, 2)), 0)
3838

3939
# Create a multi input/multi output linear system
4040
T.mimo_linsys2 = ct.StateSpace(
4141
[[-1, 1], [0, -2]], [[0, 1], [1, 0]],
42-
[[1, 0], [0, 1]], np.zeros((2, 2)))
42+
[[1, 0], [0, 1]], np.zeros((2, 2)), 0)
4343

4444
# Create simulation parameters
4545
T.T = np.linspace(0, 10, 100)
@@ -281,7 +281,7 @@ def test_algebraic_loop(self, tsys):
281281
linsys = tsys.siso_linsys
282282
lnios = ios.LinearIOSystem(linsys)
283283
nlios = ios.NonlinearIOSystem(None, \
284-
lambda t, x, u, params: u*u, inputs=1, outputs=1)
284+
lambda t, x, u, params: u*u, inputs=1, outputs=1, dt=0)
285285
nlios1 = nlios.copy()
286286
nlios2 = nlios.copy()
287287

@@ -310,7 +310,7 @@ def test_algebraic_loop(self, tsys):
310310
iosys = ios.InterconnectedSystem(
311311
(lnios, nlios), # linear system w/ nonlinear feedback
312312
((1,), # feedback interconnection (sig to 0)
313-
(0, (1, 0, -1))),
313+
(0, (1, 0, -1))),
314314
0, # input to linear system
315315
0 # output from linear system
316316
)
@@ -331,7 +331,7 @@ def test_algebraic_loop(self, tsys):
331331

332332
# Algebraic loop due to feedthrough term
333333
linsys = ct.StateSpace(
334-
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[1]])
334+
[[-1, 1], [0, -2]], [[0], [1]], [[1, 0]], [[1]], 0)
335335
lnios = ios.LinearIOSystem(linsys)
336336
iosys = ios.InterconnectedSystem(
337337
(nlios, lnios), # linear system w/ nonlinear feedback
@@ -374,7 +374,7 @@ def test_rmul(self, tsys):
374374
# Also creates a nested interconnected system
375375
ioslin = ios.LinearIOSystem(tsys.siso_linsys)
376376
nlios = ios.NonlinearIOSystem(None, \
377-
lambda t, x, u, params: u*u, inputs=1, outputs=1)
377+
lambda t, x, u, params: u*u, inputs=1, outputs=1, dt=0)
378378
sys1 = nlios * ioslin
379379
sys2 = ios.InputOutputSystem.__rmul__(nlios, sys1)
380380

@@ -414,7 +414,7 @@ def test_feedback(self, tsys):
414414
# Linear system with constant feedback (via "nonlinear" mapping)
415415
ioslin = ios.LinearIOSystem(tsys.siso_linsys)
416416
nlios = ios.NonlinearIOSystem(None, \
417-
lambda t, x, u, params: u, inputs=1, outputs=1)
417+
lambda t, x, u, params: u, inputs=1, outputs=1, dt=0)
418418
iosys = ct.feedback(ioslin, nlios)
419419
linsys = ct.feedback(tsys.siso_linsys, 1)
420420

@@ -740,7 +740,7 @@ def test_named_signals(self, tsys):
740740
inputs = ('u[0]', 'u[1]'),
741741
outputs = ('y[0]', 'y[1]'),
742742
states = tsys.mimo_linsys1.states,
743-
name = 'sys1')
743+
name = 'sys1', dt=0)
744744
sys2 = ios.LinearIOSystem(tsys.mimo_linsys2,
745745
inputs = ('u[0]', 'u[1]'),
746746
outputs = ('y[0]', 'y[1]'),
@@ -797,121 +797,6 @@ def test_named_signals(self, tsys):
797797
np.testing.assert_array_almost_equal(ss_feedback.C, lin_feedback.C)
798798
np.testing.assert_array_almost_equal(ss_feedback.D, lin_feedback.D)
799799

800-
def test_sys_naming_convention(self, tsys):
801-
"""Enforce generic system names 'sys[i]' to be present when systems are created
802-
without explicit names."""
803-
804-
ct.InputOutputSystem.idCounter = 0
805-
sys = ct.LinearIOSystem(tsys.mimo_linsys1)
806-
assert sys.name == "sys[0]"
807-
assert sys.copy().name == "copy of sys[0]"
808-
809-
namedsys = ios.NonlinearIOSystem(
810-
updfcn = lambda t, x, u, params: x,
811-
outfcn = lambda t, x, u, params: u,
812-
inputs = ('u[0]', 'u[1]'),
813-
outputs = ('y[0]', 'y[1]'),
814-
states = tsys.mimo_linsys1.states,
815-
name = 'namedsys')
816-
unnamedsys1 = ct.NonlinearIOSystem(
817-
lambda t,x,u,params: x, inputs=2, outputs=2, states=2
818-
)
819-
unnamedsys2 = ct.NonlinearIOSystem(
820-
None, lambda t,x,u,params: u, inputs=2, outputs=2
821-
)
822-
assert unnamedsys2.name == "sys[2]"
823-
824-
# Unnamed/unnamed connections
825-
uu_series = unnamedsys1 * unnamedsys2
826-
uu_parallel = unnamedsys1 + unnamedsys2
827-
u_neg = - unnamedsys1
828-
uu_feedback = unnamedsys2.feedback(unnamedsys1)
829-
uu_dup = unnamedsys1 * unnamedsys1.copy()
830-
uu_hierarchical = uu_series*unnamedsys1
831-
832-
assert uu_series.name == "sys[3]"
833-
assert uu_parallel.name == "sys[4]"
834-
assert u_neg.name == "sys[5]"
835-
assert uu_feedback.name == "sys[6]"
836-
assert uu_dup.name == "sys[7]"
837-
assert uu_hierarchical.name == "sys[8]"
838-
839-
# Unnamed/named connections
840-
un_series = unnamedsys1 * namedsys
841-
un_parallel = unnamedsys1 + namedsys
842-
un_feedback = unnamedsys2.feedback(namedsys)
843-
un_dup = unnamedsys1 * namedsys.copy()
844-
un_hierarchical = uu_series*unnamedsys1
845-
846-
assert un_series.name == "sys[9]"
847-
assert un_parallel.name == "sys[10]"
848-
assert un_feedback.name == "sys[11]"
849-
assert un_dup.name == "sys[12]"
850-
assert un_hierarchical.name == "sys[13]"
851-
852-
# Same system conflict
853-
with pytest.warns(UserWarning):
854-
unnamedsys1 * unnamedsys1
855-
856-
def test_signals_naming_convention(self, tsys):
857-
"""Enforce generic names to be present when systems are created
858-
without explicit signal names:
859-
input: 'u[i]'
860-
state: 'x[i]'
861-
output: 'y[i]'
862-
"""
863-
ct.InputOutputSystem.idCounter = 0
864-
sys = ct.LinearIOSystem(tsys.mimo_linsys1)
865-
for statename in ["x[0]", "x[1]"]:
866-
assert statename in sys.state_index
867-
for inputname in ["u[0]", "u[1]"]:
868-
assert inputname in sys.input_index
869-
for outputname in ["y[0]", "y[1]"]:
870-
assert outputname in sys.output_index
871-
assert len(sys.state_index) == sys.nstates
872-
assert len(sys.input_index) == sys.ninputs
873-
assert len(sys.output_index) == sys.noutputs
874-
875-
namedsys = ios.NonlinearIOSystem(
876-
updfcn = lambda t, x, u, params: x,
877-
outfcn = lambda t, x, u, params: u,
878-
inputs = ('u0'),
879-
outputs = ('y0'),
880-
states = ('x0'),
881-
name = 'namedsys')
882-
unnamedsys = ct.NonlinearIOSystem(
883-
lambda t,x,u,params: x, inputs=1, outputs=1, states=1
884-
)
885-
assert 'u0' in namedsys.input_index
886-
assert 'y0' in namedsys.output_index
887-
assert 'x0' in namedsys.state_index
888-
889-
# Unnamed/named connections
890-
un_series = unnamedsys * namedsys
891-
un_parallel = unnamedsys + namedsys
892-
un_feedback = unnamedsys.feedback(namedsys)
893-
un_dup = unnamedsys * namedsys.copy()
894-
un_hierarchical = un_series*unnamedsys
895-
u_neg = - unnamedsys
896-
897-
assert "sys[1].x[0]" in un_series.state_index
898-
assert "namedsys.x0" in un_series.state_index
899-
assert "sys[1].x[0]" in un_parallel.state_index
900-
assert "namedsys.x0" in un_series.state_index
901-
assert "sys[1].x[0]" in un_feedback.state_index
902-
assert "namedsys.x0" in un_feedback.state_index
903-
assert "sys[1].x[0]" in un_dup.state_index
904-
assert "copy of namedsys.x0" in un_dup.state_index
905-
assert "sys[1].x[0]" in un_hierarchical.state_index
906-
assert "sys[2].sys[1].x[0]" in un_hierarchical.state_index
907-
assert "sys[1].x[0]" in u_neg.state_index
908-
909-
# Same system conflict
910-
with pytest.warns(UserWarning):
911-
same_name_series = unnamedsys * unnamedsys
912-
assert "sys[1].x[0]" in same_name_series.state_index
913-
assert "copy of sys[1].x[0]" in same_name_series.state_index
914-
915800
def test_named_signals_linearize_inconsistent(self, tsys):
916801
"""Mare sure that providing inputs or outputs not consistent with
917802
updfcn or outfcn fail
@@ -1012,9 +897,10 @@ def test_lineariosys_statespace(self, tsys):
1012897

1013898

1014899
def test_duplicates(self, tsys):
1015-
nlios = ios.NonlinearIOSystem(lambda t,x,u,params: x, \
1016-
lambda t, x, u, params: u*u, \
1017-
inputs=1, outputs=1, states=1, name="sys")
900+
nlios = ios.NonlinearIOSystem(lambda t, x, u, params: x,
901+
lambda t, x, u, params: u * u,
902+
inputs=1, outputs=1, states=1,
903+
name="sys", dt=0)
1018904

1019905
# Duplicate objects
1020906
with pytest.warns(UserWarning, match="Duplicate object"):
@@ -1023,20 +909,17 @@ def test_duplicates(self, tsys):
1023909
# Nonduplicate objects
1024910
nlios1 = nlios.copy()
1025911
nlios2 = nlios.copy()
1026-
with pytest.warns(UserWarning, match="copy of sys") as record:
912+
with pytest.warns(UserWarning, match="Duplicate name"):
1027913
ios_series = nlios1 * nlios2
1028914

1029-
assert "copy of sys_1.x[0]" in ios_series.state_index.keys()
1030-
assert "copy of sys.x[0]" in ios_series.state_index.keys()
1031-
1032915
# Duplicate names
1033916
iosys_siso = ct.LinearIOSystem(tsys.siso_linsys)
1034917
nlios1 = ios.NonlinearIOSystem(None,
1035918
lambda t, x, u, params: u * u,
1036-
inputs=1, outputs=1, name="sys")
919+
inputs=1, outputs=1, name="sys", dt=0)
1037920
nlios2 = ios.NonlinearIOSystem(None,
1038921
lambda t, x, u, params: u * u,
1039-
inputs=1, outputs=1, name="sys")
922+
inputs=1, outputs=1, name="sys", dt=0)
1040923

1041924
with pytest.warns(UserWarning, match="Duplicate name"):
1042925
ct.InterconnectedSystem((nlios1, iosys_siso, nlios2),
@@ -1045,10 +928,10 @@ def test_duplicates(self, tsys):
1045928
# Same system, different names => everything should be OK
1046929
nlios1 = ios.NonlinearIOSystem(None,
1047930
lambda t, x, u, params: u * u,
1048-
inputs=1, outputs=1, name="nlios1")
931+
inputs=1, outputs=1, name="nlios1", dt=0)
1049932
nlios2 = ios.NonlinearIOSystem(None,
1050933
lambda t, x, u, params: u * u,
1051-
inputs=1, outputs=1, name="nlios2")
934+
inputs=1, outputs=1, name="nlios2", dt=0)
1052935
with pytest.warns(None) as record:
1053936
ct.InterconnectedSystem((nlios1, iosys_siso, nlios2),
1054937
inputs=0, outputs=0, states=0)

0 commit comments

Comments
 (0)