2020import numpy as np
2121import sympy
2222from interruptingcow import timeout
23+ import os
24+ from . import libinflx_rs
2325from joblib import Parallel , cpu_count , delayed
2426from sympy .simplify import sqrtdenest
2527from sympy .vector import Gradient
@@ -140,6 +142,9 @@ def new(
140142 This class will automatically derive names for the derivatives of the fields (these are
141143 used by other inflatox components when solving the equations of motion).
142144
145+ Simplifications are currently disabled on windows due to their time-out system relying on
146+ UNIX signals.
147+
143148 ### Args
144149 - `fields` (`list[sympy.Symbol]`): list of sympy symbols that should be
145150 interpreted as fields (coordinates on the scalar manifold).
@@ -156,7 +161,9 @@ def new(
156161 - `assertions` (`bool`, *optional*): if False, expensive intermediate
157162 assertions will be disabled. Defaults to False.
158163 - `simplify` (`bool`, *optional*): When `True` `sympy`'s simplify method will be used.
159- Defaults to `True`.
164+ Due to the time-out system for simplifications relying on UNIX signals, simplifications
165+ cannot be turned on on Windows. If you set `simplify` to `True` on Windows it will be
166+ ignored. Defaults to `True` (except on Windows platforms).
160167 - `simplify_timeout` (`float`, *optional*): time-out time in seconds for simplification
161168 steps.
162169
@@ -167,6 +174,21 @@ def new(
167174 if init_sympy_printing :
168175 sympy .init_printing ()
169176
177+ if simplify == True and os .name == "nt" :
178+ libinflx_rs .log_warn (
179+ "cannot use simplifications on Windows. Continuing without simplifications."
180+ )
181+ return cls (
182+ fields = fields ,
183+ field_metric = field_metric ,
184+ potential = potential ,
185+ model_name = model_name if model_name is not None else "generic model" ,
186+ silent = silent ,
187+ assertions = assertions ,
188+ simplify = False ,
189+ simplify_timeout = 0.0 ,
190+ )
191+
170192 return cls (
171193 fields = fields ,
172194 field_metric = field_metric ,
@@ -208,7 +230,7 @@ def __init__(
208230
209231 def simplify_expr (self , expr : sympy .Expr ) -> sympy .Expr :
210232 """simplifies expression"""
211- if not self .simplify :
233+ if not self .simplify or os . name == "nt" :
212234 return expr
213235 try :
214236 with timeout (self .simplify_timeout , exception = SimplificationTimeOut ):
@@ -220,7 +242,7 @@ def simplify_expr(self, expr: sympy.Expr) -> sympy.Expr:
220242
221243 def expand_and_factor_expr (self , expr : sympy .Expr ) -> sympy .Expr :
222244 """`sympy.expand` followed by `sympy.factor` with a time-out"""
223- if not self .simplify :
245+ if not self .simplify or os . name == "nt" :
224246 return expr
225247 try :
226248 with timeout (self .simplify_timeout , exception = SimplificationTimeOut ):
@@ -232,7 +254,7 @@ def expand_and_factor_expr(self, expr: sympy.Expr) -> sympy.Expr:
232254
233255 def sqrt_and_denest_expr (self , expr : sympy .Expr ) -> sympy .Expr :
234256 """returns denested square root of expr (with timeout)"""
235- if not self .simplify :
257+ if not self .simplify or os . name == "nt" :
236258 return sympy .sqrt (expr )
237259 try :
238260 with timeout (self .simplify_timeout , exception = SimplificationTimeOut ):
@@ -527,6 +549,8 @@ def calc_gradient_square(self) -> sympy.Expr:
527549 for a in range (dim ):
528550 for b in range (dim ):
529551 out += metric_inv [a , b ] * gradient [a ] * gradient [b ]
552+ if os .name == "nt" :
553+ return self .simplify_expr (out )
530554 try :
531555 with timeout (self .simplify_timeout , exception = SimplificationTimeOut ):
532556 out = sympy .factor (sympy .expand (out ))
@@ -599,6 +623,9 @@ def gramm_schmidt(
599623 xdoty = self .inner_prod (x , y )
600624 for a in range (dim ):
601625 y [a ] -= xdoty * x [a ]
626+ # Disable simplification if we're on Windows
627+ if os .name == "nt" :
628+ return [self .simplify_expr (yi ) for yi in self .normalize (y )]
602629 try :
603630 with timeout (self .simplify_timeout , exception = SimplificationTimeOut ):
604631 y = [sympy .factor (sympy .expand (yi )) for yi in y ]
0 commit comments