1313
1414class RocketPyEncoder (json .JSONEncoder ):
1515 """Custom JSON encoder for RocketPy objects. It defines how to encode
16- different types of objects to a JSON supported format."""
16+ different types of objects to a JSON supported format.
17+ """
1718
1819 def __init__ (self , * args , ** kwargs ):
20+ """Initializes the encoder with parameter options.
21+
22+ Parameters
23+ ----------
24+ *args : tuple
25+ Positional arguments to pass to the parent class.
26+ **kwargs : dict
27+ Keyword arguments to configure the encoder. The following
28+ options are available:
29+ - include_outputs: bool, whether to include simulation outputs.
30+ Default is False.
31+ - include_function_data: bool, whether to include Function
32+ data in the encoding. If False, Functions will be encoded by their
33+ ``__repr__``. This is useful for reducing the size of the outputs,
34+ but it prevents full restoration of the object upon decoding.
35+ Default is True.
36+ - discretize: bool, whether to discretize Functions whose source
37+ are callables. If True, the accuracy of the decoding may be reduced.
38+ Default is False.
39+ - pickle_callables: bool, whether to pickle callable objects. If
40+ False, callable sources (such as user-defined functions, parachute
41+ triggers or simulation callable outputs) will have their name
42+ stored instead of the function itself. This is useful for
43+ reducing the size of the outputs, but it prevents full restoration
44+ of the object upon decoding.
45+ Default is True.
46+ """
1947 self .include_outputs = kwargs .pop ("include_outputs" , False )
20- self .discretize = kwargs .pop ("discretize" , False )
2148 self .include_function_data = kwargs .pop ("include_function_data" , True )
49+ self .discretize = kwargs .pop ("discretize" , False )
50+ self .pickle_callables = kwargs .pop ("pickle_callables" , True )
2251 super ().__init__ (* args , ** kwargs )
2352
2453 def default (self , o ):
@@ -35,13 +64,17 @@ def default(self, o):
3564 return str (o )
3665 else :
3766 encoding = o .to_dict (
38- include_outputs = self .include_outputs , discretize = self .discretize
67+ include_outputs = self .include_outputs ,
68+ discretize = self .discretize ,
69+ pickle_callables = self .pickle_callables ,
3970 )
4071 encoding ["signature" ] = get_class_signature (o )
4172 return encoding
4273 elif hasattr (o , "to_dict" ):
4374 encoding = o .to_dict (
44- include_outputs = self .include_outputs , discretize = self .discretize
75+ include_outputs = self .include_outputs ,
76+ discretize = self .discretize ,
77+ pickle_callables = self .pickle_callables ,
4578 )
4679 encoding = remove_circular_references (encoding )
4780
0 commit comments