14
14
15
15
from ...components .simulation import Simulation
16
16
from ...components .data .monitor_data import ModeSolverData
17
+ from ...components .medium import AbstractCustomMedium
18
+ from ...components .types import Literal
17
19
from ...exceptions import WebError
18
20
from ...log import log , get_logging_console
19
21
from ..core .core_config import get_logger_console
@@ -46,7 +48,7 @@ def run(
46
48
verbose : bool = True ,
47
49
progress_callback_upload : Callable [[float ], None ] = None ,
48
50
progress_callback_download : Callable [[float ], None ] = None ,
49
- reduce_simulation : bool = True ,
51
+ reduce_simulation : Literal [ "auto" , True , False ] = "auto" ,
50
52
) -> ModeSolverData :
51
53
"""Submits a :class:`.ModeSolver` to server, starts running, monitors progress, downloads,
52
54
and loads results as a :class:`.ModeSolverData` object.
@@ -69,9 +71,9 @@ def run(
69
71
Optional callback function called when uploading file with ``bytes_in_chunk`` as argument.
70
72
progress_callback_download : Callable[[float], None] = None
71
73
Optional callback function called when downloading file with ``bytes_in_chunk`` as argument.
72
- reduce_simulation : bool = True
73
- Restrict simulation to mode solver region. This can help reduce the amount of uploaded and
74
- dowloaded data .
74
+ reduce_simulation : Literal["auto", True, False] = "auto"
75
+ Restrict simulation to mode solver region. If "auto", then simulation is automatically
76
+ restricted if it contains custom mediums .
75
77
76
78
Returns
77
79
-------
@@ -83,6 +85,21 @@ def run(
83
85
if verbose :
84
86
console = get_logging_console ()
85
87
88
+ if reduce_simulation == "auto" :
89
+ sim = mode_solver .simulation
90
+ contains_custom = any (isinstance (s .medium , AbstractCustomMedium ) for s in sim .structures )
91
+ contains_custom = contains_custom or isinstance (sim .medium , AbstractCustomMedium )
92
+ reduce_simulation = contains_custom
93
+
94
+ if reduce_simulation :
95
+ log .warning (
96
+ "The associated `Simulation` object contains custom mediums. It will be "
97
+ "automatically restricted to the mode solver plane to reduce data for uploading. "
98
+ "To force uploading the original `Simulation` object use `reduce_simulation=False`."
99
+ " Setting `reduce_simulation=True` will force simulation reduction in all cases and"
100
+ " silence this warning."
101
+ )
102
+
86
103
if reduce_simulation :
87
104
mode_solver = mode_solver .reduced_simulation_copy
88
105
0 commit comments