Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep argument to submit_new_batch and fix verbose #20

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ repos:
rev: 23.3.0
hooks:
- id: black
language_version: python3.9

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.262'
Expand Down
14 changes: 9 additions & 5 deletions aiida_submission_controller/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""A prototype class to submit processes in batches, avoiding to submit too many."""
import abc
import logging
import time
from typing import Optional

from aiida import engine, orm
Expand Down Expand Up @@ -178,11 +179,12 @@ def num_already_run(self):
"""Number of processes that have already been submitted (and might or might not have finished)."""
return len(self._check_submitted_extras())

def submit_new_batch(self, dry_run=False, sort=False, verbose=False):
def submit_new_batch(self, dry_run=False, sort=False, verbose=False, sleep=0):
"""Submit a new batch of calculations, ensuring less than self.max_concurrent active at the same time."""
CMDLINE_LOGGER.level = logging.INFO if verbose else logging.WARNING

extras_to_run = list(set(self.get_all_extras_to_submit()).difference(self._check_submitted_extras()))
all_extras = set(self.get_all_extras_to_submit())
extras_to_run = list(all_extras.difference(self._check_submitted_extras()))

if sort:
extras_to_run = sorted(extras_to_run)
Expand All @@ -203,7 +205,7 @@ def submit_new_batch(self, dry_run=False, sort=False, verbose=False):
table.add_column("Available", justify="left", style="cyan", no_wrap=True)

table.add_row(
str(self.parent_group.count()),
str(len(all_extras)),
str(self.num_already_run),
str(self.num_to_run),
str(self.max_concurrent),
Expand All @@ -213,10 +215,10 @@ def submit_new_batch(self, dry_run=False, sort=False, verbose=False):
console = Console()
console.print(table)

if number_to_submit <= 0:
if number_to_submit <= 0 or self.num_to_run == 0:
print("[bold blue]Info:[/] 😴 Nothing to submit.")
else:
print(f"[bold blue]Info:[/] 🚀 Submitting {number_to_submit} new workchains!")
print(f"[bold blue]Info:[/] 🚀 Submitting {min(number_to_submit, self.num_to_run)} new workchains!")

submitted = {}

Expand All @@ -239,6 +241,8 @@ def submit_new_batch(self, dry_run=False, sort=False, verbose=False):
wc_node.set_extra_many(get_extras_dict(self.get_extra_unique_keys(), workchain_extras))
self.group.add_nodes([wc_node])
submitted[workchain_extras] = wc_node
# Only add a delay if the submission was successful
time.sleep(sleep)

return submitted

Expand Down
Loading