math-spec-mapping 0.2.6.7__tar.gz → 0.2.8__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. {math-spec-mapping-0.2.6.7/src/math_spec_mapping.egg-info → math-spec-mapping-0.2.8}/PKG-INFO +1 -1
  2. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/pyproject.toml +1 -1
  3. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/ControlAction.py +1 -0
  4. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/MathSpec.py +251 -0
  5. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Mechanism.py +1 -0
  6. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Policy.py +1 -0
  7. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Space.py +1 -0
  8. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/State.py +1 -0
  9. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Type.py +1 -0
  10. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/__init__.py +1 -1
  11. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/control_actions.py +10 -0
  12. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/mechanism.py +8 -0
  13. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/policy.py +11 -2
  14. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/type.py +1 -0
  15. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/html.py +33 -1
  16. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/markdown.py +0 -1
  17. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/schema.schema.json +48 -24
  18. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8/src/math_spec_mapping.egg-info}/PKG-INFO +1 -1
  19. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/LICENSE +0 -0
  20. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/README.md +0 -0
  21. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/setup.cfg +0 -0
  22. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  23. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Block.py +0 -0
  24. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/BoundaryAction.py +0 -0
  25. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Entity.py +0 -0
  26. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Metric.py +0 -0
  27. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  28. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  29. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  30. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  31. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  32. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Convenience/starter.py +0 -0
  33. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/__init__.py +0 -0
  34. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  35. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/boundary_actions.py +0 -0
  36. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/displays.py +0 -0
  37. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/entities.py +0 -0
  38. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/general.py +0 -0
  39. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/implementations.py +0 -0
  40. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/load.py +0 -0
  41. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/metrics.py +0 -0
  42. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/parameters.py +0 -0
  43. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/spaces.py +0 -0
  44. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  45. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/stateful_metrics.py +0 -0
  46. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/states.py +0 -0
  47. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Load/wiring.py +0 -0
  48. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/__init__.py +0 -0
  49. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  50. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  51. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/general.py +0 -0
  52. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  53. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/node_map.py +0 -0
  54. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/parameters.py +0 -0
  55. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/policies.py +0 -0
  56. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/spaces.py +0 -0
  57. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/state.py +0 -0
  58. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/tables.py +0 -0
  59. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/Reports/wiring.py +0 -0
  60. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/__init__.py +0 -0
  61. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping/schema.py +0 -0
  62. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  63. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  64. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  65. {math-spec-mapping-0.2.6.7 → math-spec-mapping-0.2.8}/src/math_spec_mapping.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.2.6.7
3
+ Version: 0.2.8
4
4
  Summary: A library for easy mapping of mathematical specifications.
5
5
  Author-email: Sean McOwen <Sean@Block.Science>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "math-spec-mapping"
6
- version = "0.2.6.7"
6
+ version = "0.2.8"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -15,3 +15,4 @@ class ControlActionOption:
15
15
  self.name = data["name"]
16
16
  self.description = data["description"]
17
17
  self.logic = data["logic"]
18
+ self.implementations = data["implementations"]
@@ -4,6 +4,8 @@ from .Policy import Policy
4
4
  from .Mechanism import Mechanism
5
5
  from .ControlAction import ControlAction
6
6
  from .BoundaryAction import BoundaryAction
7
+ import os
8
+ from copy import deepcopy
7
9
 
8
10
 
9
11
  class MathSpec:
@@ -12,6 +14,7 @@ class MathSpec:
12
14
  self._ms_dict = ms_dict
13
15
  self._json = json
14
16
  self.type_keys = ms_dict["Type Keys"]
17
+ self.implementations = ms_dict["Implementations"]
15
18
  self.action_transmission_channels = ms_dict["Action Transmission Channels"]
16
19
  self.boundary_actions = ms_dict["Boundary Actions"]
17
20
  self.control_actions = ms_dict["Control Actions"]
@@ -39,6 +42,8 @@ class MathSpec:
39
42
  self._crawl_parameters()
40
43
  self._crawl_parameters_exploded()
41
44
  self._check_dictionary_names()
45
+ self._build_functional_parameters()
46
+ self._build_parameter_types()
42
47
 
43
48
  def _check_dictionary_names(self):
44
49
  for key in self.boundary_actions:
@@ -349,3 +354,249 @@ class MathSpec:
349
354
  for metrics in self.stateful_metrics.values():
350
355
  sm.extend([x.name for x in metrics.metrics])
351
356
  return sm
357
+
358
+ def _build_functional_parameters(self):
359
+ opts = [x for x in self.policies.values() if len(x.policy_options) > 1]
360
+ opts.extend(
361
+ [
362
+ x
363
+ for x in self.boundary_actions.values()
364
+ if len(x.boundary_action_options) > 1
365
+ ]
366
+ )
367
+ opts.extend(
368
+ [
369
+ x
370
+ for x in self.control_actions.values()
371
+ if len(x.control_action_options) > 1
372
+ ]
373
+ )
374
+ self.functional_parameters = {}
375
+ for x in opts:
376
+ self.functional_parameters["FP {}".format(x.name)] = x
377
+
378
+ def _build_parameter_types(self):
379
+ system_parameters_types = {}
380
+ behavioral_parameters_types = {}
381
+ functional_parameters_types = {}
382
+
383
+ for x in self.parameters.all_parameters:
384
+ pt = self.parameters.parameter_map[x].variable_type.original_type_name
385
+ pc = self.parameters.parameter_map[x].parameter_class
386
+ if pc == "Functional":
387
+ functional_parameters_types[x] = pt
388
+ elif pc == "System":
389
+ system_parameters_types[x] = pt
390
+ elif pc == "Behavioral":
391
+ behavioral_parameters_types[x] = pt
392
+ else:
393
+ assert False
394
+ for x in self.functional_parameters:
395
+ functional_parameters_types[x] = "str"
396
+
397
+ self.system_parameters_types = system_parameters_types
398
+ self.behavioral_parameters_types = behavioral_parameters_types
399
+ self.functional_parameters_types = functional_parameters_types
400
+
401
+ def metaprogramming_python_types(self, model_directory, overwrite=False):
402
+ path = model_directory + "/types.py"
403
+ if not overwrite:
404
+ assert "types.py" not in os.listdir(
405
+ model_directory
406
+ ), "The types file is already written, either delete it or switch to overwrite mode"
407
+ out = "import typing\n\n"
408
+ for t in self.types:
409
+ t = self.types[t]
410
+ assert "python" in t.type, "No python type associated with {}".format(
411
+ t.name
412
+ )
413
+ x = t.type["python"]
414
+ type_desc = x.__name__ if hasattr(x, "__name__") else str(x)
415
+ out += "{} = {}".format(t.original_type_name, type_desc)
416
+ out += "\n"
417
+ with open(path, "w") as f:
418
+ f.write(out)
419
+
420
+ def metaprogramming_python_spaces(self, model_directory, overwrite=False):
421
+ path = model_directory + "/spaces.py"
422
+ if not overwrite:
423
+ assert "spaces.py" not in os.listdir(
424
+ model_directory
425
+ ), "The spaces file is already written, either delete it or switch to overwrite mode"
426
+ unique_spaces = set().union(
427
+ *[set(x.schema.values()) for x in self.spaces.values()]
428
+ )
429
+ unique_types = [x.original_type_name for x in unique_spaces]
430
+ out = ""
431
+ out += "from .types import {}".format(", ".join(unique_types))
432
+ out += "\n"
433
+ out += "from typing import TypedDict"
434
+ out += "\n"
435
+ out += "\n"
436
+
437
+ for space in self.spaces:
438
+ out += self.spaces[space].name_variable
439
+ out += " = "
440
+ d = self.spaces[space].schema
441
+ d = [(x, d[x].original_type_name) for x in d]
442
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
443
+ d = ", ".join(d)
444
+ d = "{" + d + "}"
445
+ out += "TypedDict('{}', {})".format(self.spaces[space].name, d)
446
+ out += "\n"
447
+
448
+ with open(path, "w") as f:
449
+ f.write(out)
450
+
451
+ def metaprogramming_python_states(
452
+ self, model_directory, overwrite=False, default_values=None
453
+ ):
454
+ path = model_directory + "/states.py"
455
+ if not overwrite:
456
+ assert "states.py" not in os.listdir(
457
+ model_directory
458
+ ), "The states file is already written, either delete it or switch to overwrite mode"
459
+ out = ""
460
+ unique_types = [x.variables for x in self.state.values()]
461
+ unique_types = [set(y.type.original_type_name for y in x) for x in unique_types]
462
+ unique_types = set().union(*unique_types)
463
+ out = ""
464
+ out += "from .types import {}".format(", ".join(unique_types))
465
+ out += "\n"
466
+ out += "from typing import TypedDict"
467
+ out += "\n"
468
+ out += "\n"
469
+
470
+ for state in self.state:
471
+ out += self.state[state].name_variable
472
+ out += " = "
473
+ d = self.state[state].variables
474
+ d = [(x.name, x.type.original_type_name) for x in d]
475
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
476
+ d = ", ".join(d)
477
+ d = "{" + d + "}"
478
+ out += "TypedDict('{}', {})".format(self.state[state].name, d)
479
+ out += "\n"
480
+ out += "\n"
481
+ out += "state: GlobalState = "
482
+ out += "{"
483
+ for x in self.state["Global State"].variables:
484
+ out += '"{}"'.format(x.name)
485
+ out += ": "
486
+ val = "None"
487
+ if default_values:
488
+ if x.name in default_values:
489
+ val = str(default_values[x.name])
490
+ out += val
491
+ out += ",\n"
492
+ out += "}"
493
+
494
+ with open(path, "w") as f:
495
+ f.write(out)
496
+
497
+ def metaprogramming_python_parameters(
498
+ self, model_directory, overwrite=False, default_values=None
499
+ ):
500
+ path = model_directory + "/parameters.py"
501
+ if not overwrite:
502
+ assert "parameters.py" not in os.listdir(
503
+ model_directory
504
+ ), "The parameters file is already written, either delete it or switch to overwrite mode"
505
+ out = ""
506
+
507
+ unique_types = (
508
+ set(self.system_parameters_types.values())
509
+ .union(set(self.functional_parameters_types.values()))
510
+ .union(set(self.behavioral_parameters_types.values()))
511
+ )
512
+ unique_types = [x for x in unique_types if x != "str"]
513
+
514
+ out = ""
515
+ out += "from .types import {}".format(", ".join(unique_types))
516
+ out += "\n"
517
+ out += "from typing import TypedDict"
518
+ out += "\n"
519
+ out += "\n"
520
+
521
+ d = self.system_parameters_types
522
+ d = [(x, d[x]) for x in d]
523
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
524
+ d = ", ".join(d)
525
+ d = "{" + d + "}"
526
+
527
+ out += "SystemParameters = TypedDict('SystemParameters', {})".format(d)
528
+ out += "\n\n"
529
+
530
+ d = self.behavioral_parameters_types
531
+ d = [(x, d[x]) for x in d]
532
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
533
+ d = ", ".join(d)
534
+ d = "{" + d + "}"
535
+
536
+ out += "BehavioralParameters = TypedDict('BehavioralParameters', {})".format(d)
537
+ out += "\n\n"
538
+
539
+ d = self.functional_parameters_types
540
+ d = [(x, d[x]) for x in d]
541
+ d = ["'{}': {}".format(x[0], x[1]) for x in d]
542
+ d = ", ".join(d)
543
+ d = "{" + d + "}"
544
+
545
+ out += "FunctionalParameters = TypedDict('FunctionalParameters', {})".format(d)
546
+ out += "\n\n"
547
+ out += """Parameters = TypedDict("Parameters",{**BehavioralParameters.__annotations__,
548
+ **FunctionalParameters.__annotations__,
549
+ **SystemParameters.__annotations__})"""
550
+ out += "\n\n"
551
+
552
+ out += "functional_parameters: FunctionalParameters = "
553
+ out += "{"
554
+ for key in self.functional_parameters_types:
555
+ out += '"{}"'.format(key)
556
+ out += ": "
557
+ val = "None"
558
+ if default_values:
559
+ if key in default_values:
560
+ val = str(default_values[key])
561
+ out += val
562
+ out += ",\n"
563
+ out += "}"
564
+ out += "\n\n"
565
+
566
+ out += "behavioral_parameters: BehavioralParameters = "
567
+ out += "{"
568
+ for key in self.behavioral_parameters_types:
569
+ out += '"{}"'.format(key)
570
+ out += ": "
571
+ val = "None"
572
+ if default_values:
573
+ if key in default_values:
574
+ val = str(default_values[key])
575
+ out += val
576
+ out += ",\n"
577
+ out += "}"
578
+ out += "\n\n"
579
+
580
+ out += "system_parameters: SystemParameters = "
581
+ out += "{"
582
+ for key in self.system_parameters_types:
583
+ out += '"{}"'.format(key)
584
+ out += ": "
585
+ val = "None"
586
+ if default_values:
587
+ if key in default_values:
588
+ val = str(default_values[key])
589
+ out += val
590
+ out += ",\n"
591
+ out += "}"
592
+ out += "\n\n"
593
+
594
+ out += "parameters: Parameters = {**behavioral_parameters, **functional_parameters, **system_parameters}"
595
+
596
+ with open(path, "w") as f:
597
+ f.write(out)
598
+
599
+
600
+ class MathSpecImplementation:
601
+ def __init__(self, ms: MathSpec, params):
602
+ self.ms = deepcopy(ms)
@@ -10,3 +10,4 @@ class Mechanism(Block):
10
10
  self.logic = data["logic"]
11
11
  self.updates = []
12
12
  self.block_type = "Mechanism"
13
+ self.implementations = data["implementations"]
@@ -7,6 +7,7 @@ class PolicyOption:
7
7
  self.name = data["name"]
8
8
  self.description = data["description"]
9
9
  self.logic = data["logic"]
10
+ self.implementations = data["implementations"]
10
11
 
11
12
 
12
13
  class Policy(Block):
@@ -6,6 +6,7 @@ class Space:
6
6
  self.name = data["name"]
7
7
  self.schema = data["schema"]
8
8
  self.metadata = data["metadata"]
9
+ self.name_variable = self.name.replace(" ", "").replace("-", "_")
9
10
 
10
11
  def __repr__(self):
11
12
  return self.name
@@ -15,6 +15,7 @@ class State:
15
15
  self._write_variable_map()
16
16
  self.updated_by = []
17
17
  self.metadata = data["metadata"]
18
+ self.name_variable = self.name.replace(" ", "").replace("-", "_")
18
19
 
19
20
  def _write_variable_map(self) -> None:
20
21
  """
@@ -6,3 +6,4 @@ class Type:
6
6
  self.type_name = data["type_name"]
7
7
  self.notes = data["notes"]
8
8
  self.metadata = data["metadata"]
9
+ self.original_type_name = data["original_type_name"]
@@ -1,4 +1,4 @@
1
- from .MathSpec import MathSpec
1
+ from .MathSpec import MathSpec, MathSpecImplementation
2
2
  from .State import State, StateVariable
3
3
  from .Entity import Entity
4
4
  from .BoundaryAction import BoundaryAction, BoundaryActionOption
@@ -35,6 +35,16 @@ def convert_control_action(data: Dict, ms: Dict) -> ControlAction:
35
35
  new_cao = []
36
36
  for ca in data["control_action_options"]:
37
37
  check_json_keys(ca, "Control Action Option")
38
+ ca["implementations"] = {}
39
+ if "python" in ms["Implementations"]:
40
+ if "control_action_options" in ms["Implementations"]["python"]:
41
+ if (
42
+ ca["name"]
43
+ in ms["Implementations"]["python"]["control_action_options"]
44
+ ):
45
+ ca["implementations"]["python"] = ms["Implementations"]["python"][
46
+ "control_action_options"
47
+ ][ca["name"]]
38
48
  new_cao.append(ControlActionOption(ca))
39
49
  data["control_action_options"] = new_cao
40
50
 
@@ -42,6 +42,14 @@ def convert_mechanism(data: Dict, ms: Dict) -> Mechanism:
42
42
  )
43
43
 
44
44
  data["domain"] = tuple(ms["Spaces"][x] for x in data["domain"])
45
+ data["implementations"] = {}
46
+
47
+ if "python" in ms["Implementations"]:
48
+ if "mechanisms" in ms["Implementations"]["python"]:
49
+ if data["name"] in ms["Implementations"]["python"]["mechanisms"]:
50
+ data["implementations"]["python"] = ms["Implementations"]["python"][
51
+ "mechanisms"
52
+ ][data["name"]]
45
53
 
46
54
  # Build the action transmission channel object
47
55
  return Mechanism(data), new_channels
@@ -5,7 +5,7 @@ from ..Classes import Policy, PolicyOption
5
5
  from .general import check_json_keys
6
6
 
7
7
 
8
- def convert_policy_options(data: Dict) -> PolicyOption:
8
+ def convert_policy_options(data: Dict, ms) -> PolicyOption:
9
9
  """Function to convert policy options
10
10
 
11
11
  Args:
@@ -21,6 +21,15 @@ def convert_policy_options(data: Dict) -> PolicyOption:
21
21
  # Copy
22
22
  data = data.copy()
23
23
 
24
+ data["implementations"] = {}
25
+
26
+ if "python" in ms["Implementations"]:
27
+ if "policies" in ms["Implementations"]["python"]:
28
+ if data["name"] in ms["Implementations"]["python"]["policies"]:
29
+ data["implementations"]["python"] = ms["Implementations"]["python"][
30
+ "policies"
31
+ ][data["name"]]
32
+
24
33
  # Build the policy object
25
34
  return PolicyOption(data)
26
35
 
@@ -62,7 +71,7 @@ def convert_policy(data: Dict, ms: Dict) -> Policy:
62
71
  # Convert policy options
63
72
  policy_options = []
64
73
  for po in data["policy_options"]:
65
- policy_options.append(convert_policy_options(po))
74
+ policy_options.append(convert_policy_options(po, ms))
66
75
  data["policy_options"] = policy_options
67
76
 
68
77
  data["codomain"] = tuple(ms["Spaces"][x] for x in data["codomain"])
@@ -18,6 +18,7 @@ def convert_type(data, ms):
18
18
  type_name = data["type"]
19
19
  data["type"] = {}
20
20
  data["type_name"] = {}
21
+ data["original_type_name"] = type_name
21
22
 
22
23
  if "python" in ms["Type Keys"]:
23
24
 
@@ -9,6 +9,7 @@ from .node_map import create_action_chains_graph
9
9
  from .parameters import write_out_params
10
10
  from .state import write_local_state_variable_tables, write_global_state_variable_table
11
11
  from typing import List
12
+ import os
12
13
 
13
14
 
14
15
  def write_basic_report_full(ms: MathSpec, directory: str, name: str) -> None:
@@ -128,6 +129,15 @@ def write_spec_tree(
128
129
  symbol3 = "│ │ ├──"
129
130
 
130
131
  out = ""
132
+
133
+ if linking:
134
+ out += """---
135
+ cssclasses:
136
+ - spec
137
+ ---
138
+
139
+ """
140
+
131
141
  out += symbol1 + "**Entities**\n"
132
142
  for name in ms.entities.keys():
133
143
  if linking:
@@ -214,7 +224,29 @@ def write_spec_tree(
214
224
  if path:
215
225
  with open("{}/Spec Tree.md".format(path), "w") as f:
216
226
  f.write(out)
217
- return out
227
+ try:
228
+ if ".obsidian" not in os.listdir(path):
229
+ path = path + "/" + ".obsidian"
230
+ os.mkdir(path)
231
+ else:
232
+ path = path + "/" + ".obsidian"
233
+ if "snippets" not in os.listdir(path):
234
+ path = path + "/" + "snippets"
235
+ os.mkdir(path)
236
+ else:
237
+ path = path + "/" + "snippets"
238
+
239
+ snippet = """.spec {
240
+ font-family: 'Consolas', Courier, monospace ;
241
+ line-height: 1;
242
+ }"""
243
+ with open("{}/spec.css".format(path), "w") as f:
244
+ f.write(snippet)
245
+
246
+ except:
247
+ print("Couldn't find .obsidian/snippets to put snippet in")
248
+ else:
249
+ return out
218
250
 
219
251
 
220
252
  def write_overview(ms: MathSpec, name: str, file_path: str, summary: str = None):
@@ -675,7 +675,6 @@ def write_all_markdown_reports(ms, path, clear_folders=False):
675
675
  "Types",
676
676
  "Control Actions",
677
677
  "Spaces",
678
- ".obsidian",
679
678
  "Boundary Actions",
680
679
  "Policies",
681
680
  "Wiring",
@@ -116,28 +116,34 @@
116
116
  "additionalProperties": false,
117
117
  "properties": {
118
118
  "name": {
119
- "type": "string"
119
+ "type": "string",
120
+ "description": "The name of the control action"
120
121
  },
121
122
  "description": {
122
- "type": "string"
123
+ "type": "string",
124
+ "description": "The description of the control action"
123
125
  },
124
126
  "constraints": {
125
127
  "type": "array",
126
- "items": {}
128
+ "description": "Any constraints which the control action must respect",
129
+ "items": {"type": "string"}
127
130
  },
128
131
  "control_action_options": {
129
132
  "type": "array",
130
- "items": {}
133
+ "items": {},
134
+ "description": "Possible implementations of the control action"
131
135
  },
132
136
  "codomain": {
133
137
  "type": "array",
134
138
  "items": {
135
139
  "type": "string"
136
- }
140
+ },
141
+ "description": "The output spaces of the control action"
137
142
  },
138
143
  "parameters_used": {
139
144
  "type": "array",
140
- "items": {"type": "string"}
145
+ "items": {"type": "string"},
146
+ "description": "The parameters which the control action uses in its implenetations"
141
147
  }
142
148
  },
143
149
  "required": [
@@ -308,44 +314,52 @@
308
314
  "additionalProperties": false,
309
315
  "properties": {
310
316
  "name": {
311
- "type": "string"
317
+ "type": "string",
318
+ "description": "The name of the policy"
312
319
  },
313
320
  "description": {
314
- "type": "string"
321
+ "type": "string",
322
+ "description": "Description of the policy"
315
323
  },
316
324
  "constraints": {
317
325
  "type": "array",
318
- "items": {}
326
+ "description": "Any constraints which the policy must respect",
327
+ "items": {"type": "string"}
319
328
  },
320
329
  "policy_options": {
321
330
  "type": "array",
322
331
  "items": {
323
332
  "$ref": "./schema.schema.json/#/definitions/PolicyOption"
324
- }
333
+ },
334
+ "description": "Possible implementations of the policy"
325
335
  },
326
336
  "domain": {
327
337
  "type": "array",
328
338
  "items": {
329
339
  "type": "string"
330
- }
340
+ },
341
+ "description": "The spaces which are passed in as inputs to the policy"
331
342
  },
332
343
  "codomain": {
333
344
  "type": "array",
334
345
  "items": {
335
346
  "type": "string"
336
- }
347
+ },
348
+ "description": "The spaces which are returned as results of the policy"
337
349
  },
338
350
  "parameters_used": {
339
351
  "type": "array",
340
352
  "items": {
341
353
  "type": "string"
342
- }
354
+ },
355
+ "description": "All parameters used in the implementations of policies"
343
356
  },
344
357
  "metrics_used": {
345
358
  "type": "array",
346
359
  "items": {
347
360
  "type": "string"
348
- }
361
+ },
362
+ "description": "All metrics used in implementation of policies"
349
363
  }
350
364
  },
351
365
  "required": [
@@ -366,13 +380,16 @@
366
380
  "additionalProperties": false,
367
381
  "properties": {
368
382
  "name": {
369
- "type": "string"
383
+ "type": "string",
384
+ "description": "The name of the policy option"
370
385
  },
371
386
  "description": {
372
- "type": "string"
387
+ "type": "string",
388
+ "description": "A description of the implementation"
373
389
  },
374
390
  "logic": {
375
- "type": "string"
391
+ "type": "string",
392
+ "description": "Any logic associated with the implementation"
376
393
  }
377
394
  },
378
395
  "required": [
@@ -434,38 +451,45 @@
434
451
  "additionalProperties": true,
435
452
  "properties": {
436
453
  "name": {
437
- "type": "string"
454
+ "type": "string",
455
+ "description": "Name of the boundary action"
438
456
  },
439
457
  "description": {
440
- "type": "string"
458
+ "type": "string",
459
+ "description": "Quick description of the boundary action"
441
460
  },
442
461
  "constraints": {
443
462
  "type": "array",
444
463
  "items": {
445
464
  "type": "string"
446
- }
465
+ },
466
+ "description": "Any constraints which the boundary action must respect"
447
467
  },
448
468
  "boundary_action_options": {
449
469
  "type": "array",
450
- "items": {}
470
+ "items": {},
471
+ "description": "The options for implementation of the boundary action"
451
472
  },
452
473
  "called_by": {
453
474
  "type": "array",
454
475
  "items": {
455
476
  "type": "string"
456
- }
477
+ },
478
+ "description": "The entities which are allowed to call this boundary action"
457
479
  },
458
480
  "codomain": {
459
481
  "type": "array",
460
482
  "items": {
461
483
  "type": "string"
462
- }
484
+ },
485
+ "description": "List of outputs that come out of this block"
463
486
  },
464
487
  "parameters_used": {
465
488
  "type": "array",
466
489
  "items": {
467
490
  "type": "string"
468
- }
491
+ },
492
+ "description": "The string keys of parameters which have an effect on the boundary action"
469
493
  }
470
494
  },
471
495
  "required": [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.2.6.7
3
+ Version: 0.2.8
4
4
  Summary: A library for easy mapping of mathematical specifications.
5
5
  Author-email: Sean McOwen <Sean@Block.Science>
6
6
  Classifier: Programming Language :: Python :: 3