From 4f231507053226aaf835f3de17b7c66891c15ce7 Mon Sep 17 00:00:00 2001
From: Andi Gerken <andi.gerken@gmail.com>
Date: Thu, 14 Apr 2022 14:06:45 +0200
Subject: [PATCH] Added option to not validate files when saving for
 performance reasons.

---
 src/robofish/evaluate/evaluate.py | 2 +-
 src/robofish/io/file.py           | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/robofish/evaluate/evaluate.py b/src/robofish/evaluate/evaluate.py
index 7db6569..fedefc7 100644
--- a/src/robofish/evaluate/evaluate.py
+++ b/src/robofish/evaluate/evaluate.py
@@ -650,8 +650,8 @@ def evaluate_tracks(
 
     # Iterate all paths
     for k, files_in_path in enumerate(files_per_path):
-
         random.shuffle(files_in_path)
+
         # Iterate all files
         for i, file_path in enumerate(files_in_path):
             with robofish.io.File(file_path, "r") as file:
diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py
index d57c7bf..b29a546 100644
--- a/src/robofish/io/file.py
+++ b/src/robofish/io/file.py
@@ -67,6 +67,7 @@ class File(h5py.File):
         *,  # PEP 3102
         world_size_cm: List[int] = None,
         validate: bool = False,
+        validate_when_saving: bool = True,
         strict_validate: bool = False,
         format_version: List[int] = default_format_version,
         format_url: str = default_format_url,
@@ -143,6 +144,7 @@ class File(h5py.File):
         """
 
         self.path = path
+        self.validate_when_saving = validate_when_saving
 
         if open_copy:
             assert (
@@ -256,7 +258,9 @@ class File(h5py.File):
     def __exit__(self, type, value, traceback):
         # Check if the context was left under normal circumstances
         if (type, value, traceback) == (None, None, None):
-            if self.mode != "r":  # No need to validate read only files (performance).
+            if (
+                self.mode != "r" and self.validate_when_saving
+            ):  # No need to validate read only files (performance).
                 self.validate()
 
         super().__exit__(type, value, traceback)
-- 
GitLab