Skip to content

Remove empty experiment dirs#242

Merged
leahaeusel merged 2 commits intoqueens-py:mainfrom
leahaeusel:remove-empty-experiment-dirs
Jan 26, 2026
Merged

Remove empty experiment dirs#242
leahaeusel merged 2 commits intoqueens-py:mainfrom
leahaeusel:remove-empty-experiment-dirs

Conversation

@leahaeusel
Copy link
Member

Description and Context:
What and Why?

This PR introduces the deletion of empty experiment directories when exiting the global settings context.

Related Issues and Pull Requests

Interested Parties

@sbrandstaeter

Note: More information on the merge request procedure in QUEENS can be found in the Submit a pull request section in the CONTRIBUTING.md file.

@leahaeusel leahaeusel requested a review from Copilot November 7, 2025 17:42
Copy link

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 PR refactors the experiment directory management to prevent accidental overwrites and automatically clean up empty directories. The experiment_directory() function now returns a tuple (Path, bool) indicating both the directory path and whether it already exists. Schedulers gain the ability to prompt users for confirmation before overwriting existing experiments and automatically delete empty experiment directories when the GlobalSettings context exits.

  • Modified experiment_directory() to return whether the directory exists without creating it
  • Added user confirmation prompts to prevent accidental overwrites of existing experiments
  • Implemented automatic cleanup of empty experiment directories via a scheduler registry

Reviewed Changes

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

Show a summary per file
File Description
src/queens/utils/config_directories.py Changed experiment_directory() return type to tuple including existence flag
src/queens/schedulers/_scheduler.py Added user confirmation prompt, cleanup registry, and local experiment directory management
src/queens/schedulers/local.py Added overwrite_existing_experiment parameter and uses new experiment directory logic
src/queens/schedulers/pool.py Added overwrite_existing_experiment parameter and uses new experiment directory logic
src/queens/schedulers/cluster.py Added remote/local experiment directory methods and overwrite handling
src/queens/schedulers/_dask.py Refactored to use cleanup registry instead of shutdown client list
src/queens/global_settings.py Changed to call scheduler cleanup functions instead of client shutdown
src/queens/drivers/jobscript.py Updated to use create_folder_if_not_existent() helper
tests/unit_tests/tutorials/test_tutorials.py Mocks base_directory to prevent writing to user's home during tests
tests/unit_tests/schedulers/test_experiment_dir.py New test file for experiment directory creation and overwrite behavior
tests/unit_tests/drivers/test_jobscript.py Replaced local experiment_name fixture with shared test_name fixture
tests/integration_tests/fourc/test_fourc_mc.py Updated to unpack tuple from experiment_directory()
tests/integration_tests/fourc/test_fourc_mc_random_material_field.py Updated to unpack tuple from experiment_directory()
tests/integration_tests/cluster/test_dask_cluster.py Updated mock and added comprehensive experiment directory tests

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

@leahaeusel leahaeusel force-pushed the remove-empty-experiment-dirs branch from 435dbda to 3b9671b Compare November 7, 2025 17:49
@leahaeusel leahaeusel force-pushed the remove-empty-experiment-dirs branch 4 times, most recently from 6170ece to 5f72d64 Compare November 12, 2025 14:58
@leahaeusel leahaeusel marked this pull request as ready for review November 12, 2025 15:00
@leahaeusel leahaeusel force-pushed the remove-empty-experiment-dirs branch from 5f72d64 to 8fea8e7 Compare December 17, 2025 08:41
@maxdinkel
Copy link
Member

maxdinkel commented Dec 18, 2025

Would it be possible to delay the creation of the experiment directory by removing self.start_cluster_and_connect_client() from the init of the Dask scheduler and adding the experiment_directory() function to the self.start_cluster_and_connect_client() method? Then the experiment directory is only created once an evaluation is called, I believe.

@leahaeusel
Copy link
Member Author

Would it be possible to delay the creation of the experiment directory by removing self.start_cluster_and_connect_client() from the init of the Dask scheduler and adding the experiment_directory() function to the self.start_cluster_and_connect_client() method? Then the experiment directory is only created once an evaluation is called, I believe.

You are right that we could delay the creation of the experiment directory until evaluate() is called. However, this does not get rid of empty experiment directories in cases where the function passed to evaluate() does not actually write anything to the experiment directory, as is currently the case with the function driver. Therefore, I haven't been able to come up with a prettier solution than checking for an empty experiment directory at the end of the run.

@leahaeusel leahaeusel force-pushed the remove-empty-experiment-dirs branch from 8fea8e7 to 622c4b8 Compare January 16, 2026 10:50
@maxdinkel
Copy link
Member

You are right that we could delay the creation of the experiment directory until evaluate() is called. However, this does not get rid of empty experiment directories in cases where the function passed to evaluate() does not actually write anything to the experiment directory, as is currently the case with the function driver. Therefore, I haven't been able to come up with a prettier solution than checking for an empty experiment directory at the end of the run.

Aren't the log files still written by the scheduler in this case?

@leahaeusel
Copy link
Member Author

Aren't the log files still written by the scheduler in this case?

Only for the Cluster scheduler. If you use either the Local or the Pool scheduler, no log files or any other outputs are written to the experiment directory by the scheduler itself.

Copy link
Member

@maxdinkel maxdinkel left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Thank you for your efforts :)

@leahaeusel leahaeusel merged commit 994804c into queens-py:main Jan 26, 2026
3 checks passed
@leahaeusel leahaeusel deleted the remove-empty-experiment-dirs branch January 26, 2026 09:09
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.

4 participants