Skip to content

9 being able to work without outputfolder and saving nothing or all temporary#10

Merged
Pablo1990 merged 5 commits intomainfrom
9-being-able-to-work-without-outputfolder-and-saving-nothing-or-all-temporary
Feb 2, 2026
Merged

9 being able to work without outputfolder and saving nothing or all temporary#10
Pablo1990 merged 5 commits intomainfrom
9-being-able-to-work-without-outputfolder-and-saving-nothing-or-all-temporary

Conversation

@Pablo1990
Copy link
Copy Markdown
Owner

@Pablo1990 Pablo1990 commented Feb 2, 2026

Summary by CodeRabbit

  • New Features

    • Added methods to create and manage temporary folders during model execution
    • Made initial configuration file optional during model initialization
  • Bug Fixes

    • Improved conditional handling of output folder setup and temporary file processing
  • Chores

    • Updated ignore list to exclude temporary directories

Copilot AI review requested due to automatic review settings February 2, 2026 15:24
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 2, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

 __________________________________________________________
< If your code was a carrot, I'd bury it and forget where. >
 ----------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

Tip

You can customize the tone of the review comments and chat replies.

Set the tone_instructions setting in your project's settings in CodeRabbit to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 9-being-able-to-work-without-outputfolder-and-saving-nothing-or-all-temporary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 2, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #11

@Pablo1990 Pablo1990 merged commit 240a926 into main Feb 2, 2026
4 of 6 checks passed
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/pyVertexModel/algorithm/vertexModel.py`:
- Around line 255-265: The code currently always builds filename with
os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state) which turns
None into the string "None"; update initialize to first check if img_input is
None and self.set.initial_filename_state is None and handle that case (either
skip file-based initialization or raise a clear ValueError), and only call
os.path.join when self.set.initial_filename_state is not None; ensure any error
log references the actual missing filename or explicitly states that
initial_filename_state is unset; adjust the FileNotFoundError path check
accordingly in initialize.

In `@src/pyVertexModel/geometry/geo.py`:
- Around line 369-370: The membership check "if '/Temp/' not in
c_set.initial_filename_state" can raise TypeError when
c_set.initial_filename_state is None; update the condition used before calling
update_lmin0 (and the default_value call to find_lmin0_equal_target_gr) to guard
against None by first checking truthiness of c_set.initial_filename_state (e.g.,
treat None the same as "does not contain '/Temp/'"); modify the conditional
around update_lmin0 accordingly so it safely handles
c_set.initial_filename_state == None and still calls
update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set)) when
appropriate.
🧹 Nitpick comments (1)
src/pyVertexModel/algorithm/vertexModel.py (1)

1294-1302: Fragile check for temporary folder path.

The check 'Temp' in self.set.OutputFolder could match unintended paths (e.g., /home/user/Temperature/output or /data/TempResults/). Consider using a more specific check that matches the expected path structure.

♻️ Proposed fix for more robust path checking
     def clean_temporary_folder(self):
         """
         Clean temporary folder after the simulation.
         :return:
         """
-        if self.set.OutputFolder is not None and 'Temp' in self.set.OutputFolder:
+        temp_base = os.path.join(PROJECT_DIRECTORY, 'Temp')
+        if self.set.OutputFolder is not None and self.set.OutputFolder.startswith(temp_base):
             shutil.rmtree(self.set.OutputFolder)
             logger.info(f'Removed temporary output folder at: {self.set.OutputFolder}')
             self.set.OutputFolder = None

Comment on lines +255 to +265
def initialize(self, img_input=None):
"""
Initialize the geometry and the topology of the model.
:param img_input: Optional. Either a filename (str) or a numpy array containing the image.
If None, uses the filename from settings.
"""
filename = os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state)

if not os.path.exists(filename):
if not os.path.exists(filename) and img_input is None:
logging.error(f'File {filename} not found')
raise FileNotFoundError(f'File {filename} not found')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Potential issue when initial_filename_state is None.

When initial_filename_state is None (the new default), os.path.join(PROJECT_DIRECTORY, None) will convert None to the string 'None', resulting in a path like /path/to/project/None. This creates a confusing error message since the path won't exist.

Consider adding an early check for None:

🐛 Proposed fix to handle None gracefully
     def initialize(self, img_input=None):
         """
         Initialize the geometry and the topology of the model.
         :param img_input: Optional. Either a filename (str) or a numpy array containing the image. 
                          If None, uses the filename from settings.
         """
+        if self.set.initial_filename_state is None and img_input is None:
+            raise ValueError("Either initial_filename_state must be set or img_input must be provided")
+
         filename = os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state)

         if not os.path.exists(filename) and img_input is None:
             logging.error(f'File {filename} not found')
             raise FileNotFoundError(f'File {filename} not found')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def initialize(self, img_input=None):
"""
Initialize the geometry and the topology of the model.
:param img_input: Optional. Either a filename (str) or a numpy array containing the image.
If None, uses the filename from settings.
"""
filename = os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state)
if not os.path.exists(filename):
if not os.path.exists(filename) and img_input is None:
logging.error(f'File {filename} not found')
raise FileNotFoundError(f'File {filename} not found')
def initialize(self, img_input=None):
"""
Initialize the geometry and the topology of the model.
:param img_input: Optional. Either a filename (str) or a numpy array containing the image.
If None, uses the filename from settings.
"""
if self.set.initial_filename_state is None and img_input is None:
raise ValueError("Either initial_filename_state must be set or img_input must be provided")
filename = os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state)
if not os.path.exists(filename) and img_input is None:
logging.error(f'File {filename} not found')
raise FileNotFoundError(f'File {filename} not found')
🧰 Tools
🪛 Ruff (0.14.14)

[warning] 265-265: Avoid specifying long messages outside the exception class

(TRY003)

🤖 Prompt for AI Agents
In `@src/pyVertexModel/algorithm/vertexModel.py` around lines 255 - 265, The code
currently always builds filename with os.path.join(PROJECT_DIRECTORY,
self.set.initial_filename_state) which turns None into the string "None"; update
initialize to first check if img_input is None and
self.set.initial_filename_state is None and handle that case (either skip
file-based initialization or raise a clear ValueError), and only call
os.path.join when self.set.initial_filename_state is not None; ensure any error
log references the actual missing filename or explicitly states that
initial_filename_state is unset; adjust the FileNotFoundError path check
accordingly in initialize.

Comment on lines +369 to +370
if '/Temp/' not in c_set.initial_filename_state:
self.update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

TypeError when initial_filename_state is None.

Since initial_filename_state now defaults to None (as changed in set.py), this condition will raise a TypeError when checking '/Temp/' not in None. The in operator doesn't work with None.

🐛 Proposed fix to handle None case
-        if '/Temp/' not in c_set.initial_filename_state:
+        if c_set.initial_filename_state is not None and '/Temp/' not in c_set.initial_filename_state:
             self.update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if '/Temp/' not in c_set.initial_filename_state:
self.update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set))
if c_set.initial_filename_state is not None and '/Temp/' not in c_set.initial_filename_state:
self.update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set))
🤖 Prompt for AI Agents
In `@src/pyVertexModel/geometry/geo.py` around lines 369 - 370, The membership
check "if '/Temp/' not in c_set.initial_filename_state" can raise TypeError when
c_set.initial_filename_state is None; update the condition used before calling
update_lmin0 (and the default_value call to find_lmin0_equal_target_gr) to guard
against None by first checking truthiness of c_set.initial_filename_state (e.g.,
treat None the same as "does not contain '/Temp/'"); modify the conditional
around update_lmin0 accordingly so it safely handles
c_set.initial_filename_state == None and still calls
update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set)) when
appropriate.

coderabbitai Bot added a commit that referenced this pull request Feb 2, 2026
…ving-nothing-or-all-temporary`

Docstrings generation was requested by @Pablo1990.

* #10 (comment)

The following files were modified:

* `src/pyVertexModel/algorithm/vertexModel.py`
* `src/pyVertexModel/geometry/geo.py`
* `src/pyVertexModel/parameters/set.py`
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request attempts to enable the system to work without an output folder, allowing users to run simulations without saving intermediate files or by using temporary folders. The changes make both OutputFolder and initial_filename_state optional by setting them to None by default.

Changes:

  • Set initial_filename_state to None by default instead of 'Input/wing_disc_150.mat'
  • Added None checks for OutputFolder in redirect_output, iterate_over_time, and save_v_model_state methods
  • Added conditional logic to skip expensive computation when loading from temporary files
  • Added create_temporary_folder() and clean_temporary_folder() methods for managing temporary folders
  • Added Temp/ directory to .gitignore

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/pyVertexModel/parameters/set.py Changed initial_filename_state default to None and added None guard to redirect_output method
src/pyVertexModel/geometry/geo.py Added condition to skip computation for temporary files (contains bug)
src/pyVertexModel/algorithm/vertexModel.py Added None checks for OutputFolder, FileNotFoundError raising, temporary folder management methods, and fixed whitespace
.gitignore Added Temp/ directory to ignore list
Comments suppressed due to low confidence (1)

src/pyVertexModel/algorithm/vertexModel.py:271

  • When initial_filename_state is None (the new default), os.path.join will convert None to the string 'None', creating an invalid path like 'PROJECT_DIRECTORY/None'. This causes several problems: (1) Line 267's os.path.splitext will operate on this invalid path, (2) Lines 269-271 will create invalid output_filename paths, and (3) Lines 273-295 will use these invalid paths for file operations. Even with the added check at lines 263-265, if img_input is provided but initial_filename_state is None, the code will continue with the invalid filename. The method should first check if initial_filename_state is None and handle it appropriately before attempting any path operations.
        filename = os.path.join(PROJECT_DIRECTORY, self.set.initial_filename_state)

        if not os.path.exists(filename) and img_input is None:
            logging.error(f'File {filename} not found')
            raise FileNotFoundError(f'File {filename} not found')

        base, ext = os.path.splitext(filename)
        if self.set.min_3d_neighbours is None:
            output_filename = f"{base}_{self.set.TotalCells}cells_{self.set.CellHeight}_scutoids_{self.set.percentage_scutoids}.pkl"
        else:
            output_filename = f"{base}_{self.set.TotalCells}cells_{self.set.CellHeight}_min3d_{self.set.min_3d_neighbours}.pkl"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1299 to +1302
if self.set.OutputFolder is not None and 'Temp' in self.set.OutputFolder:
shutil.rmtree(self.set.OutputFolder)
logger.info(f'Removed temporary output folder at: {self.set.OutputFolder}')
self.set.OutputFolder = None No newline at end of file
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for checking temporary folders using string matching with 'Temp' is fragile and could lead to unintended behavior. If a user creates an output folder with 'Temp' anywhere in its path (e.g., 'MyTempResults' or '/home/user/Temporary/output'), this method would incorrectly delete it. Consider using a more robust approach, such as storing a flag indicating whether the folder is temporary, or checking if the folder is specifically within the PROJECT_DIRECTORY/Temp directory.

Suggested change
if self.set.OutputFolder is not None and 'Temp' in self.set.OutputFolder:
shutil.rmtree(self.set.OutputFolder)
logger.info(f'Removed temporary output folder at: {self.set.OutputFolder}')
self.set.OutputFolder = None
if self.set.OutputFolder is None:
return
output_folder = os.path.abspath(self.set.OutputFolder)
temp_root = os.path.abspath(os.path.join(PROJECT_DIRECTORY, 'Temp'))
try:
is_within_temp = os.path.commonpath([output_folder, temp_root]) == temp_root
except ValueError:
# If paths are on different drives or otherwise incomparable, do not delete.
is_within_temp = False
if is_within_temp and output_folder != temp_root and os.path.isdir(output_folder):
shutil.rmtree(output_folder)
logger.info(f'Removed temporary output folder at: {self.set.OutputFolder}')
else:
logger.warning(f"Output folder '{self.set.OutputFolder}' not removed because it is not a managed temporary folder.")
self.set.OutputFolder = None

Copilot uses AI. Check for mistakes.
# Update lmin0 with the minimum value in lmin_values
self.update_lmin0()
self.update_lmin0(default_value=find_lmin0_equal_target_gr(self, c_set))
if '/Temp/' not in c_set.initial_filename_state:
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition attempts to check if the initial_filename_state contains '/Temp/', but it will raise a TypeError when initial_filename_state is None because the 'in' operator cannot be used with None. The logic should first check if initial_filename_state is not None before checking if it contains '/Temp/'. A safer approach would be: 'if c_set.initial_filename_state is not None and '/Temp/' not in c_set.initial_filename_state:'

Suggested change
if '/Temp/' not in c_set.initial_filename_state:
if c_set.initial_filename_state is not None and '/Temp/' not in c_set.initial_filename_state:

Copilot uses AI. Check for mistakes.

def create_temporary_folder(self):
"""
Create temporary folder where store every require file during the simulation.
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: 'require' should be 'required'. The docstring should read 'Create temporary folder where every required file is stored during the simulation.'

Suggested change
Create temporary folder where store every require file during the simulation.
Create temporary folder where every required file is stored during the simulation.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Being able to work without OutputFolder (and saving nothing or all temporary)

2 participants