@@ -31,13 +31,11 @@ def is_dll(path: os.PathLike) -> bool:
31
31
return suffix in {'.so' , '.dll' }
32
32
33
33
34
- def install_path_to_cadet_paths (
35
- install_path : Optional [os .PathLike ],
34
+ def resolve_cadet_paths (
35
+ install_path : Optional [os .PathLike ]
36
36
) -> tuple [Optional [Path ], Optional [Path ], Optional [Path ], Optional [Path ]]:
37
37
"""
38
- Get the correct paths (root_path, cadet_cli_path, cadet_dll_path, cadet_create_lwe_path)
39
- from the installation path of CADET. This is extracted into a function to be used
40
- in both the meta class and the cadet class itself.
38
+ Resolve paths from the installation path of CADET.
41
39
42
40
Parameters
43
41
----------
@@ -48,7 +46,7 @@ def install_path_to_cadet_paths(
48
46
Returns
49
47
-------
50
48
tuple[Optional[Path], Optional[Path], Optional[Path], Optional[Path]]
51
- Tuple with CADET installation paths
49
+ tuple with CADET installation paths
52
50
(root_path, cadet_cli_path, cadet_dll_path, cadet_create_lwe_path)
53
51
"""
54
52
if install_path is None :
@@ -75,16 +73,16 @@ def install_path_to_cadet_paths(
75
73
lwe_executable += '.exe'
76
74
77
75
cadet_cli_path = cadet_root / 'bin' / cli_executable
78
- if cadet_cli_path .is_file ():
79
- cadet_cli_path = cadet_cli_path
80
- else :
76
+ if not cadet_cli_path .is_file ():
81
77
raise FileNotFoundError (
82
- "CADET could not be found. Please check the path."
78
+ "CADET CLI could not be found. Please check the path."
83
79
)
84
80
85
81
cadet_create_lwe_path = cadet_root / 'bin' / lwe_executable
86
- if cadet_create_lwe_path .is_file ():
87
- cadet_create_lwe_path = cadet_create_lwe_path .as_posix ()
82
+ if not cadet_create_lwe_path .is_file ():
83
+ raise FileNotFoundError (
84
+ "CADET createLWE could not be found. Please check the path."
85
+ )
88
86
89
87
if platform .system () == 'Windows' :
90
88
dll_path = cadet_root / 'bin' / 'cadet.dll'
@@ -97,10 +95,7 @@ def install_path_to_cadet_paths(
97
95
if not dll_path .is_file () and dll_debug_path .is_file ():
98
96
dll_path = dll_debug_path
99
97
100
- if dll_path .is_file ():
101
- cadet_dll_path = dll_path
102
- else :
103
- cadet_dll_path = None
98
+ cadet_dll_path = dll_path if dll_path .is_file () else None
104
99
105
100
return root_path , cadet_cli_path , cadet_dll_path , cadet_create_lwe_path
106
101
@@ -112,6 +107,7 @@ class CadetMeta(type):
112
107
This meta class allows setting the `cadet_path` attribute for all instances of the
113
108
`Cadet` class.
114
109
"""
110
+
115
111
use_dll = False
116
112
cadet_cli_path = None
117
113
cadet_dll_path = None
@@ -166,9 +162,10 @@ def cadet_path(cls, cadet_path: Optional[os.PathLike]) -> None:
166
162
167
163
cls .use_dll = cadet_path .suffix in [".dll" , ".so" ]
168
164
169
- _install_path , cadet_cli_path , cadet_dll_path , cadet_create_lwe_path = install_path_to_cadet_paths (cadet_path )
165
+ install_path , cadet_cli_path , cadet_dll_path , cadet_create_lwe_path = \
166
+ resolve_cadet_paths (cadet_path )
170
167
171
- cls ._install_path = _install_path
168
+ cls ._install_path = install_path
172
169
cls .cadet_create_lwe_path = cadet_create_lwe_path
173
170
cls .cadet_cli_path = cadet_cli_path
174
171
cls .cadet_dll_path = cadet_dll_path
@@ -178,8 +175,9 @@ class Cadet(H5, metaclass=CadetMeta):
178
175
"""
179
176
CADET interface class.
180
177
181
- This class manages the CADET runner, whether it's based on a CLI executable or a DLL,
182
- and provides methods for running simulations and loading results.
178
+ This class manages the CADET runner, whether it's based on the CLI executable or
179
+ the in-memory interface and provides methods for running simulations and loading
180
+ results.
183
181
184
182
Attributes
185
183
----------
@@ -195,9 +193,15 @@ class Cadet(H5, metaclass=CadetMeta):
195
193
Stores the information returned after a simulation run.
196
194
"""
197
195
198
- def __init__ (self , install_path : Optional [Path ] = None , use_dll : bool = False , * data ):
196
+ def __init__ (
197
+ self ,
198
+ install_path : Optional [Path ] = None ,
199
+ use_dll : bool = False ,
200
+ * data
201
+ ) -> None :
199
202
"""
200
203
Initialize a new instance of the Cadet class.
204
+
201
205
Priority order of install_paths is:
202
206
1. install_path set in __init__ args
203
207
2. install_path set in CadetMeta
@@ -216,13 +220,14 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
216
220
self ._cadet_cli_runner : Optional [CadetCLIRunner ] = None
217
221
self ._cadet_dll_runner : Optional [CadetDLLRunner ] = None
218
222
219
- # Regardless of settings in the Meta Class, if we get an install_path, we respect the install_path
223
+ # Regardless of settings in the Meta Class, if we get an install_path, we
224
+ # respect the install_path
220
225
if install_path is not None :
221
226
self .use_dll = use_dll
222
- self .install_path = install_path # This will set _cadet_dll_runner and _cadet_cli_runner
227
+ self .install_path = install_path # This will automatically set the runners.
223
228
return
224
229
225
- # If _cadet_cli_runner_class has been set in the Meta Class, use them, else instantiate Nones
230
+ # Use CLIRunner of the Meta class, if provided.
226
231
if hasattr (self , "cadet_cli_path" ) and self .cadet_cli_path is not None :
227
232
self ._cadet_cli_runner : Optional [CadetCLIRunner ] = CadetCLIRunner (
228
233
self .cadet_cli_path
@@ -231,6 +236,7 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
231
236
self ._cadet_cli_runner : Optional [CadetCLIRunner ] = None
232
237
self .use_dll = use_dll
233
238
239
+ # Use DLLRunner of the Meta class, if provided.
234
240
if hasattr (self , "cadet_dll_path" ) and self .cadet_dll_path is not None :
235
241
try :
236
242
self ._cadet_dll_runner : Optional [CadetDLLRunner ] = CadetDLLRunner (
@@ -244,11 +250,10 @@ def __init__(self, install_path: Optional[Path] = None, use_dll: bool = False, *
244
250
self ._cadet_dll_runner : Optional [CadetCLIRunner ] = None
245
251
self .use_dll = use_dll
246
252
247
- # If any runner has been set in the Meta Class, don't auto-detect Cadet, just return
248
253
if self ._cadet_cli_runner is not None or self ._cadet_dll_runner is not None :
249
254
return
250
255
251
- # If neither Meta Class nor install_path are given: auto-detect Cadet
256
+ # Auto-detect Cadet if neither Meta Class nor install_path are given.
252
257
self .install_path = self .autodetect_cadet ()
253
258
254
259
@property
@@ -271,7 +276,7 @@ def install_path(self, install_path: Optional[os.PathLike]) -> None:
271
276
Parameters
272
277
----------
273
278
install_path : Optional[os.PathLike]
274
- Path to the root of the CADET installation or the executable file 'cadet-cli'.
279
+ Path to the root of the CADET installation or the 'cadet-cli' executable .
275
280
If a file path is provided, the root directory will be inferred.
276
281
"""
277
282
if install_path is None :
@@ -281,7 +286,8 @@ def install_path(self, install_path: Optional[os.PathLike]) -> None:
281
286
self .cadet_create_lwe_path = None
282
287
return
283
288
284
- root_path , cadet_cli_path , cadet_dll_path , create_lwe_path = install_path_to_cadet_paths (install_path )
289
+ root_path , cadet_cli_path , cadet_dll_path , create_lwe_path = \
290
+ resolve_cadet_paths (install_path )
285
291
286
292
self ._install_path = root_path
287
293
self .cadet_create_lwe_path = create_lwe_path
@@ -376,7 +382,6 @@ def cadet_runner(self) -> CadetRunnerBase:
376
382
Optional[CadetRunnerBase]
377
383
The current runner instance, either a DLL or file-based runner.
378
384
"""
379
-
380
385
if self .use_dll and self .found_dll :
381
386
return self ._cadet_dll_runner
382
387
@@ -422,10 +427,10 @@ def create_lwe(self, file_path=None):
422
427
423
428
self .filename = file_path
424
429
425
- self .load ()
430
+ self .load_from_file ()
426
431
427
432
if file_path_input is None :
428
- os . remove ( file_path )
433
+ self . delete_file ( )
429
434
430
435
return self
431
436
@@ -487,20 +492,53 @@ def run_load(
487
492
timeout : Optional[int]
488
493
Maximum time allowed for the simulation to run, in seconds.
489
494
clear : bool
490
- If True, clear previous results after loading new ones .
495
+ If True, clear the simulation results from the current runner instance .
491
496
492
497
Returns
493
498
-------
494
499
ReturnInformation
495
500
Information about the simulation run.
496
501
"""
497
- return_information = self .run (timeout )
502
+ warnings .warn (
503
+ "Cadet.run_load() will be removed in a future release. "
504
+ "Please use Cadet.run_simulation()" ,
505
+ category = FutureWarning
506
+ )
507
+ return_information = self .run_simulation (timeout = timeout , clear = clear )
508
+
509
+ return return_information
510
+
511
+ def run_simulation (
512
+ self ,
513
+ timeout : Optional [int ] = None ,
514
+ clear : bool = True
515
+ ) -> ReturnInformation :
516
+ """
517
+ Run the CADET simulation and load the results.
518
+
519
+ Parameters
520
+ ----------
521
+ timeout : Optional[int]
522
+ Maximum time allowed for the simulation to run, in seconds.
523
+ clear : bool
524
+ If True, clear the simulation results from the current runner instance.
525
+
526
+ Returns
527
+ -------
528
+ ReturnInformation
529
+ Information about the simulation run.
530
+ """
531
+ return_information = self .cadet_runner .run (
532
+ simulation = self ,
533
+ timeout = timeout
534
+ )
498
535
499
536
if return_information .return_code == 0 :
500
- self .load_results ()
537
+ self .cadet_runner . load_results (self )
501
538
502
539
if clear :
503
540
self .clear ()
541
+
504
542
return return_information
505
543
506
544
def run (
@@ -520,6 +558,11 @@ def run(
520
558
ReturnInformation
521
559
Information about the simulation run.
522
560
"""
561
+ warnings .warn (
562
+ "Cadet.run() will be removed in a future release. \n "
563
+ "Please use Cadet.run_simulation()" ,
564
+ category = FutureWarning
565
+ )
523
566
return_information = self .cadet_runner .run (
524
567
self ,
525
568
timeout = timeout ,
@@ -529,23 +572,32 @@ def run(
529
572
530
573
def load_results (self ) -> None :
531
574
"""Load the results of the last simulation run into the current instance."""
532
- runner = self .cadet_runner
533
- if runner is not None :
534
- runner .load_results (self )
575
+ warnings .warn (
576
+ "Cadet.load_results() will be removed in a future release. \n "
577
+ "Please use Cadet.load_from_file() to load results from a file "
578
+ "or use Cadet.run_simulation() to run a simulation and directly load the "
579
+ "simulation results." ,
580
+ category = FutureWarning
581
+ )
582
+ self .load_from_file ()
583
+
584
+ def load (self ) -> None :
585
+ """Load the results of the last simulation run into the current instance."""
586
+ warnings .warn (
587
+ "Cadet.load() will be removed in a future release. \n "
588
+ "Please use Cadet.load_from_file() to load results from a file or use "
589
+ "Cadet.run_simulation() to run a simulation and directly load the "
590
+ "simulation results." ,
591
+ category = FutureWarning
592
+ )
593
+ self .load_from_file ()
535
594
536
595
def clear (self ) -> None :
537
- """Clear the loaded results from the current instance."""
596
+ """Clear the simulation results from the current runner instance."""
538
597
runner = self .cadet_runner
539
598
if runner is not None :
540
599
runner .clear ()
541
600
542
- def delete_file (self ) -> None :
543
- if self .filename is not None :
544
- try :
545
- os .remove (self .filename )
546
- except FileNotFoundError :
547
- pass
548
-
549
601
def __del__ (self ):
550
602
self .clear ()
551
603
del self ._cadet_dll_runner
0 commit comments