1212import sys
1313import time
1414from pathlib import Path
15- from typing import Any , Optional , Union
15+ from typing import Any
1616
1717import libensemble .utils .launcher as launcher
1818from libensemble .message_numbers import (
2424 WORKER_DONE ,
2525 WORKER_KILL_ON_TIMEOUT ,
2626)
27- from libensemble .resources .resources import Resources
2827from libensemble .utils .timer import TaskTimer
2928
3029logger = logging .getLogger (__name__ )
@@ -78,10 +77,10 @@ class Application:
7877 def __init__ (
7978 self ,
8079 full_path : str ,
81- name : Optional [ str ] = None ,
82- calc_type : Optional [ str ] = "sim" ,
83- desc : Optional [ str ] = None ,
84- pyobj : Optional [ Any ] = None , # used by balsam_executor to store ApplicationDefinition
80+ name : str | None = None ,
81+ calc_type : str | None = "sim" ,
82+ desc : str | None = None ,
83+ pyobj : Any | None = None , # used by balsam_executor to store ApplicationDefinition
8584 precedent : str = "" ,
8685 ) -> None :
8786 """Instantiates a new Application instance."""
@@ -101,7 +100,7 @@ def __init__(
101100 self .app_cmd = " " .join (filter (None , [self .precedent , self .full_path ]))
102101
103102
104- def jassert (test : Optional [ Union [ Application , bool ]] , * args ) -> None :
103+ def jassert (test : Application | bool | None , * args ) -> None :
105104 "Version of assert that raises a ExecutorException"
106105 if not test :
107106 raise ExecutorException (* args )
@@ -170,7 +169,7 @@ def _add_to_env(self, key, value):
170169 """Add to task environment - overwrites if already set"""
171170 self .env [key ] = value
172171
173- def workdir_exists (self ) -> Optional [ bool ] :
172+ def workdir_exists (self ) -> bool | None :
174173 """Returns true if the task's workdir exists"""
175174 return self .workdir and os .path .exists (self .workdir )
176175
@@ -260,7 +259,7 @@ def poll(self) -> None:
260259
261260 self ._set_complete ()
262261
263- def wait (self , timeout : Optional [ float ] = None ) -> None :
262+ def wait (self , timeout : float | None = None ) -> None :
264263 """Waits on completion of the task or raises TimeoutExpired exception
265264
266265 Status attributes of task are updated on completion.
@@ -288,7 +287,7 @@ def wait(self, timeout: Optional[float] = None) -> None:
288287
289288 self ._set_complete ()
290289
291- def result (self , timeout : Optional [ Union [ int , float ]] = None ) -> str :
290+ def result (self , timeout : int | float | None = None ) -> str :
292291 """Wrapper for task.wait() that also returns the task's status on completion.
293292
294293 Parameters
@@ -303,7 +302,7 @@ def result(self, timeout: Optional[Union[int, float]] = None) -> str:
303302 self .wait (timeout = timeout )
304303 return self .state
305304
306- def exception (self , timeout : Optional [ Union [ int , float ]] = None ):
305+ def exception (self , timeout : int | float | None = None ):
307306 """Wrapper for task.wait() that instead returns the task's error code on completion.
308307
309308 Parameters
@@ -386,7 +385,7 @@ class Executor:
386385
387386 executor = None
388387
389- def _wait_on_start (self , task : Task , fail_time : Optional [ int ] = None ) -> None :
388+ def _wait_on_start (self , task : Task , fail_time : int | None = None ) -> None :
390389 """Called by submit when wait_on_start is True.
391390
392391 Blocks until task polls as having started.
@@ -472,7 +471,7 @@ def default_app(self, calc_type: str) -> Application:
472471 jassert (app , f"Default { calc_type } app is not set" )
473472 return app
474473
475- def set_resources (self , resources : Resources ):
474+ def set_resources (self , resources ):
476475 # Does not use resources
477476 pass
478477
@@ -493,9 +492,9 @@ def set_gen_procs_gpus(self, libE_info):
493492 def register_app (
494493 self ,
495494 full_path : str ,
496- app_name : Optional [ str ] = None ,
497- calc_type : Optional [ str ] = None ,
498- desc : Optional [ str ] = None ,
495+ app_name : str | None = None ,
496+ calc_type : str | None = None ,
497+ desc : str | None = None ,
499498 precedent : str = "" ,
500499 ) -> None :
501500 """Registers a user application to libEnsemble.
@@ -571,7 +570,7 @@ def manager_kill_received(self) -> bool:
571570 return False
572571
573572 def polling_loop (
574- self , task : Task , timeout : Optional [ int ] = None , delay : float = 0.1 , poll_manager : bool = False
573+ self , task : Task , timeout : int | None = None , delay : float = 0.1 , poll_manager : bool = False
575574 ) -> int :
576575 """Optional, blocking, generic task status polling loop. Operates until the task
577576 finishes, times out, or is optionally killed via a manager signal. On completion, returns a
@@ -637,7 +636,7 @@ def polling_loop(
637636
638637 return calc_status
639638
640- def get_task (self , taskid : Union [ str , int ] ) -> Optional [ Task ] :
639+ def get_task (self , taskid : str | int ) -> Task | None :
641640 """Returns the task object for the supplied task ID"""
642641 task = next ((j for j in self .list_of_tasks if j .id == taskid ), None )
643642 if task is None :
@@ -681,14 +680,14 @@ def _check_app_exists(self, full_path: str) -> None:
681680
682681 def submit (
683682 self ,
684- calc_type : Optional [ str ] = None ,
685- app_name : Optional [ str ] = None ,
686- app_args : Optional [ str ] = None ,
687- stdout : Optional [ str ] = None ,
688- stderr : Optional [ str ] = None ,
689- dry_run : Optional [ bool ] = False ,
690- wait_on_start : Optional [ bool ] = False ,
691- env_script : Optional [ str ] = None ,
683+ calc_type : str | None = None ,
684+ app_name : str | None = None ,
685+ app_args : str | None = None ,
686+ stdout : str | None = None ,
687+ stderr : str | None = None ,
688+ dry_run : bool | None = False ,
689+ wait_on_start : bool | None = False ,
690+ env_script : str | None = None ,
692691 ) -> Task :
693692 """Create a new task and run as a local serial subprocess.
694693
0 commit comments