@@ -79,7 +79,9 @@ def __init__(
7979
8080 # Create a chunk of code to start the process
8181 lua_debug_flag = "true" if debug else "false"
82- startup_chunk = f"MAD.pymad '{ py_name } ' {{_dbg = { lua_debug_flag } }} :__ini({ mad_write } )"
82+ startup_chunk = (
83+ f"MAD.pymad '{ py_name } ' {{_dbg = { lua_debug_flag } }} :__ini({ mad_write } )"
84+ )
8385
8486 if threading .current_thread () is threading .main_thread ():
8587 self ._setup_signal_handler ()
@@ -125,7 +127,9 @@ def __init__(
125127 if not startup_status_checker [0 ] or mad_rtrn != "started" :
126128 self .close ()
127129 if mad_rtrn == "started" :
128- raise OSError (f"Could not establish communication with { mad_path } process" )
130+ raise OSError (
131+ f"Could not establish communication with { mad_path } process"
132+ )
129133 raise OSError (f"Could not start { mad_path } process, received: { mad_rtrn } " )
130134
131135 # Set the error handler to be on by default
@@ -175,7 +179,9 @@ def send_cpx_tpsa(self, monos: np.ndarray, coefficients: np.ndarray) -> None:
175179 self .mad_input_stream .write (b"ctpa" )
176180 send_generic_tpsa (self , monos , coefficients , send_cpx )
177181
178- def send (self , data : str | int | float | np .ndarray | bool | list | dict ) -> MadProcess :
182+ def send (
183+ self , data : str | int | float | np .ndarray | bool | list | dict
184+ ) -> MadProcess :
179185 """Send data to the MAD-NG process.
180186
181187 Accepts several types (str, int, float, ndarray, bool, list, dict) and sends them using the appropriate serialization.
@@ -199,9 +205,13 @@ def protected_send(self, string: str) -> MadProcess:
199205 if self .raise_on_madng_error :
200206 # If the user has specified that they want to raise an error always, skip the error handling on and off
201207 return self .send (string )
202- return self .send (f"{ self .py_name } :__err(true); { string } ; { self .py_name } :__err(false);" )
208+ return self .send (
209+ f"{ self .py_name } :__err(true); { string } ; { self .py_name } :__err(false);"
210+ )
203211
204- def protected_variable_retrieval (self , name : str , shallow_copy : bool = False ) -> Any :
212+ def protected_variable_retrieval (
213+ self , name : str , shallow_copy : bool = False
214+ ) -> Any :
205215 """Safely retrieve a variable from MAD-NG.
206216
207217 Enables temporary error handling while retrieving a variable.
@@ -213,7 +223,7 @@ def protected_variable_retrieval(self, name: str, shallow_copy: bool = False) ->
213223 """
214224 shallow_copy = str (shallow_copy ).lower ()
215225 if self .raise_on_madng_error :
216- return self .send (f"py :send({ name } , { shallow_copy } )" ).recv (name )
226+ return self .send (f"{ self . py_name } :send({ name } , { shallow_copy } )" ).recv (name )
217227 self .send (
218228 f"{ self .py_name } :__err(true):send({ name } , { shallow_copy } ):__err(false)"
219229 ) # Enable error handling, ask for the variable, and disable error handling
@@ -297,7 +307,9 @@ def recv_vars(self, *names, shallow_copy: bool = False) -> Any:
297307 raise ValueError ("Cannot retrieve private variables from MAD-NG" )
298308 if len (names ) == 1 :
299309 return self .protected_variable_retrieval (names [0 ], shallow_copy )
300- return tuple (self .protected_variable_retrieval (name , shallow_copy ) for name in names )
310+ return tuple (
311+ self .protected_variable_retrieval (name , shallow_copy ) for name in names
312+ )
301313
302314 # -------------------------------------------------------------------------- #
303315
@@ -683,7 +695,9 @@ def recv_generic_matrix(self: MadProcess, dtype: np.dtype) -> str:
683695 str: A string representation of the matrix (reshaped numpy array).
684696 """
685697 shape = read_data_stream (self , 8 , np .int32 )
686- return read_data_stream (self , shape [0 ] * shape [1 ] * dtype .itemsize , dtype ).reshape (shape )
698+ return read_data_stream (self , shape [0 ] * shape [1 ] * dtype .itemsize , dtype ).reshape (
699+ shape
700+ )
687701
688702
689703def recv_matrix (self : MadProcess ) -> np .ndarray :
@@ -759,7 +773,9 @@ def send_generic_tpsa(
759773 assert len (monos ) == len (coefficients ), (
760774 "The number of monomials must be equal to the number of coefficients"
761775 )
762- assert monos .dtype == np .uint8 , "The monomials must be of type 8-bit unsigned integer "
776+ assert monos .dtype == np .uint8 , (
777+ "The monomials must be of type 8-bit unsigned integer "
778+ )
763779 write_serial_data (self , "ii" , len (monos ), len (monos [0 ]))
764780 for mono in monos :
765781 self .mad_input_stream .write (mono .tobytes ())
0 commit comments