simapy 4.6.0.dev1__py3-none-any.whl → 4.6.1.dev0__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.
@@ -1 +1 @@
1
- packages = [{'name': 'command', 'version': 1}, {'name': 'condition', 'version': 19}, {'name': 'custom', 'version': 12}, {'name': 'doc', 'version': 11}, {'name': 'environment', 'version': 22}, {'name': 'graph', 'version': 4}, {'name': 'hla', 'version': 24}, {'name': 'hydro', 'version': 28}, {'name': 'metocean', 'version': 10}, {'name': 'optimization', 'version': 1}, {'name': 'post', 'version': 27}, {'name': 'report', 'version': 11}, {'name': 'riflex', 'version': 43}, {'name': 'signals', 'version': 2, 'packages': [{'name': 'report', 'version': 2}]}, {'name': 'sima', 'version': 24}, {'name': 'simo', 'version': 45}, {'name': 'wamit', 'version': 14}, {'name': 'windpark', 'version': 1}, {'name': 'windturbine', 'version': 10}, {'name': 'workflow', 'version': 19}]
1
+ packages = {'command': 1, 'condition': 19,'custom': 12,'doc': 11,'environment': 22,'graph': 4,'hla': 24,'hydro': 28,'metocean': 10,'optimization': 1,'post': 27,'report': 11,'riflex': 43,'signals': 2, 'sima': 24,'simo': 45,'wamit': 14,'windpark': 1,'windturbine': 10,'workflow': 19}
simapy/sima_reader.py CHANGED
@@ -6,6 +6,7 @@ from typing import Sequence
6
6
  from dmt.entity import Entity
7
7
  from dmt.dmt_reader import DMTReader
8
8
  from .sima.modelcontent import ModelContent
9
+ from .sima.package_info import packages
9
10
 
10
11
  class SIMAReader():
11
12
  """ Creates entities from Dicts or file """
@@ -17,4 +18,17 @@ class SIMAReader():
17
18
  modelcontent: ModelContent = res[0]
18
19
  else:
19
20
  modelcontent: ModelContent = res
21
+ self.__check_version(modelcontent)
20
22
  return modelcontent.contents
23
+
24
+ def __check_version(self, modelcontent: ModelContent):
25
+ """ Check if imported model has the same version as the reader """
26
+ header = modelcontent.header
27
+ if header:
28
+ pkgs = modelcontent.header.packages
29
+ for pkg in pkgs:
30
+ version = packages.get(pkg.name)
31
+ if not version:
32
+ raise ValueError(f"Unknown package {pkg.name}")
33
+ if version != pkg.version:
34
+ raise ValueError(f"Package {pkg.name} has version {pkg.version} but reader expects {version}. Please use the correct version of simapy for the corresponding version of SIMA.")
simapy/sima_writer.py CHANGED
@@ -24,8 +24,8 @@ class SIMAWriter():
24
24
  content = ModelContent()
25
25
  header = Header()
26
26
 
27
- for package in packages:
28
- header.packages.append(PackageInfo(**package))
27
+ for name,version in packages.items():
28
+ header.packages.append(PackageInfo(name=name,version=version))
29
29
 
30
30
  content.header = header
31
31
  content.contents.extend(models)
simapy/sre.py CHANGED
@@ -1,12 +1,13 @@
1
1
  """Run a command using SIMA runtime engine (sre executable)"""
2
2
  import asyncio
3
3
  import os
4
+ import re
4
5
  from pathlib import Path
5
- from typing import Sequence
6
+ from typing import Sequence,Callable
6
7
  from simapy.sima_writer import SIMAWriter
7
8
 
8
9
 
9
- async def run_command(args, error_file, out_file):
10
+ async def run_command(args, error_file, out_file, status_handler):
10
11
  """"Run a command asynchronously and print output to standard out.
11
12
  Standard err is piped to stderr.txt in the working directory"""
12
13
  process = await asyncio.create_subprocess_exec(
@@ -14,26 +15,41 @@ async def run_command(args, error_file, out_file):
14
15
  )
15
16
 
16
17
  while True:
17
- stdout, _ = await process.communicate()
18
-
19
- if stdout:
20
- for line in stdout.splitlines():
21
- sline = line.decode("utf-8")
22
- if sline.startswith("@STATUS"):
23
- print("STATUS found:" + sline, end="\n")
24
- else:
25
- print(sline, end="\n")
26
- print(sline, end="\n", file=out_file)
18
+ # Use an awaitable to read data from stdout
19
+ # Read the next line of data from stdout asynchronously
20
+ data = await process.stdout.readline()
21
+ if not data:
22
+ break # Break the loop when there's no more data
23
+ sline = data.decode('utf-8')
24
+ if status_handler and sline.startswith("@STATUS"):
25
+ __parse_status(sline,status_handler)
26
+ else:
27
+ print(sline, end="\n")
28
+ print(sline, end="\n", file=out_file)
27
29
 
28
- if process.returncode is not None:
29
- return process.returncode
30
+ # Wait for the subprocess to finish
31
+ await process.wait()
32
+ if process.returncode is not None:
33
+ return process.returncode
30
34
 
35
+ def __parse_status(line: str,status_handler):
36
+ # A status line looks like this: @STATUS "Total" 100 1000
37
+ # The first number is the current value, the second is the total
38
+ pattern = r'@STATUS "(?P<label>\w+)" (?P<current>\d+) (?P<total>\d+)'
39
+ # Match the pattern in the string
40
+ match = re.match(pattern, line)
41
+ if match:
42
+ label = match.group('label')
43
+ current = int(match.group('current'))
44
+ total = int(match.group('total'))
45
+ status_handler(label,current,total)
31
46
 
32
47
  class SIMA:
33
48
  """"Run a command using SIMA runtime engine (sre executable)"""
34
49
 
35
50
  def __init__(self, exe=None, fail_on_error=True):
36
51
  self.fail_on_error = fail_on_error
52
+ self.status_handler: Callable = None
37
53
  if exe:
38
54
  self.exe = exe
39
55
  else:
@@ -42,22 +58,24 @@ class SIMA:
42
58
  raise ValueError("No executable given, and SRE_EXE environment variable is not set")
43
59
 
44
60
 
45
- def run(self, working_dir: Path, command_args: Sequence):
61
+ def run(self, working_dir, command_args: Sequence[str]):
46
62
  """Run the sima executable and print output to standard out.
47
63
  Standard err is piped to stderr.txt in the working directory"""
64
+
65
+ wdir = Path(str(working_dir))
48
66
  arguments = [self.exe]
49
67
  arguments.extend(["-configuration", "/var/opt/sima/config"])
50
68
  arguments.append("-consoleLog")
51
69
  arguments.append("--progress")
52
70
  arguments.extend(["-data", working_dir])
53
- working_dir.mkdir(parents=True, exist_ok=True)
71
+ wdir.mkdir(parents=True, exist_ok=True)
54
72
  self.__add_command_args(working_dir, arguments, command_args)
55
- err_file = working_dir / "stderr.txt"
56
- out_file = working_dir / "stdout.txt"
57
- with open(err_file, "w", encoding="utf8") as ef, open(
73
+ err_file = wdir / "stderr.txt"
74
+ out_file = wdir / "stdout.txt"
75
+ with open(err_file, "w", encoding="utf8") as e_f, open(
58
76
  out_file, "w", encoding="utf8"
59
- ) as of:
60
- exit_code = asyncio.run(run_command(arguments, ef, of))
77
+ ) as o_f:
78
+ exit_code = asyncio.run(run_command(arguments, e_f, o_f, self.status_handler))
61
79
  if exit_code != 0 and self.fail_on_error:
62
80
  raise RuntimeError(f"SIMA exited with error code {exit_code}")
63
81
 
@@ -1,37 +1,49 @@
1
- Metadata-Version: 2.1
2
- Name: simapy
3
- Version: 4.6.0.dev1
4
- Summary: Python utilities for SIMA
5
- Home-page: https://github.com/SINTEF/simapy
6
- Author: SINTEF Ocean
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: >=3.8
11
- Description-Content-Type: text/markdown
12
- License-File: LICENSE
13
- Requires-Dist: dmtpy (==0.3.4)
14
- Requires-Dist: numpy
15
-
16
- SIMAPY - Python utilities for SIMA
17
- =================================================================
18
-
19
- This Python library can be used to interact with [SIMA](https://sima.sintef.no)
20
-
21
- Parts of the library is generated from DMT models using a DMT Python code generator
22
-
23
- Please examine the tests for ways to interact
24
-
25
- Also check out the examples in [simapy-examples](https://github.com/SINTEF/simapy-examples)
26
-
27
- ## Dependencies
28
-
29
- * [DMTPY](https://github.com/SINTEF/dmtpy)
30
-
31
- ## Authors
32
-
33
- * **Lasse Bjermeland** - [lassebje](https://github.com/lassebje)
34
-
35
- ## License
36
-
37
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1
+ Metadata-Version: 2.1
2
+ Name: simapy
3
+ Version: 4.6.1.dev0
4
+ Summary: Python utilities for SIMA
5
+ Home-page: https://github.com/SINTEF/simapy
6
+ Author: SINTEF Ocean
7
+ License: UNKNOWN
8
+ Platform: UNKNOWN
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: dmtpy (==0.3.4)
16
+ Requires-Dist: numpy
17
+
18
+ SIMAPY - Python utilities for SIMA
19
+ =================================================================
20
+
21
+ This Python library can be used to interact with [SIMA](https://sima.sintef.no)
22
+
23
+ Parts of the library is generated from [data models](https://github.com/SINTEF/sima-dmt-models) using a [Python code generator](https://github.com/SINTEF/dmt-gen-py)
24
+
25
+ Please examine the tests for ways to interact
26
+
27
+ Also check out the examples in [simapy-examples](https://github.com/SINTEF/simapy-examples)
28
+
29
+ ## Installation
30
+
31
+ Use the package manager [pip](https://pip.pypa.io/en/stable/) to install simapy.
32
+
33
+ ```bash
34
+ pip install simapy
35
+ ```
36
+
37
+ ## Dependencies
38
+
39
+ * [DMTPY](https://github.com/SINTEF/dmtpy)
40
+
41
+ ## Authors
42
+
43
+ * **Lasse Bjermeland** - [lassebje](https://github.com/lassebje)
44
+
45
+ ## License
46
+
47
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
48
+
49
+
@@ -1,7 +1,7 @@
1
1
  simapy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- simapy/sima_reader.py,sha256=lU8mvZp1LMh5wvcZhlQRD3T0ltSjWnuPqO1J8YsoBnI,611
3
- simapy/sima_writer.py,sha256=bklm6V4m6qnF1h1uoglK4i6Paw9PVQt4t8kvpKe8XAc,1180
4
- simapy/sre.py,sha256=VWcaAqHvMHa8L_OcOfROT9tS6ncFwiBT-i5n7huVn0o,3240
2
+ simapy/sima_reader.py,sha256=86P_CMaz1i6o8pIzXtNBHcJj0zS6Bw8_8BVO-Wvzs5c,1364
3
+ simapy/sima_writer.py,sha256=MPwvooPLfGpOISxJUVlOWbtf4wVOEvgVCVsvQfLzxxY,1209
4
+ simapy/sre.py,sha256=M2Lhwecrx030C7sDceOks1KM94i13Jry2FBIuE6nIJ0,4045
5
5
  simapy/metocean/__init__.py,sha256=AeEF1FYpBDe46JuZ0EYJOofOuf2dwsaAdQZ0DsseB_g,39
6
6
  simapy/metocean/metocean.py,sha256=TmfSYezAzxWLt9n_ChLKIdaIz6GxSTUu6-5wnipQz6Y,2912
7
7
  simapy/metocean/package_info.py,sha256=6FEJ4gZkXieP2WWTA-oZO23BjQOi4YnXx3nLQY0ydYE,208
@@ -70,7 +70,7 @@ simapy/metocean/scatter/blueprints/windcurrent.py,sha256=lNR5Y7y-gjWo1SpHyMIOg3Z
70
70
  simapy/sima/__init__.py,sha256=vSYgUegrUGeABTa0EaQ6arITEaz9Nhy0sNsC0TWCTW4,127
71
71
  simapy/sima/header.py,sha256=97CWJjRGUokQ-VDeaDYrUi06JKgyU0qZh037RHv01PI,1442
72
72
  simapy/sima/modelcontent.py,sha256=HRP2YuN05rJjPO0eLJVmRSTsS5sSODKd66ce66lC2_o,1697
73
- simapy/sima/package_info.py,sha256=6obukVUnRiFgVpOzmdlXk8ra_gcxHvi-GWNXCNLH4xo,767
73
+ simapy/sima/package_info.py,sha256=b2lrouwC5nCYB5WON-aArm1lXSdLI39xWQ5mYpeUGng,284
74
74
  simapy/sima/packageinfo.py,sha256=f_8twmLCJ-7IBtzOit94I6ya4AyfRXNQSjto6TDGycE,1564
75
75
  simapy/sima/blueprints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  simapy/sima/blueprints/header.py,sha256=Z4l7ACY3WvgqqIPYDhQB2KAn2mMw-KZOfBDZUfXKMnw,655
@@ -2400,8 +2400,8 @@ simapy/sima/workflow/blueprints/workflowsetitem.py,sha256=EyyxbrnPDcL-f1cgjWcH3o
2400
2400
  simapy/sima/workflow/blueprints/workflowsetnode.py,sha256=UIZYi61xYtOEBzSZ5wQclUjzdAarZ8ymJ67iGARdXH4,4018
2401
2401
  simapy/sima/workflow/blueprints/workflowtask.py,sha256=c1rpN0KRKg7zIhonXKEaAGL0c6k8-ecIcP3RK3EUD8g,1514
2402
2402
  simapy/sima/workflow/blueprints/xytablenode.py,sha256=J-ADKlq47efkQMbay2eS0WJGtB9K0B75caOUTbj7Ogs,1667
2403
- simapy-4.6.0.dev1.dist-info/LICENSE,sha256=F5QFv7maV1Hoof3UbIwTNKqDFoo2JykLoI_w6F4HqxI,1088
2404
- simapy-4.6.0.dev1.dist-info/METADATA,sha256=R1LCuUTQSDr37M_rtxtWMkQAlkd1z848U7wPkdmTnAI,1129
2405
- simapy-4.6.0.dev1.dist-info/WHEEL,sha256=00yskusixUoUt5ob_CiUp6LsnN5lqzTJpoqOFg_FVIc,92
2406
- simapy-4.6.0.dev1.dist-info/top_level.txt,sha256=AVWKlvxcgSVR0H1omucqMujOVuQbcFNLjlgp3skT_1Q,7
2407
- simapy-4.6.0.dev1.dist-info/RECORD,,
2403
+ simapy-4.6.1.dev0.dist-info/LICENSE,sha256=F5QFv7maV1Hoof3UbIwTNKqDFoo2JykLoI_w6F4HqxI,1088
2404
+ simapy-4.6.1.dev0.dist-info/METADATA,sha256=RXFQ7YP9_9z4tNzSr22AIovvcRcBkV1gE9gESWgWlvI,1342
2405
+ simapy-4.6.1.dev0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
2406
+ simapy-4.6.1.dev0.dist-info/top_level.txt,sha256=AVWKlvxcgSVR0H1omucqMujOVuQbcFNLjlgp3skT_1Q,7
2407
+ simapy-4.6.1.dev0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.1)
2
+ Generator: bdist_wheel (0.37.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5