def __init__( self, f_sym=(), n_lyap=-1, simplify=None, **kwargs ): self.n_basic = kwargs.pop("n",None) f_basic = self._handle_input(f_sym,n_basic=True) self._n_lyap = n_lyap if (0<=n_lyap<=self.n_basic) else self.n_basic if simplify is None: simplify = self.n_basic<=10 helpers = sort_helpers(sympify_helpers( kwargs.pop("helpers",[]) )) def f_lyap(): yield from f_basic() for i in range(self._n_lyap): for line in _jac_from_f_with_helpers( f = f_basic, helpers = helpers, simplify = False, n = self.n_basic ): expression = sum( entry * y(k+(i+1)*self.n_basic) for k,entry in enumerate(line) if entry ) if simplify: expression = expression.simplify(ratio=1.0) yield expression super(jitcode_lyap, self).__init__( f_lyap, helpers = helpers, n = self.n_basic*(self._n_lyap+1), **kwargs )
def __init__(self, f_sym=(), n_lyap=-1, simplify=None, **kwargs): self.n_basic = kwargs.pop("n", None) f_basic = self._handle_input(f_sym, n_basic=True) self._n_lyap = n_lyap if ( 0 <= n_lyap <= self.n_basic) else self.n_basic if self._n_lyap > 10: warn( "You are about to calculate %i Lyapunov exponents. This is very likely more than you need and may lead to severe difficulties with compilation and integration. Unless you really know what you are doing, consider how many Lyapunov exponents you actually need and set the parameter `n_lyap` accordingly." % self._n_lyap) if simplify is None: simplify = self.n_basic <= 10 helpers = sort_helpers(sympify_helpers(kwargs.pop("helpers", []))) def f_lyap(): yield from f_basic() for i in range(self._n_lyap): for line in _jac_from_f_with_helpers(f=f_basic, helpers=helpers, simplify=False, n=self.n_basic): expression = sum(entry * y(k + (i + 1) * self.n_basic) for k, entry in enumerate(line) if entry) if simplify: expression = expression.simplify(ratio=1.0) yield expression super(jitcode_lyap, self).__init__(f_lyap, helpers=helpers, n=self.n_basic * (self._n_lyap + 1), **kwargs)
def __init__(self, f_sym=(), n_lyap=-1, simplify=None, **kwargs): self.n_basic = kwargs.pop("n", None) f_basic = self._handle_input(f_sym, n_basic=True) self._n_lyap = n_lyap if ( 0 <= n_lyap <= self.n_basic) else self.n_basic if simplify is None: simplify = self.n_basic <= 10 helpers = sort_helpers(sympify_helpers(kwargs.pop("helpers", []))) def f_lyap(): yield from f_basic() for i in range(self._n_lyap): for line in _jac_from_f_with_helpers(f=f_basic, helpers=helpers, simplify=False, n=self.n_basic): expression = sum(entry * y(k + (i + 1) * self.n_basic) for k, entry in enumerate(line) if entry) if simplify: expression = expression.simplify(ratio=1.0) yield expression super(jitcode_lyap, self).__init__(f_lyap, helpers=helpers, n=self.n_basic * (self._n_lyap + 1), **kwargs)
def __init__(self, f_sym=(), groups=(), simplify=None, average_dynamics=False, **kwargs): GroupHandler.__init__(self, groups) self.n = kwargs.pop("n", None) f_basic, extracted = self.extract_main(self._handle_input(f_sym)) helpers = sort_helpers(sympify_helpers(kwargs.pop("helpers", []))) if simplify is None: simplify = self.n <= 10 z = symengine.Function("z") z_vector = [z(i) for i in range(self.n)] tangent_vector = self.back_transform(z_vector) def tangent_vector_f(): for line in _jac_from_f_with_helpers(f=f_basic, helpers=helpers, simplify=False, n=self.n): yield sum(entry * tangent_vector[k] for k, entry in enumerate(line) if entry) substitutions = {y(i): z(self.map_to_main(i)) for i in range(self.n)} def finalise(entry): entry = entry.subs(substitutions) if simplify: entry = entry.simplify(ratio=1) return replace_function(entry, z, y) if average_dynamics: f_list = list(f_basic()) def f_lyap(): for entry in self.iterate(tangent_vector_f()): if type(entry) == int: # i.e., if main index if average_dynamics: group = groups[entry] yield sum(finalise(f_list[i]) for i in group) / len(group) else: yield finalise(extracted[self.main_indices[entry]]) else: yield finalise(entry[0] - entry[1]) helpers = ((helper[0], finalise(helper[1])) for helper in helpers) super(jitcode_transversal_lyap, self).__init__(f_lyap, helpers=helpers, n=self.n, **kwargs)
def _arrange_helpers(self): """ Splits helpers into those needed by f and those needed by g. """ helpers = sort_helpers(sympify_helpers(self.helpers or [])) if self.g_helpers=="auto": f_needed = set().union(*(entry.free_symbols for entry in self.f_sym())) g_needed = set().union(*(entry.free_symbols for entry in self.g_sym())) self._f_helpers = filter_helpers(helpers,f_needed) self._g_helpers = filter_helpers(helpers,g_needed) else: self._f_helpers = helpers if self.g_helpers=="same": self._g_helpers = copy_helpers(helpers) else: self._g_helpers = sort_helpers(sympify_helpers(self.g_helpers or []))
def __init__( self, f_sym=(), groups=(), simplify=None, **kwargs ): GroupHandler.__init__(self,groups) self.n = kwargs.pop("n",None) f_basic,extracted = self.extract_main(self._handle_input(f_sym)) helpers = sort_helpers(sympify_helpers( kwargs.pop("helpers",[]) )) if simplify is None: simplify = self.n<=10 z = symengine.Function("z") z_vector = [z(i) for i in range(self.n)] tangent_vector = self.back_transform(z_vector) def tangent_vector_f(): for line in _jac_from_f_with_helpers( f = f_basic, helpers = helpers, simplify = False, n = self.n ): yield sum( entry * tangent_vector[k] for k,entry in enumerate(line) if entry ) substitutions = { y(i): z(self.map_to_main(i)) for i in range(self.n) } def finalise(entry): entry = entry.subs(substitutions) if simplify: entry = entry.simplify(ratio=1) return replace_function(entry,z,y) def f_lyap(): for entry in self.iterate(tangent_vector_f()): if type(entry)==int: yield finalise(extracted[self.main_indices[entry]]) else: yield finalise(entry[0]-entry[1]) helpers = ((helper[0],finalise(helper[1])) for helper in helpers) super(jitcode_transversal_lyap, self).__init__( f_lyap, helpers = helpers, n = self.n, **kwargs )
def __init__( self, f_sym=(), *, helpers=None, wants_jacobian=False, n=None, control_pars=(), callback_functions=(), verbose=True, module_location=None, ): jitcxde.__init__(self, n, verbose, module_location) self.f_sym = self._handle_input(f_sym) self._f_C_source = False self._jac_C_source = False self._helper_C_source = False self.helpers = sort_helpers(sympify_helpers(helpers or [])) self.control_pars = control_pars self.control_par_values = () self.callback_functions = callback_functions self._wants_jacobian = wants_jacobian self.integrator = empty_integrator() if self.jitced is None: self._initialise = None self.f = None self.jac = None else: # Load derivative and Jacobian if a compiled module has been provided self._initialise = self.jitced.initialise self.f = self.jitced.f self.jac = self.jitced.jac if hasattr(self.jitced, "jac") else None self._number_of_jac_helpers = None self._number_of_f_helpers = None self.general_subs = { control_par: symengine.Symbol("parameter_" + control_par.name) for control_par in self.control_pars }
def __init__(self, f_sym = (), helpers = None, wants_jacobian = False, n = None, control_pars = (), verbose = True, module_location = None, ): jitcxde.__init__(self,n,verbose,module_location) self.f_sym = self._handle_input(f_sym) self._f_C_source = False self._jac_C_source = False self._helper_C_source = False self.helpers = sort_helpers(sympify_helpers(helpers or [])) self.control_pars = control_pars self._wants_jacobian = wants_jacobian self.integrator = empty_integrator() if self.jitced is None: self.f = None self.jac = None else: # Load derivative and Jacobian if a compiled module has been provided self.f = self.jitced.f self.jac = self.jitced.jac if hasattr(self.jitced,"jac") else None self._number_of_jac_helpers = None self._number_of_f_helpers = None self.general_subs = { control_par: symengine.Symbol("parameter_"+control_par.name) for control_par in self.control_pars }