pyMOTO 1.5.1__py3-none-any.whl → 1.5.1b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pymoto/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = '1.5.1'
1
+ __version__ = '1.5.1-beta1'
2
2
 
3
3
  from .common.domain import DomainDefinition
4
4
 
pymoto/common/domain.py CHANGED
@@ -288,7 +288,7 @@ class DomainDefinition:
288
288
  patch.set_path(self.get_path(x + u, y + v))
289
289
 
290
290
  # flake8: noqa: C901
291
- def write_to_vti(self, vectors: dict, filename="out.vti", scale=1.0, origin=(0.0, 0.0, 0.0)):
291
+ def write_to_vti(self, vectors: dict, filename="out.vti", scale=1.0):
292
292
  """ Write all given vectors to a Paraview (VTI) file
293
293
 
294
294
  The size of the vectors should be a multiple of ``nel`` or ``nnodes``. Based on their size they are marked as
@@ -300,7 +300,6 @@ class DomainDefinition:
300
300
  vectors: A dictionary of vectors to write. Keys are used as vector names.
301
301
  filename (str): The file loction
302
302
  scale: Uniform scaling of the gridpoints
303
- origin: Origin of the domain
304
303
  """
305
304
  ext = '.vti'
306
305
  if ext not in os.path.splitext(filename)[-1].lower():
@@ -337,7 +336,7 @@ class DomainDefinition:
337
336
  file.write(f"<ImageData WholeExtent=\"0 {self.nelx} 0 {self.nely} 0 {self.nelz}\"".encode())
338
337
 
339
338
  # Origin of domain
340
- file.write(f" Origin=\"{origin[0]*scale} {origin[1]*scale} {origin[2]*scale}\"".encode())
339
+ file.write(f" Origin=\"{self.origin[0]*scale} {self.origin[1]*scale} {self.origin[2]*scale}\"".encode())
341
340
 
342
341
  # Spacing of points (dx, dy, dz)
343
342
  dx, dy, dz = self.element_size[0:3]*scale
pymoto/core_objects.py CHANGED
@@ -5,6 +5,7 @@ import time
5
5
  import copy
6
6
  from typing import Union, List, Any
7
7
  from abc import ABC, abstractmethod
8
+ from collections.abc import Callable
8
9
  from .utils import _parse_to_list, _concatenate_to_array, _split_from_array
9
10
 
10
11
 
@@ -325,30 +326,54 @@ def _is_valid_module(mod: Any):
325
326
  return False
326
327
 
327
328
 
328
- def _check_function_signature(fn, signals):
329
+ # Type definition for bound method
330
+ class BoundMethod:
331
+ __self__: object
332
+
333
+
334
+ BoundMethodT = Union[Callable, BoundMethod]
335
+
336
+
337
+ def _check_function_signature(fn: BoundMethodT, signals: list = None) -> (int, int):
329
338
  """ Checks the function signature against given signal list
330
- :param fn: response_ or sensitivity_ function of a Module
331
- :param signals: The signals involved
339
+
340
+ - Only positional-only or positional-or-keyword arguments are allowed
341
+ (https://peps.python.org/pep-0362/#parameter-object)
342
+ - If `signals` is provided, the number of them is compared with the allowed min/max number of arguments
343
+
344
+ Args:
345
+ fn: response_ or sensitivity_ function of a Module
346
+ signals (optional): The signals involved, which are checked with the function signature
347
+
348
+ Returns:
349
+ (min_args, max_args): Minimum and maximum number of accepted arguments to the function;
350
+ `None` denotes an unlimited number of maximum arguments (caused by `*args`)
332
351
  """
333
352
  min_args, max_args = 0, 0
334
353
  callstr = f"{type(fn.__self__).__name__}.{fn.__name__}{inspect.signature(fn)}"
354
+ # Loop over all the parameters defined for the function
335
355
  for s, p in inspect.signature(fn).parameters.items():
336
356
  if p.kind == inspect.Parameter.POSITIONAL_ONLY or p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
337
- if p.default != inspect.Parameter.empty:
338
- raise SyntaxError(f"{callstr} must not have default values \"{p}\"")
339
- min_args += 1
340
- if max_args >= 0:
357
+ if p.default == inspect.Parameter.empty:
358
+ # No default argument is provided, a value MUST be provided
359
+ min_args += 1
360
+ if max_args is not None:
341
361
  max_args += 1
342
362
  elif p.kind == inspect.Parameter.VAR_POSITIONAL:
343
- max_args = -1
363
+ # If *args is passed, the maximum number of arguments is unknown. Does not affect minimum number
364
+ max_args = None
344
365
  elif p.kind == inspect.Parameter.KEYWORD_ONLY:
345
- raise SyntaxError(f"{callstr} may not contain keyword arguments \"{p}\"")
366
+ raise SyntaxError(f"{callstr} may not contain keyword-only arguments \"{p}\"")
346
367
  elif p.kind == inspect.Parameter.VAR_KEYWORD:
347
- raise SyntaxError(f"{callstr} may not contain \"{p}\"")
348
- if len(signals) < min_args:
349
- raise TypeError(f"Not enough arguments ({len(signals)}) for {callstr}")
350
- if max_args >= 0 and len(signals) > max_args:
351
- raise TypeError(f"Too many arguments ({len(signals)}) for {callstr}")
368
+ raise SyntaxError(f"{callstr} may not contain dict of keyword-only arguments \"{p}\"")
369
+
370
+ # Check with signal list
371
+ if signals is not None:
372
+ if len(signals) < min_args:
373
+ raise TypeError(f"Not enough arguments ({len(signals)}) for {callstr}; expected {min_args}")
374
+ if max_args is not None and len(signals) > max_args:
375
+ raise TypeError(f"Too many arguments ({len(signals)}) for {callstr}; expected {max_args}")
376
+ return min_args, max_args
352
377
 
353
378
 
354
379
  class RegisteredClass(object):
@@ -522,8 +547,12 @@ class Module(ABC, RegisteredClass):
522
547
  raise type(e)(str(e) + "\n\t| Above error was raised when calling response(). Module details:" +
523
548
  self._err_str(fn=self._response)).with_traceback(sys.exc_info()[2])
524
549
 
525
- def __call__(self):
526
- return self.response()
550
+ def __call__(self, *args):
551
+ if len(args) == 0 and len(self.sig_in) > 0:
552
+ inp = [s.state for s in self.sig_in]
553
+ return self._response(*inp)
554
+ else:
555
+ return self._response(*args)
527
556
 
528
557
  def sensitivity(self):
529
558
  """ Calculate sensitivities using backpropagation
pymoto/modules/io.py CHANGED
@@ -1,13 +1,9 @@
1
1
  import os
2
- import platform
3
2
  import numbers
4
- import sys
5
3
  from pathlib import Path
6
4
  import numpy as np
7
- if platform.system() == 'Darwin': # Avoid "Python is not installed as a framework (Mac OS X)" error
8
- # Change backend
9
- import matplotlib
10
- matplotlib.use('TkAgg')
5
+ import matplotlib
6
+ matplotlib.use('TkAgg') # Change default backend -- TkAgg does not freeze during calculations
11
7
  import matplotlib.pyplot as plt
12
8
 
13
9
  from pymoto import Module
@@ -1,29 +1,37 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pyMOTO
3
- Version: 1.5.1
4
- Summary: A modular approach for topology optimization
5
- Home-page: https://github.com/aatmdelissen/pyMOTO
6
- Author: Arnoud Delissen
7
- Author-email: arnouddelissen+pymoto@gmail.com
8
- License: MIT License
9
- Keywords: topology optimization,generative design,structural,sensitivities,derivatives,framework,modular,blocks,pipeline
3
+ Version: 1.5.1b1
4
+ Summary: A modular approach to topology optimization
5
+ Author-email: Arnoud Delissen <arnouddelissen+pymoto@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://pymoto.readthedocs.io/
8
+ Project-URL: Code, https://github.com/aatmdelissen/pyMOTO
9
+ Project-URL: Documentation, https://pymoto.readthedocs.io/
10
+ Project-URL: Issues, https://github.com/aatmdelissen/pyMOTO/issues
11
+ Project-URL: Release notes, https://github.com/aatmdelissen/pyMOTO/releases/latest
12
+ Keywords: topology optimization,generative design,sensitivity analysis,gradients,finite element method,structural optimization,mechanics,engineering
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering
16
+ Classifier: Natural Language :: English
10
17
  Classifier: Programming Language :: Python :: 3
11
18
  Classifier: Operating System :: OS Independent
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Topic :: Scientific/Engineering
19
+ Requires-Python: >=3.8
14
20
  Description-Content-Type: text/markdown
15
21
  License-File: LICENSE
16
22
  Requires-Dist: numpy
17
- Requires-Dist: scipy >=1.7
23
+ Requires-Dist: scipy>=1.7
18
24
  Requires-Dist: sympy
19
25
  Requires-Dist: matplotlib
20
26
  Provides-Extra: dev
21
- Requires-Dist: flake8 ; extra == 'dev'
22
- Requires-Dist: pytest ; extra == 'dev'
23
- Requires-Dist: cvxopt ; extra == 'dev'
24
- Requires-Dist: scikit-sparse ; extra == 'dev'
25
- Requires-Dist: pypardiso ; extra == 'dev'
26
- Requires-Dist: jax[cpu] ; extra == 'dev'
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Requires-Dist: flake8; extra == "dev"
29
+ Requires-Dist: cvxopt; extra == "dev"
30
+ Requires-Dist: scikit-sparse; extra == "dev"
31
+ Requires-Dist: pypardiso; extra == "dev"
32
+ Requires-Dist: opt-einsum; extra == "dev"
33
+ Requires-Dist: jax[cpu]; extra == "dev"
34
+ Dynamic: license-file
27
35
 
28
36
  [![10.5281/zenodo.8138859](https://zenodo.org/badge/DOI/10.5281/zenodo.8138859.svg)](https://doi.org/10.5281/zenodo.8138859)
29
37
  [![anaconda.org/aatmdelissen/pymoto](https://anaconda.org/aatmdelissen/pymoto/badges/version.svg)](https://anaconda.org/aatmdelissen/pymoto)
@@ -1,8 +1,8 @@
1
- pymoto/__init__.py,sha256=i4B3bc954raAJs0lh0vycgWQ3n6FQCL5oKllmaHtt8M,2058
2
- pymoto/core_objects.py,sha256=JDY5OBnzSnmXp35-gY_Gqawjh6C2x8dL1cEV8KAW944,27343
1
+ pymoto/__init__.py,sha256=csgRTVQ2B0pIbQZYvpmL4RDcKYVoyc-vaio3UzlaQ-s,2064
2
+ pymoto/core_objects.py,sha256=Amxn-338Igm2BT1O76wr6GgftQ3vgldj-aqHhJodGfA,28579
3
3
  pymoto/routines.py,sha256=inz5GbSnvmbD3WKmaNKATTc_SthKsAMPuRc8Jaub4xs,15568
4
4
  pymoto/utils.py,sha256=YJ-PNLJLc12Yx6TYCrEechS2aaBRx0o4mTM1soeeyz0,1122
5
- pymoto/common/domain.py,sha256=1peaQJuePBZCWjW2oMhRxlhOl1FuhthEE1aWW9dMumk,18168
5
+ pymoto/common/domain.py,sha256=lstnJ-ITqtjLMQljoc5gN3XVgdFa7gXlMNWiG7IfcR4,18118
6
6
  pymoto/common/dyadcarrier.py,sha256=Q0MCIP4b-W_RuYxynvY-voCHfeZ4oF12ykAuVUnmLq4,19433
7
7
  pymoto/common/mma.py,sha256=SaFdZhpL5uoQRLWxQrElcjRMzGG4CL3BcPc77z3eMVE,24612
8
8
  pymoto/modules/aggregation.py,sha256=Oi17hIJ6dic4lOPw16zmjbdC72MjB6XK34H80bnbWAI,7580
@@ -11,7 +11,7 @@ pymoto/modules/autodiff.py,sha256=WAfoAOHBSozf7jbr9gQz9Vw4a_2G9wGJxLMMqUQP0Co,16
11
11
  pymoto/modules/complex.py,sha256=B_Obk-ABdV66lEudZ5s8o6qG9NsmYlBsX-PbWvbphhc,4429
12
12
  pymoto/modules/filter.py,sha256=6X9FaQMWYZ_TpHVTFiEibzlmAwmSWbydYM93LFrJ0Wo,25490
13
13
  pymoto/modules/generic.py,sha256=YzsGZ8J0oLCORt78Bf2p0v4GuqpWRI77NLoCk7gqidw,10666
14
- pymoto/modules/io.py,sha256=BHJgS5IvFTiYYH4cXqRwSid1bfB58HOQs_jhFeLbb3A,13639
14
+ pymoto/modules/io.py,sha256=nWhXlDc3l-g-5GEY50yRLbbDAy7pay5Tm92pSgLfUIw,13553
15
15
  pymoto/modules/linalg.py,sha256=GIMqcIfVsMib5nIwrhx4sPT6-auLiHBJjbKCAdulLLE,22005
16
16
  pymoto/modules/scaling.py,sha256=uq88HHW9rP16XLz7UGc3CNBBpY2Z1glo8yjYxZEnXUg,2327
17
17
  pymoto/solvers/__init__.py,sha256=9JUeD2SgZbkYFullA7s7s6SuAVv0onqAqJ8hFvNOs2g,1033
@@ -21,9 +21,8 @@ pymoto/solvers/iterative.py,sha256=hfMRw2LChupr4sQf8qUKG6OHjhpeVAp6C9N7M4-845M,1
21
21
  pymoto/solvers/matrix_checks.py,sha256=bbrfjpTSWWnuQW3xY0_CYE8yrh5gA9K5b1LzHEOFAxI,1663
22
22
  pymoto/solvers/solvers.py,sha256=Srn44oRonZIjJq-XVpJY9KoTWV0R7zBWFaSmXKWsUCw,11870
23
23
  pymoto/solvers/sparse.py,sha256=BPw-2Q4lgbmtjCl8eLEmDdWhjqD7RSLrVYy_kQN_LdU,17144
24
- pyMOTO-1.5.1.dist-info/LICENSE,sha256=ZXMC2Txpzs-dBwz9Me4_1rQCSVl4P1B27MomNi43F30,1072
25
- pyMOTO-1.5.1.dist-info/METADATA,sha256=_ZZ3mHjsLTWtdHuM2k8VcO2t3xF6gt67gFVFHibXMJ8,5062
26
- pyMOTO-1.5.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
27
- pyMOTO-1.5.1.dist-info/top_level.txt,sha256=EdvAUSmFMaiqhuEZW8jxANMiK-LdPtlmDWL6SfmCdUU,7
28
- pyMOTO-1.5.1.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
29
- pyMOTO-1.5.1.dist-info/RECORD,,
24
+ pymoto-1.5.1b1.dist-info/licenses/LICENSE,sha256=ZXMC2Txpzs-dBwz9Me4_1rQCSVl4P1B27MomNi43F30,1072
25
+ pymoto-1.5.1b1.dist-info/METADATA,sha256=Xt0HY8PX1nI1W1_xiWZNkin3vVXNenx-mvhMhn0F2wY,5510
26
+ pymoto-1.5.1b1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ pymoto-1.5.1b1.dist-info/top_level.txt,sha256=EdvAUSmFMaiqhuEZW8jxANMiK-LdPtlmDWL6SfmCdUU,7
28
+ pymoto-1.5.1b1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1 +0,0 @@
1
-