bmtool 0.5.6.2__py3-none-any.whl → 0.5.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bmtool/SLURM.py CHANGED
@@ -2,6 +2,7 @@ import time
2
2
  import os
3
3
  import subprocess
4
4
  import json
5
+ import requests
5
6
 
6
7
 
7
8
  def check_job_status(job_id):
@@ -18,9 +19,9 @@ def check_job_status(job_id):
18
19
  result = subprocess.run(['scontrol', 'show', 'job', job_id], capture_output=True, text=True)
19
20
  if result.returncode != 0:
20
21
  # this check is not needed if check_interval is less than 5 min (~300 seconds)
21
- #if 'slurm_load_jobs error: Invalid job id specified' in result.stderr:
22
- # return 'COMPLETED' # Treat invalid job ID as completed because scontrol expires and removed job info when done.
23
- raise Exception(f"Error checking job status: {result.stderr}")
22
+ if 'slurm_load_jobs error: Invalid job id specified' in result.stderr:
23
+ return 'COMPLETED' # Treat invalid job ID as completed because scontrol expires and removed job info when done.
24
+ #raise Exception(f"Error checking job status: {result.stderr}")
24
25
 
25
26
  job_state = None
26
27
  for line in result.stdout.split('\n'):
@@ -57,6 +58,25 @@ def submit_job(script_path):
57
58
  return job_id
58
59
 
59
60
 
61
+ def send_teams_message(webhook,message):
62
+ """Sends a message to a teams channel or chat
63
+
64
+ Args:
65
+ webhook (str): A microsoft teams webhook
66
+ message (str): A message to send in the chat/channel
67
+ """
68
+ message = {
69
+ "text": f"{message}"
70
+ }
71
+
72
+ # Send POST request to trigger the flow
73
+ response = requests.post(
74
+ webhook,
75
+ json=message, # Using 'json' instead of 'data' for automatic serialization
76
+ headers={'Content-Type': 'application/json'}
77
+ )
78
+
79
+
60
80
  class seedSweep:
61
81
  def __init__(self, json_file_path, param_name):
62
82
  """
@@ -239,6 +259,31 @@ export OUTPUT_DIR={case_output_dir}
239
259
  if status not in self.status_list:
240
260
  return False
241
261
  return True
262
+
263
+ def check_block_completed(self):
264
+ """checks if all the jobs in the block have been completed by slurm
265
+
266
+ Returns:
267
+ bool: True if all block jobs have been ran, false if job is still running
268
+ """
269
+ for job_id in self.job_ids:
270
+ status = check_job_status(job_id)
271
+ if status != 'COMPLETED': # can add PENDING here for debugging NOT FOR ACTUALLY USING IT
272
+ return False
273
+ return True
274
+
275
+
276
+ def check_block_running(self):
277
+ """checks if a job is running
278
+
279
+ Returns:
280
+ bool: True if jobs are RUNNING false if anything else
281
+ """
282
+ for job_id in self.job_ids:
283
+ status = check_job_status(job_id)
284
+ if status != 'RUNNING': #
285
+ return False
286
+ return True
242
287
 
243
288
 
244
289
  class SequentialBlockRunner:
@@ -249,13 +294,15 @@ class SequentialBlockRunner:
249
294
  blocks (list): List of SimulationBlock instances to be run.
250
295
  json_editor (seedSweep or multiSweep): Instance of seedSweep to edit JSON file.
251
296
  param_values (list): List of values for the parameter to be modified.
297
+ webhook (str): a microsoft webhook for teams. When used will send teams messages to the hook!
252
298
  """
253
299
 
254
- def __init__(self, blocks, json_editor=None, param_values=None, check_interval=200):
300
+ def __init__(self, blocks, json_editor=None, param_values=None, check_interval=200,webhook=None):
255
301
  self.blocks = blocks
256
302
  self.json_editor = json_editor
257
303
  self.param_values = param_values
258
304
  self.check_interval = check_interval
305
+ self.webhook = webhook
259
306
 
260
307
  def submit_blocks_sequentially(self):
261
308
  """
@@ -283,12 +330,23 @@ class SequentialBlockRunner:
283
330
  # Submit the block
284
331
  print(f"Submitting block: {block.block_name}", flush=True)
285
332
  block.submit_block()
286
-
333
+ if self.webhook:
334
+ message = f"SIMULATION UPDATE: Block {i} has been submitted! There are {(len(self.blocks)-1)-i} left to be submitted"
335
+ send_teams_message(self.webhook,message)
336
+
287
337
  # Wait for the block to complete
288
- while not block.check_block_status():
289
- print(f"Waiting for block {block.block_name} to complete...", flush=True)
290
- time.sleep(self.check_interval)
338
+ if i == len(self.blocks) - 1: # Corrected index to check the last block
339
+ while not block.check_block_completed():
340
+ print(f"Waiting for the last block {i} to complete...")
341
+ time.sleep(self.check_interval)
342
+ else: # Not the last block so if job is running lets start a new one (checks status list)
343
+ while not block.check_block_status():
344
+ print(f"Waiting for block {i} to complete...")
345
+ time.sleep(self.check_interval)
291
346
 
292
347
  print(f"Block {block.block_name} completed.", flush=True)
293
348
  print("All blocks are done!",flush=True)
349
+ if self.webhook:
350
+ message = "SIMULATION UPDATE: Simulation are Done!"
351
+ send_teams_message(self.webhook,message)
294
352
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bmtool
3
- Version: 0.5.6.2
3
+ Version: 0.5.7.1
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -1,4 +1,4 @@
1
- bmtool/SLURM.py,sha256=8XbzNLIQfE_lNRd_Z8ya2PEDT4TqhVnDZkil-ckLUCU,11508
1
+ bmtool/SLURM.py,sha256=AX5MKV7dD-XwS8SROnW1IyesZ3jDwMf0txO6mHxTbuw,13694
2
2
  bmtool/__init__.py,sha256=ZStTNkAJHJxG7Pwiy5UgCzC4KlhMS5pUNPtUJZVwL_Y,136
3
3
  bmtool/__main__.py,sha256=TmFkmDxjZ6250nYD4cgGhn-tbJeEm0u-EMz2ajAN9vE,650
4
4
  bmtool/bmplot.py,sha256=-kw4VOcTnA22JVQi1PzH2E308pcmY1Xo7oqgCnm0cC8,46260
@@ -16,9 +16,9 @@ bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
16
16
  bmtool/util/util.py,sha256=24E5rUoDU86nqypDF4uZJkuJKO1BrwrQE8lZzAxu1kw,56770
17
17
  bmtool/util/neuron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  bmtool/util/neuron/celltuner.py,sha256=xSRpRN6DhPFz4q5buq_W8UmsD7BbUrkzYBEbKVloYss,87194
19
- bmtool-0.5.6.2.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
- bmtool-0.5.6.2.dist-info/METADATA,sha256=Gf0JkdWfaJgYR3_mx-nlr3y2S_5i0kZT5sCckT-Up0E,24107
21
- bmtool-0.5.6.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
22
- bmtool-0.5.6.2.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
- bmtool-0.5.6.2.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
- bmtool-0.5.6.2.dist-info/RECORD,,
19
+ bmtool-0.5.7.1.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
+ bmtool-0.5.7.1.dist-info/METADATA,sha256=cgwZVmUCp3LN20uI_TD0FkTlxfvlNDei3HlW1-PVHi4,24107
21
+ bmtool-0.5.7.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
22
+ bmtool-0.5.7.1.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
+ bmtool-0.5.7.1.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
+ bmtool-0.5.7.1.dist-info/RECORD,,