1111import os
1212import re
1313from typing import Any , Optional
14- import warnings
1514import xml .etree .ElementTree as ET
1615
1716import numpy as np
@@ -759,56 +758,13 @@ def simulate(
759758
760759 @staticmethod
761760 def _prepare_input_data (
762- input_args : Any ,
763761 input_kwargs : dict [str , Any ],
764762 ) -> dict [str , str ]:
765763 """
766764 Convert raw input to a structured dictionary {'key1': 'value1', 'key2': 'value2'}.
767765 """
768-
769- def prepare_str (str_in : str ) -> dict [str , str ]:
770- str_in = str_in .replace (" " , "" )
771- key_val_list : list [str ] = str_in .split ("=" )
772- if len (key_val_list ) != 2 :
773- raise ModelicaSystemError (f"Invalid 'key=value' pair: { str_in } " )
774- if len (key_val_list [0 ]) == 0 :
775- raise ModelicaSystemError (f"Empty key: { str_in } " )
776-
777- input_data_from_str : dict [str , str ] = {str (key_val_list [0 ]): str (key_val_list [1 ])}
778-
779- return input_data_from_str
780-
781766 input_data : dict [str , str ] = {}
782767
783- for input_arg in input_args :
784- if isinstance (input_arg , str ):
785- warnings .warn (message = "The definition of values to set should use a dictionary, "
786- "i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
787- "use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]" ,
788- category = DeprecationWarning ,
789- stacklevel = 3 )
790- input_data = input_data | prepare_str (input_arg )
791- elif isinstance (input_arg , list ):
792- warnings .warn (message = "The definition of values to set should use a dictionary, "
793- "i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
794- "use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]" ,
795- category = DeprecationWarning ,
796- stacklevel = 3 )
797-
798- for item in input_arg :
799- if not isinstance (item , str ):
800- raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (item )} !" )
801- input_data = input_data | prepare_str (item )
802- elif isinstance (input_arg , dict ):
803- input_arg_str : dict [str , str ] = {}
804- for key , val in input_arg .items ():
805- if not isinstance (key , str ) or len (key ) == 0 :
806- raise ModelicaSystemError (f"Invalid key for set*() functions: { repr (key )} " )
807- input_arg_str [key ] = str (val )
808- input_data = input_data | input_arg_str
809- else :
810- raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (input_arg )} !" )
811-
812768 if len (input_kwargs ):
813769 for key , val in input_kwargs .items ():
814770 # ensure all values are strings to align it on one type: dict[str, str]
@@ -886,21 +842,17 @@ def isParameterChangeable(
886842
887843 def setContinuous (
888844 self ,
889- * args : Any ,
890845 ** kwargs : dict [str , Any ],
891846 ) -> bool :
892847 """
893- This method is used to set continuous values. It can be called:
894- with a sequence of continuous name and assigning corresponding values as arguments as show in the example below:
895- usage
896- >>> setContinuous("Name=value") # depreciated
897- >>> setContinuous(["Name1=value1","Name2=value2"]) # depreciated
848+ This method is used to set continuous values.
898849
850+ usage:
899851 >>> setContinuous(Name1="value1", Name2="value2")
900852 >>> param = {"Name1": "value1", "Name2": "value2"}
901853 >>> setContinuous(**param)
902854 """
903- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
855+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
904856
905857 return self ._set_method_helper (
906858 inputdata = inputdata ,
@@ -910,21 +862,17 @@ def setContinuous(
910862
911863 def setParameters (
912864 self ,
913- * args : Any ,
914865 ** kwargs : dict [str , Any ],
915866 ) -> bool :
916867 """
917- This method is used to set parameter values. It can be called:
918- with a sequence of parameter name and assigning corresponding value as arguments as show in the example below:
919- usage
920- >>> setParameters("Name=value") # depreciated
921- >>> setParameters(["Name1=value1","Name2=value2"]) # depreciated
868+ This method is used to set parameter values
922869
870+ usage:
923871 >>> setParameters(Name1="value1", Name2="value2")
924872 >>> param = {"Name1": "value1", "Name2": "value2"}
925873 >>> setParameters(**param)
926874 """
927- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
875+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
928876
929877 return self ._set_method_helper (
930878 inputdata = inputdata ,
@@ -934,22 +882,17 @@ def setParameters(
934882
935883 def setSimulationOptions (
936884 self ,
937- * args : Any ,
938885 ** kwargs : dict [str , Any ],
939886 ) -> bool :
940887 """
941- This method is used to set simulation options. It can be called:
942- with a sequence of simulation options name and assigning corresponding values as arguments as show in the
943- example below:
944- usage
945- >>> setSimulationOptions("Name=value") # depreciated
946- >>> setSimulationOptions(["Name1=value1","Name2=value2"]) # depreciated
888+ This method is used to set simulation options.
947889
890+ usage:
948891 >>> setSimulationOptions(Name1="value1", Name2="value2")
949892 >>> param = {"Name1": "value1", "Name2": "value2"}
950893 >>> setSimulationOptions(**param)
951894 """
952- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
895+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
953896
954897 return self ._set_method_helper (
955898 inputdata = inputdata ,
@@ -959,22 +902,17 @@ def setSimulationOptions(
959902
960903 def setLinearizationOptions (
961904 self ,
962- * args : Any ,
963905 ** kwargs : dict [str , Any ],
964906 ) -> bool :
965907 """
966- This method is used to set linearization options. It can be called:
967- with a sequence of linearization options name and assigning corresponding value as arguments as show in the
968- example below
969- usage
970- >>> setLinearizationOptions("Name=value") # depreciated
971- >>> setLinearizationOptions(["Name1=value1","Name2=value2"]) # depreciated
908+ This method is used to set linearization options.
972909
910+ usage:
973911 >>> setLinearizationOptions(Name1="value1", Name2="value2")
974912 >>> param = {"Name1": "value1", "Name2": "value2"}
975913 >>> setLinearizationOptions(**param)
976914 """
977- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
915+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
978916
979917 return self ._set_method_helper (
980918 inputdata = inputdata ,
@@ -984,22 +922,17 @@ def setLinearizationOptions(
984922
985923 def setOptimizationOptions (
986924 self ,
987- * args : Any ,
988925 ** kwargs : dict [str , Any ],
989926 ) -> bool :
990927 """
991- This method is used to set optimization options. It can be called:
992- with a sequence of optimization options name and assigning corresponding values as arguments as show in the
993- example below:
994- usage
995- >>> setOptimizationOptions("Name=value") # depreciated
996- >>> setOptimizationOptions(["Name1=value1","Name2=value2"]) # depreciated
928+ This method is used to set optimization options.
997929
930+ usage:
998931 >>> setOptimizationOptions(Name1="value1", Name2="value2")
999932 >>> param = {"Name1": "value1", "Name2": "value2"}
1000933 >>> setOptimizationOptions(**param)
1001934 """
1002- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
935+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
1003936
1004937 return self ._set_method_helper (
1005938 inputdata = inputdata ,
@@ -1013,19 +946,17 @@ def setInputs(
1013946 ** kwargs : dict [str , Any ],
1014947 ) -> bool :
1015948 """
1016- This method is used to set input values. It can be called with a sequence of input name and assigning
1017- corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
1018- special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
1019- and restored here via ast.literal_eval().
949+ This method is used to set input values.
1020950
1021- >>> setInputs("Name=value") # depreciated
1022- >>> setInputs(["Name1=value1","Name2=value2"]) # depreciated
951+ Compared to other set*() methods this is a special case as value could be a list of tuples - these are
952+ converted to a string in _prepare_input_data() and restored here via ast.literal_eval().
1023953
954+ usage:
1024955 >>> setInputs(Name1="value1", Name2="value2")
1025956 >>> param = {"Name1": "value1", "Name2": "value2"}
1026957 >>> setInputs(**param)
1027958 """
1028- inputdata = self ._prepare_input_data (input_args = args , input_kwargs = kwargs )
959+ inputdata = self ._prepare_input_data (input_kwargs = kwargs )
1029960
1030961 for key , val in inputdata .items ():
1031962 if key not in self ._inputs :
0 commit comments