1414
1515from ...components .simulation import Simulation
1616from ...components .data .monitor_data import ModeSolverData
17+ from ...components .medium import AbstractCustomMedium
18+ from ...components .types import Literal
1719from ...exceptions import WebError
1820from ...log import log , get_logging_console
1921from ..core .core_config import get_logger_console
@@ -46,7 +48,7 @@ def run(
4648 verbose : bool = True ,
4749 progress_callback_upload : Callable [[float ], None ] = None ,
4850 progress_callback_download : Callable [[float ], None ] = None ,
49- reduce_simulation : bool = True ,
51+ reduce_simulation : Literal [ "auto" , True , False ] = "auto" ,
5052) -> ModeSolverData :
5153 """Submits a :class:`.ModeSolver` to server, starts running, monitors progress, downloads,
5254 and loads results as a :class:`.ModeSolverData` object.
@@ -69,9 +71,9 @@ def run(
6971 Optional callback function called when uploading file with ``bytes_in_chunk`` as argument.
7072 progress_callback_download : Callable[[float], None] = None
7173 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 .
7577
7678 Returns
7779 -------
@@ -83,6 +85,21 @@ def run(
8385 if verbose :
8486 console = get_logging_console ()
8587
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+
86103 if reduce_simulation :
87104 mode_solver = mode_solver .reduced_simulation_copy
88105
0 commit comments