Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into chnixi-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Comeani authored Mar 5, 2024
2 parents 997c5f4 + 9f6e333 commit 4b547fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
33 changes: 18 additions & 15 deletions bank/account_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ def add_sus(self, inv_id: Optional[int], sus: int) -> None:
with DBConnection.session() as session:
investment = session.execute(query).scalars().first()
investment.service_units += sus
investment.current_sus += sus

session.commit()

Expand Down Expand Up @@ -574,7 +573,6 @@ def subtract_sus(self, inv_id: Optional[int], sus: int) -> None:
f'Cannot subtract {sus}. Investment {inv_id} only has {investment.current_sus} available.')

investment.service_units -= sus
investment.current_sus -= sus

session.commit()

Expand Down Expand Up @@ -795,28 +793,33 @@ def _build_usage_table(self) -> PrettyTable:
usage_percentage = self._calculate_percentage(aggregate_usage_total, allocation_total)

floating_su_percent = self._calculate_percentage(floating_su_usage, floating_su_total)
output_table.add_row(['Floating SUs', "SUs Remaining", "% Used"], divider=True)
output_table.add_row([f'*Floating SUs', "", ""])
output_table.add_row([f'are applied on', "", ""])
output_table.add_row([f'any cluster to', str(floating_su_remaining)+'*', floating_su_percent])
output_table.add_row([f'cover usage above', "", ""])
output_table.add_row([f'Total SUs', "", ""], divider=True)
output_table.add_row(["Floating SUs", "", ""], divider=True)
output_table.add_row(["Floating SUs", "", ""])
output_table.add_row(["are applied on", "", ""])
output_table.add_row(["any cluster to", "", ""])
output_table.add_row(["cover usage above", "", ""])
output_table.add_row(["Total Proposal SUs", "", ""])
output_table.add_row(["Total", "SUs Remaining", "% Used"])
output_table.add_row([floating_su_total, floating_su_remaining, floating_su_percent], divider=True)

# Add another inner table describing aggregate usage
if not investments:
output_table.add_row(['Aggregate Usage', usage_percentage, ""], divider=True)
else:
investment_total = sum(inv.service_units for inv in investments)
investment_remaining = sum(inv.current_sus for inv in investments)
investment_remaining = sum(inv.current_sus for inv in investments)
investment_used = investment_total - investment_remaining
investment_percentage = self._calculate_percentage(investment_used, investment_total)

output_table.add_row(['Investment SUs', "SUs Remaining", "% Used"], divider=True)
output_table.add_row([f'**Investment SUs', "",""])
output_table.add_row([f'are applied on', "", ""])
output_table.add_row([f'any cluster to', str(investment_remaining)+"**", investment_percentage])
output_table.add_row([f'cover usage above',"",""])
output_table.add_row([f'Total SUs', "", ""], divider=True)
output_table.add_row(["Investment SUs", "", ""], divider=True)
output_table.add_row(["Investment SUs", "", ""])
output_table.add_row(["are applied on", "", ""])
output_table.add_row(["any cluster to", "", ""])
output_table.add_row(["cover usage above", "", ""])
output_table.add_row(["Total Proposal SUs", "", ""])
output_table.add_row(["Total", "SUs Remaining", "% Used"])
output_table.add_row([investment_total, investment_remaining, investment_percentage], divider=True)

output_table.add_row(['Aggregate Usage', usage_percentage, ""])
output_table.add_row(['(no investments)', "", ""])

Expand Down
7 changes: 2 additions & 5 deletions bank/system/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_locked_state(self, cluster: str) -> bool:
raise ClusterNotFoundError(f'Cluster {cluster} is not configured with Slurm')

cmd = f'sacctmgr -n -P show assoc account={self.account_name} format=GrpTresRunMins clusters={cluster}'
return 'cpu=0' in ShellCmd(cmd).out
return 'billing=0' in ShellCmd(cmd).out

def set_locked_state(self, lock_state: bool, cluster: str) -> None:
"""Lock or unlock the current slurm account
Expand All @@ -146,10 +146,7 @@ def set_locked_state(self, lock_state: bool, cluster: str) -> None:
raise ClusterNotFoundError(f'Cluster {cluster} is not configured with Slurm')

lock_state_int = 0 if lock_state else -1
ShellCmd(f'sacctmgr -i modify account where account={self.account_name} cluster={cluster} '
f'set GrpTresRunMins=cpu={lock_state_int}').raise_if_err()
ShellCmd(f'sacctmgr -i modify account where account={self.account_name} cluster={cluster} '
f'set GrpTresRunMins=gres/gpu={lock_state_int}').raise_if_err()
ShellCmd(f'sacctmgr -i modify account where account={self.account_name} cluster={cluster} set GrpTresRunMins=billing={lock_state_int}').raise_if_err()

def get_cluster_usage_per_user(self, cluster: str, start: date, end: date, in_hours: bool = True) -> Dict[str, int]:
"""Return the raw account usage per user on a given cluster
Expand Down

0 comments on commit 4b547fd

Please sign in to comment.