Skip to content

PestSolver pypestworker raises a TypeError: cannot pickle 'TextIOWrapper' instances #27

Description

@cnicol-gwlogic

Example notebook pest_pastas_ies.ipynb and pest_pastas_glm_hp.ipynb both fail when using the default solver argument use_pypestworker=True. Windows 11 machine(s). The (rather long) traceback is below. Any ideas what I have wrong? Ta.


[C:\Python313\Lib\site-packages\pastas_plugins\pest\solver.py:387](file:///C:/Python313/Lib/site-packages/pastas_plugins/pest/solver.py#line=386): SyntaxWarning: invalid escape sequence '\s'
[C:\Python313\Lib\site-packages\pastas_plugins\pest\solver.py:506](file:///C:/Python313/Lib/site-packages/pastas_plugins/pest/solver.py#line=505): SyntaxWarning: invalid escape sequence '\s'
[C:\Python313\Lib\site-packages\pastas_plugins\pest\solver.py:512](file:///C:/Python313/Lib/site-packages/pastas_plugins/pest/solver.py#line=511): SyntaxWarning: invalid escape sequence '\s'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 16
     14 # ml_ies.set_parameter("constant_d", initial=27.5, vary=False)
     15 ml_ies.add_solver(solver)
---> 16 ml_ies.solver.run_ensembles()
     17 ml_ies.solver.nfev = solver.noptmax

File [C:\Python313\Lib\site-packages\pastas_plugins\pest\solver.py:681](file:///C:/Python313/Lib/site-packages/pastas_plugins/pest/solver.py#line=680), in PestIesSolver.run_ensembles(self, ies_add_base, par_sigma_range, observation_noise_standard_deviation, observation_noise_correlation_coefficient, ies_parameter_ensemble_method, pestpp_options, silent)
    677 pst.pestpp_options.update(pestpp_options)
    679 self.write_pst(pst=pst, version=2)
--> 681 pyemu.os_utils.start_workers(
    682     worker_dir=self.temp_ws,  # the folder which contains the "template" PEST dataset
    683     exe_rel_path=self.exe_name.name,  # the PEST software version we want to run
    684     pst_rel_path="pest.pst",  # the control file to use with PEST
    685     num_workers=self.num_workers,  # how many agents to deploy
    686     worker_root=self.master_ws.parent,  # where to deploy the agent directories; relative to where python is running
    687     master_dir=self.master_ws,  # the manager directory
    688     port=self.port_number,  # the port to use for communication
    689     verbose=silent,
    690     silent_master=silent,
    691     reuse_master=self.use_pypestworker,
    692     ppw_function=self.ppw_function
    693     if self.use_pypestworker
    694     else None,  # the function to run in the agent
    695     ppw_kwargs={"ml": self.ml}
    696     if self.use_pypestworker
    697     else {},  # the arguments to pass to the ppw_function
    698 )
    700 phidf = pd.read_csv(self.master_ws / "pest.phi.meas.csv", index_col=0)
    701 self.nfev = phidf.index[-1]

File [C:\Python313\Lib\site-packages\pyemu\utils\os_utils.py:412](file:///C:/Python313/Lib/site-packages/pyemu/utils/os_utils.py#line=411), in start_workers(worker_dir, exe_rel_path, pst_rel_path, num_workers, worker_root, port, rel_path, local, cleanup, master_dir, verbose, silent_master, reuse_master, restart, ppw_function, ppw_kwargs)
    410     for i in range(num_workers):
    411         p = mp.Process(target=ppw_function,args=args,kwargs=ppw_kwargs)
--> 412         p.start()
    413         procs.append(p)
    415 else:

File [C:\Python313\Lib\multiprocessing\process.py:121](file:///C:/Python313/Lib/multiprocessing/process.py#line=120), in BaseProcess.start(self)
    118 assert not _current_process._config.get('daemon'), \
    119        'daemonic processes are not allowed to have children'
    120 _cleanup()
--> 121 self._popen = self._Popen(self)
    122 self._sentinel = self._popen.sentinel
    123 # Avoid a refcycle if the target function holds an indirect
    124 # reference to the process object (see bpo-30775)

File [C:\Python313\Lib\multiprocessing\context.py:224](file:///C:/Python313/Lib/multiprocessing/context.py#line=223), in Process._Popen(process_obj)
    222 @staticmethod
    223 def _Popen(process_obj):
--> 224     return _default_context.get_context().Process._Popen(process_obj)

File [C:\Python313\Lib\multiprocessing\context.py:337](file:///C:/Python313/Lib/multiprocessing/context.py#line=336), in SpawnProcess._Popen(process_obj)
    334 @staticmethod
    335 def _Popen(process_obj):
    336     from .popen_spawn_win32 import Popen
--> 337     return Popen(process_obj)

File [C:\Python313\Lib\multiprocessing\popen_spawn_win32.py:97](file:///C:/Python313/Lib/multiprocessing/popen_spawn_win32.py#line=96), in Popen.__init__(self, process_obj)
     95 try:
     96     reduction.dump(prep_data, to_child)
---> 97     reduction.dump(process_obj, to_child)
     98 finally:
     99     set_spawning_popen(None)

File [C:\Python313\Lib\multiprocessing\reduction.py:60](file:///C:/Python313/Lib/multiprocessing/reduction.py#line=59), in dump(obj, file, protocol)
     58 def dump(obj, file, protocol=None):
     59     '''Replacement for pickle.dump() using ForkingPickler.'''
---> 60     ForkingPickler(file, protocol).dump(obj)

TypeError: cannot pickle 'TextIOWrapper' instances

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions