Optimization

Optimization#

%pylab inline --no-import-all
from gpe import bec
from gpe.bec import u
from pytimeode.evolvers import EvolverABM

s = bec.State(
    Nxyz=(2**9, 2**7, 2**7), Lxyz=(80 * u.micron, 45 * u.micron, 45 * u.micron)
)
# state = bec.State(Nxyz=(2**8, 2**5, 2**5), Lxyz=(80*u.micron, 30*u.micron, 30*u.micron))
e = EvolverABM(s, dt=0.1 * s.t_scale)
%time e.evolve(5)
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[1], line 10
      6 s = bec.State(
      7     Nxyz=(2**9, 2**7, 2**7), Lxyz=(80 * u.micron, 45 * u.micron, 45 * u.micron)
      8 )
      9 # state = bec.State(Nxyz=(2**8, 2**5, 2**5), Lxyz=(80*u.micron, 30*u.micron, 30*u.micron))
---> 10 e = EvolverABM(s, dt=0.1 * s.t_scale)
     11 get_ipython().run_line_magic('time', 'e.evolve(5)')

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/evolvers.py:352, in EvolverABM.__init__(self, y, dt, t, mu, no_runge_kutta, **kw)
    350 self.dcps = None
    351 self.dys = None
--> 352 super().__init__(y=y, dt=dt, t=t, **kw)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/evolvers.py:84, in EvolverBase.__init__(self, y, dt, t, normalize, copy)
     81 else:
     82     self._apply = False
---> 84 Object.__init__(self)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/utils/__init__.py:72, in Object.__init__(self)
     70 def __init__(self):
     71     self.picklable_attributes = [_k for _k in self.__dict__]
---> 72     self.init()

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/evolvers.py:387, in EvolverABM.init(self)
    384 m = "((y0+y1)/2 + h/48*(119*dy0-99*dy1+69*dy2-17*dy3) + dcp0)"
    385 dcp = "h*161/48/170*(17*dm-68*dy0+102*dy1-68*dy2+17*dy3)"
    386 self._expr_m = self.y.Expression(
--> 387     expr.simplify(m, constants=constants),
    388     dtype=y0.dtype,
    389     args=["y0", "y1", "dy0", "dy1", "dy2", "dy3", "dcp0"],
    390 )
    391 self._expr_dcp = self.y.Expression(
    392     expr.simplify(dcp, constants=constants),
    393     dtype=y0.dtype,
    394     args=["dm", "dy0", "dy1", "dy2", "dy3"],
    395 )
    397 self._expr_y = self.y.Expression(
    398     "m + dcp - dcp0", dtype=y0.dtype, args=["m", "dcp", "dcp0"]
    399 )

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/utils/expr.py:102, in simplify(sexpr, constants, simplify)
    100 constants = clean_constants(constants)
    101 if sympy is not None:
--> 102     expr = sympy_simplify(sexpr, constants=constants, simplify=simplify)
    103 else:
    104     for _k in _SYMPY_REPLACEMENTS:

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/pytimeode/utils/expr.py:74, in sympy_simplify(sexpr, constants, simplify)
     58 def sympy_simplify(sexpr, constants=None, simplify=True):
     59     """Return `expr` valid for IExpression.expr.
     60 
     61     * Uses sympy to do some simplification and replacement of constants.
   (...)     72        otherwise just convert it.
     73     """
---> 74     sexpr = sympy.S(sexpr).subs(clean_constants(constants))
     75     if simplify:
     76         sexpr = sympy.simplify(sexpr.evalf())

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/sympify.py:507, in sympify(a, locals, convert_xor, strict, rational, evaluate)
    505 try:
    506     a = a.replace('\n', '')
--> 507     expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
    508 except (TokenError, SyntaxError) as exc:
    509     raise SympifyError('could not parse %r' % a, exc)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/parsing/sympy_parser.py:1081, in parse_expr(s, local_dict, transformations, global_dict, evaluate)
   1078     code = compile(evaluateFalse(code), '<string>', 'eval') # type: ignore
   1080 try:
-> 1081     rv = eval_expr(code, local_dict, global_dict)
   1082     # restore neutral definitions for names
   1083     for i in local_dict.pop(null, ()):

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/parsing/sympy_parser.py:905, in eval_expr(code, local_dict, global_dict)
    899 def eval_expr(code, local_dict: DICT, global_dict: DICT):
    900     """
    901     Evaluate Python code generated by ``stringify_expr``.
    902 
    903     Generally, ``parse_expr`` should be used.
    904     """
--> 905     expr = eval(
    906         code, global_dict, local_dict)  # take local objects in preference
    907     return expr

File <string>:1
----> 1 'Could not get source, probably due dynamically evaluated source code.'

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/decorators.py:248, in _SympifyWrapper.make_wrapped.<locals>._func(self, other)
    246 if not isinstance(other, expectedcls):
    247     return retval
--> 248 return func(self, other)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/decorators.py:118, in call_highest_priority.<locals>.priority_decorator.<locals>.binary_op_wrapper(self, other)
    116         if f is not None:
    117             return f(self)
--> 118 return func(self, other)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/expr.py:234, in Expr.__add__(self, other)
    231 @sympify_return([('other', 'Expr')], NotImplemented)
    232 @call_highest_priority('__radd__')
    233 def __add__(self, other) -> Expr:
--> 234     return Add(self, other)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/cache.py:72, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     69 @wraps(func)
     70 def wrapper(*args, **kwargs):
     71     try:
---> 72         retval = cfunc(*args, **kwargs)
     73     except TypeError as e:
     74         if not e.args or not e.args[0].startswith('unhashable type:'):

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/operations.py:108, in AssocOp.__new__(cls, evaluate, _sympify, *args)
    105 if len(args) == 1:
    106     return args[0]
--> 108 c_part, nc_part, order_symbols = cls.flatten(args)
    109 is_commutative = not nc_part
    110 obj = cls._from_args(c_part + nc_part, is_commutative)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/add.py:217, in Add.flatten(cls, seq)
    215 from sympy.calculus.accumulationbounds import AccumBounds
    216 from sympy.matrices.expressions import MatrixExpr
--> 217 from sympy.tensor.tensor import TensExpr, TensAdd
    218 rv = None
    219 if len(seq) == 2:

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/tensor/tensor.py:43
     40 import itertools
     42 from sympy.core.numbers import (Integer, Rational)
---> 43 from sympy.combinatorics import Permutation
     44 from sympy.combinatorics.tensor_can import get_symmetric_group_sgs, \
     45     bsgs_direct_product, canonicalize, riemann_bsgs
     46 from sympy.core import Basic, Expr, sympify, Add, Mul, S

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/combinatorics/__init__.py:7
      4 from sympy.combinatorics.subsets import Subset
      5 from sympy.combinatorics.partitions import (Partition, IntegerPartition,
      6     RGS_rank, RGS_unrank, RGS_enum)
----> 7 from sympy.combinatorics.polyhedron import (Polyhedron, tetrahedron, cube,
      8     octahedron, dodecahedron, icosahedron)
      9 from sympy.combinatorics.perm_groups import PermutationGroup, Coset, SymmetricPermutationGroup
     10 from sympy.combinatorics.group_constructs import DirectProduct

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/combinatorics/polyhedron.py:955
    881 octahedron = Polyhedron(
    882     Tuple(0, 1, 2, 3, 4, 5),
    883     Tuple(
   (...)    904         Perm(0, 2, 3)(1, 5, 4),
    905         Perm(0, 4, 3)(1, 5, 2)))
    907 dodecahedron = Polyhedron(
    908     Tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
    909     Tuple(
   (...)    952         Perm(0, 11, 15)(1, 17, 14)(2, 18, 9)(3, 12, 13)(4, 7, 19)(5, 6, 16),
    953         Perm(0, 8, 15)(1, 12, 16)(2, 18, 10)(3, 19, 5)(4, 13, 14)(6, 7, 17)))
--> 955 icosahedron = Polyhedron(
    956     Tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
    957     Tuple(
    958         Tuple(0, 1, 2),
    959         Tuple(0, 2, 3),
    960         Tuple(0, 3, 4),
    961         Tuple(0, 4, 5),
    962         Tuple(0, 1, 5),
    963         Tuple(1, 6, 7),
    964         Tuple(1, 2, 7),
    965         Tuple(2, 7, 8),
    966         Tuple(2, 3, 8),
    967         Tuple(3, 8, 9),
    968         Tuple(3, 4, 9),
    969         Tuple(4, 9, 10),
    970         Tuple(4, 5, 10),
    971         Tuple(5, 6, 10),
    972         Tuple(1, 5, 6),
    973         Tuple(6, 7, 11),
    974         Tuple(7, 8, 11),
    975         Tuple(8, 9, 11),
    976         Tuple(9, 10, 11),
    977         Tuple(6, 10, 11)),
    978     Tuple(
    979         Perm(11)(1, 2, 3, 4, 5)(6, 7, 8, 9, 10),
    980         Perm(0, 5, 6, 7, 2)(3, 4, 10, 11, 8),
    981         Perm(0, 1, 7, 8, 3)(4, 5, 6, 11, 9),
    982         Perm(0, 2, 8, 9, 4)(1, 7, 11, 10, 5),
    983         Perm(0, 3, 9, 10, 5)(1, 2, 8, 11, 6),
    984         Perm(0, 4, 10, 6, 1)(2, 3, 9, 11, 7),
    985         Perm(0, 1)(2, 5)(3, 6)(4, 7)(8, 10)(9, 11),
    986         Perm(0, 2)(1, 3)(4, 7)(5, 8)(6, 9)(10, 11),
    987         Perm(0, 3)(1, 9)(2, 4)(5, 8)(6, 11)(7, 10),
    988         Perm(0, 4)(1, 9)(2, 10)(3, 5)(6, 8)(7, 11),
    989         Perm(0, 5)(1, 4)(2, 10)(3, 6)(7, 9)(8, 11),
    990         Perm(0, 6)(1, 5)(2, 10)(3, 11)(4, 7)(8, 9),
    991         Perm(0, 7)(1, 2)(3, 6)(4, 11)(5, 8)(9, 10),
    992         Perm(0, 8)(1, 9)(2, 3)(4, 7)(5, 11)(6, 10),
    993         Perm(0, 9)(1, 11)(2, 10)(3, 4)(5, 8)(6, 7),
    994         Perm(0, 10)(1, 9)(2, 11)(3, 6)(4, 5)(7, 8),
    995         Perm(0, 11)(1, 6)(2, 10)(3, 9)(4, 8)(5, 7),
    996         Perm(0, 11)(1, 8)(2, 7)(3, 6)(4, 10)(5, 9),
    997         Perm(0, 11)(1, 10)(2, 9)(3, 8)(4, 7)(5, 6),
    998         Perm(0, 11)(1, 7)(2, 6)(3, 10)(4, 9)(5, 8),
    999         Perm(0, 11)(1, 9)(2, 8)(3, 7)(4, 6)(5, 10),
   1000         Perm(0, 5, 1)(2, 4, 6)(3, 10, 7)(8, 9, 11),
   1001         Perm(0, 1, 2)(3, 5, 7)(4, 6, 8)(9, 10, 11),
   1002         Perm(0, 2, 3)(1, 8, 4)(5, 7, 9)(6, 11, 10),
   1003         Perm(0, 3, 4)(1, 8, 10)(2, 9, 5)(6, 7, 11),
   1004         Perm(0, 4, 5)(1, 3, 10)(2, 9, 6)(7, 8, 11),
   1005         Perm(0, 10, 7)(1, 5, 6)(2, 4, 11)(3, 9, 8),
   1006         Perm(0, 6, 8)(1, 7, 2)(3, 5, 11)(4, 10, 9),
   1007         Perm(0, 7, 9)(1, 11, 4)(2, 8, 3)(5, 6, 10),
   1008         Perm(0, 8, 10)(1, 7, 6)(2, 11, 5)(3, 9, 4),
   1009         Perm(0, 9, 6)(1, 3, 11)(2, 8, 7)(4, 10, 5)))
   1011 tetrahedron_faces = [tuple(arg) for arg in tetrahedron.faces]
   1013 cube_faces = [tuple(arg) for arg in cube.faces]

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/combinatorics/polyhedron.py:388, in Polyhedron.__new__(cls, corners, faces, pgroup)
     34 def __new__(cls, corners, faces=(), pgroup=()):
     35     """
     36     The constructor of the Polyhedron group object.
     37 
   (...)    386 
    387     """
--> 388     faces = [minlex(f, directed=False, key=default_sort_key) for f in faces]
    389     corners, faces, pgroup = args = \
    390         [Tuple(*a) for a in (corners, faces, pgroup)]
    391     obj = Basic.__new__(cls, *args)

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/utilities/iterables.py:2655, in minlex(seq, directed, key)
   2653 from sympy.functions.elementary.miscellaneous import Id
   2654 if key is None: key = Id
-> 2655 best = rotate_left(seq, least_rotation(seq, key=key))
   2656 if not directed:
   2657     rseq = seq[::-1]

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/utilities/iterables.py:1199, in least_rotation(x, key)
   1197     i = f[i]
   1198 if sj != S[k+i+1]:
-> 1199     if key(sj) < key(S[k]):
   1200         k = j
   1201     f[j-k] = -1

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/sorting.py:127, in default_sort_key(item, order)
    124 from .singleton import S
    126 if isinstance(item, Basic):
--> 127     return item.sort_key(order=order)
    129 if iterable(item, exclude=str):
    130     if isinstance(item, dict):

File ~/checkouts/readthedocs.org/user_builds/gpe/conda/latest/lib/python3.14/site-packages/sympy/core/cache.py:69, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     66 def func_wrapper(func):
     67     cfunc = lru_cache(maxsize, typed=True)(func)
---> 69     @wraps(func)
     70     def wrapper(*args, **kwargs):
     71         try:
     72             retval = cfunc(*args, **kwargs)

KeyboardInterrupt: 
%pylab inline --no-import-all
from gpe import bec

reload(bec)
from gpe.bec import u
from pytimeode.evolvers import EvolverABM

s = bec.State(
    Nxyz=(2**9, 2**7, 2**7), Lxyz=(80 * u.micron, 45 * u.micron, 45 * u.micron)
)
# state = bec.State(Nxyz=(2**8, 2**5, 2**5), Lxyz=(80*u.micron, 30*u.micron, 30*u.micron))
e = EvolverABM(s, dt=0.1 * s.t_scale)
%time e.evolve(5)