1111import os
1212import re
1313from typing import Any , Optional
14- import warnings
1514import xml .etree .ElementTree as ET
1615
1716import numpy as np
@@ -740,56 +739,13 @@ def simulate(
740739
741740 @staticmethod
742741 def _prepare_input_data (
743- input_args : Any ,
744742 input_kwargs : dict [str , Any ],
745743 ) -> dict [str , str ]:
746744 """
747745 Convert raw input to a structured dictionary {'key1': 'value1', 'key2': 'value2'}.
748746 """
749-
750- def prepare_str (str_in : str ) -> dict [str , str ]:
751- str_in = str_in .replace (" " , "" )
752- key_val_list : list [str ] = str_in .split ("=" )
753- if len (key_val_list ) != 2 :
754- raise ModelicaSystemError (f"Invalid 'key=value' pair: { str_in } " )
755- if len (key_val_list [0 ]) == 0 :
756- raise ModelicaSystemError (f"Empty key: { str_in } " )
757-
758- input_data_from_str : dict [str , str ] = {str (key_val_list [0 ]): str (key_val_list [1 ])}
759-
760- return input_data_from_str
761-
762747 input_data : dict [str , str ] = {}
763748
764- for input_arg in input_args :
765- if isinstance (input_arg , str ):
766- warnings .warn (message = "The definition of values to set should use a dictionary, "
767- "i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
768- "use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]" ,
769- category = DeprecationWarning ,
770- stacklevel = 3 )
771- input_data = input_data | prepare_str (input_arg )
772- elif isinstance (input_arg , list ):
773- warnings .warn (message = "The definition of values to set should use a dictionary, "
774- "i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
775- "use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]" ,
776- category = DeprecationWarning ,
777- stacklevel = 3 )
778-
779- for item in input_arg :
780- if not isinstance (item , str ):
781- raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (item )} !" )
782- input_data = input_data | prepare_str (item )
783- elif isinstance (input_arg , dict ):
784- input_arg_str : dict [str , str ] = {}
785- for key , val in input_arg .items ():
786- if not isinstance (key , str ) or len (key ) == 0 :
787- raise ModelicaSystemError (f"Invalid key for set*() functions: { repr (key )} " )
788- input_arg_str [key ] = str (val )
789- input_data = input_data | input_arg_str
790- else :
791- raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (input_arg )} !" )
792-
793749 if len (input_kwargs ):
794750 for key , val in input_kwargs .items ():
795751 # ensure all values are strings to align it on one type: dict[str, str]
@@ -867,21 +823,17 @@ def isParameterChangeable(
867823
868824 def setContinuous (
869825 self ,
870- * args : Any ,
871826 ** kwargs : dict [str , Any ],
872827 ) -> bool :
873828 """
874- This method is used to set continuous values. It can be called:
875- with a sequence of continuous name and assigning corresponding values as arguments as show in the example below:
876- usage
877- >>> setContinuous("Name=value") # depreciated
878- >>> setContinuous(["Name1=value1","Name2=value2"]) # depreciated
829+ This method is used to set continuous values.
879830
831+ usage:
880832 >>> setContinuous(Name1="value1", Name2="value2")
881833 >>> param = {"Name1": "value1", "Name2": "value2"}
882834 >>> setContinuous(**param)
883835 """
884- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
836+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
885837
886838 return self ._set_method_helper (
887839 inputdata = inputdata ,
@@ -891,21 +843,17 @@ def setContinuous(
891843
892844 def setParameters (
893845 self ,
894- * args : Any ,
895846 ** kwargs : dict [str , Any ],
896847 ) -> bool :
897848 """
898- This method is used to set parameter values. It can be called:
899- with a sequence of parameter name and assigning corresponding value as arguments as show in the example below:
900- usage
901- >>> setParameters("Name=value") # depreciated
902- >>> setParameters(["Name1=value1","Name2=value2"]) # depreciated
849+ This method is used to set parameter values
903850
851+ usage:
904852 >>> setParameters(Name1="value1", Name2="value2")
905853 >>> param = {"Name1": "value1", "Name2": "value2"}
906854 >>> setParameters(**param)
907855 """
908- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
856+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
909857
910858 return self ._set_method_helper (
911859 inputdata = inputdata ,
@@ -915,22 +863,17 @@ def setParameters(
915863
916864 def setSimulationOptions (
917865 self ,
918- * args : Any ,
919866 ** kwargs : dict [str , Any ],
920867 ) -> bool :
921868 """
922- This method is used to set simulation options. It can be called:
923- with a sequence of simulation options name and assigning corresponding values as arguments as show in the
924- example below:
925- usage
926- >>> setSimulationOptions("Name=value") # depreciated
927- >>> setSimulationOptions(["Name1=value1","Name2=value2"]) # depreciated
869+ This method is used to set simulation options.
928870
871+ usage:
929872 >>> setSimulationOptions(Name1="value1", Name2="value2")
930873 >>> param = {"Name1": "value1", "Name2": "value2"}
931874 >>> setSimulationOptions(**param)
932875 """
933- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
876+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
934877
935878 return self ._set_method_helper (
936879 inputdata = inputdata ,
@@ -940,22 +883,17 @@ def setSimulationOptions(
940883
941884 def setLinearizationOptions (
942885 self ,
943- * args : Any ,
944886 ** kwargs : dict [str , Any ],
945887 ) -> bool :
946888 """
947- This method is used to set linearization options. It can be called:
948- with a sequence of linearization options name and assigning corresponding value as arguments as show in the
949- example below
950- usage
951- >>> setLinearizationOptions("Name=value") # depreciated
952- >>> setLinearizationOptions(["Name1=value1","Name2=value2"]) # depreciated
889+ This method is used to set linearization options.
953890
891+ usage:
954892 >>> setLinearizationOptions(Name1="value1", Name2="value2")
955893 >>> param = {"Name1": "value1", "Name2": "value2"}
956894 >>> setLinearizationOptions(**param)
957895 """
958- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
896+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
959897
960898 return self ._set_method_helper (
961899 inputdata = inputdata ,
@@ -965,22 +903,17 @@ def setLinearizationOptions(
965903
966904 def setOptimizationOptions (
967905 self ,
968- * args : Any ,
969906 ** kwargs : dict [str , Any ],
970907 ) -> bool :
971908 """
972- This method is used to set optimization options. It can be called:
973- with a sequence of optimization options name and assigning corresponding values as arguments as show in the
974- example below:
975- usage
976- >>> setOptimizationOptions("Name=value") # depreciated
977- >>> setOptimizationOptions(["Name1=value1","Name2=value2"]) # depreciated
909+ This method is used to set optimization options.
978910
911+ usage:
979912 >>> setOptimizationOptions(Name1="value1", Name2="value2")
980913 >>> param = {"Name1": "value1", "Name2": "value2"}
981914 >>> setOptimizationOptions(**param)
982915 """
983- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
916+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
984917
985918 return self ._set_method_helper (
986919 inputdata = inputdata ,
@@ -994,19 +927,17 @@ def setInputs(
994927 ** kwargs : dict [str , Any ],
995928 ) -> bool :
996929 """
997- This method is used to set input values. It can be called with a sequence of input name and assigning
998- corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
999- special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
1000- and restored here via ast.literal_eval().
930+ This method is used to set input values.
1001931
1002- >>> setInputs("Name=value") # depreciated
1003- >>> setInputs(["Name1=value1","Name2=value2"]) # depreciated
932+ Compared to other set*() methods this is a special case as value could be a list of tuples - these are
933+ converted to a string in _prepare_input_data() and restored here via ast.literal_eval().
1004934
935+ usage:
1005936 >>> setInputs(Name1="value1", Name2="value2")
1006937 >>> param = {"Name1": "value1", "Name2": "value2"}
1007938 >>> setInputs(**param)
1008939 """
1009- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
940+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
1010941
1011942 for key , val in inputdata .items ():
1012943 if key not in self ._inputs :
0 commit comments