Repository: haddocking/haddock3
Issue: unicode problems in restarting mpi runs

currently the restart option does not allow to restart a haddock3 MPI run, as the following error occurs:
```
  ...
  File "/trinity/login/mgiulini/haddock3/src/haddock/gear/prepare_run.py", line 273, in setup_run
    update_step_contents_to_step_names(
  File "/trinity/login/mgiulini/haddock3/src/haddock/gear/prepare_run.py", line 905, in update_step_contents_to_step_names
    update_step_names_in_file(file_, prev_names, new_names)
  File "/trinity/login/mgiulini/haddock3/src/haddock/gear/prepare_run.py", line 925, in update_step_names_in_file
    text = file_.read_text()
  File "/trinity/login/mgiulini/anaconda3/envs/haddock3/lib/python3.9/pathlib.py", line 1256, in read_text
    return f.read()
  File "/trinity/login/mgiulini/anaconda3/envs/haddock3/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
[2022-09-26 10:03:43,829 libutil ERROR] 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
```
this occurs because we are trying to read the `mpi.pkl` file, which contains non-ASCII characters. This can probably be fixed by correcting the `encoding` of `file_.read_text()`.
I have another doubt: the goal of this part of the code is, as far as I understand, to replace the old module names with the new ones. But apparently this is done even if the names are equal. Should we correct this?
@joaomcteixeira maybe we can use your help here :)

Changed files:
src/haddock/gear/extend_run.py, src/haddock/gear/prepare_run.py

diff --git a/src/haddock/gear/extend_run.py b/src/haddock/gear/extend_run.py
index 16161757..c1d95de7 100644
--- a/src/haddock/gear/extend_run.py
+++ b/src/haddock/gear/extend_run.py
@@ -256,7 +256,11 @@ def update_contents_of_new_steps(selected_steps, olddir, newdir):
     for ns in new_steps:
         new_step = Path(newdir, ns)
         for file_ in new_step.iterdir():
-            text = file_.read_text()
+            try:
+                text = file_.read_text()
+            except UnicodeDecodeError as err:
+                log.warning(f"Failed to read file {file_}. Error is {err}")
+                continue
             for s1, s2 in zip(selected_steps, new_steps):
                 text = text.replace(s1, s2)
             text = text.replace(olddir.name, newdir.name)
diff --git a/src/haddock/gear/prepare_run.py b/src/haddock/gear/prepare_run.py
index cfc845b3..64535bbc 100644
--- a/src/haddock/gear/prepare_run.py
+++ b/src/haddock/gear/prepare_run.py
@@ -934,7 +934,11 @@ def update_step_names_in_subfolders(folder, prev_names, new_names):
 
 def update_step_names_in_file(file_, prev_names, new_names):
     """Update step names in file following the `--restart` option."""
-    text = file_.read_text()
+    try:
+        text = file_.read_text()
+    except UnicodeDecodeError as err:
+        log.warning(f"Failed to read file {file_}. Error is {err}")
+        return
     for s1, s2 in zip(prev_names, new_names):
         text = text.replace(s1, s2)
     file_.write_text(text)