math-spec-mapping 0.3.6__tar.gz → 0.3.7__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.3.6/src/math_spec_mapping.egg-info → math_spec_mapping-0.3.7}/PKG-INFO +4 -3
  2. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/README.md +3 -2
  3. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/pyproject.toml +1 -1
  4. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/MathSpec.py +103 -3
  5. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7/src/math_spec_mapping.egg-info}/PKG-INFO +4 -3
  6. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/LICENSE +0 -0
  7. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/setup.cfg +0 -0
  8. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/ActionTransmissionChannel.py +0 -0
  9. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Block.py +0 -0
  10. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/BoundaryAction.py +0 -0
  11. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/ControlAction.py +0 -0
  12. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Entity.py +0 -0
  13. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Mechanism.py +0 -0
  14. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Metric.py +0 -0
  15. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Parameter.py +0 -0
  16. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Policy.py +0 -0
  17. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Space.py +0 -0
  18. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/State.py +0 -0
  19. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/StateUpdateTransmissionChannel.py +0 -0
  20. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/StatefulMetric.py +0 -0
  21. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/Type.py +0 -0
  22. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Classes/__init__.py +0 -0
  23. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Convenience/__init__.py +0 -0
  24. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Convenience/documentation.py +0 -0
  25. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Convenience/starter.py +0 -0
  26. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/__init__.py +0 -0
  27. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/action_transmission_channel.py +0 -0
  28. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/boundary_actions.py +0 -0
  29. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/control_actions.py +0 -0
  30. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/displays.py +0 -0
  31. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/entities.py +0 -0
  32. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/general.py +0 -0
  33. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/implementations.py +0 -0
  34. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/load.py +0 -0
  35. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/mechanism.py +0 -0
  36. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/metrics.py +0 -0
  37. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/parameters.py +0 -0
  38. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/policy.py +0 -0
  39. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/spaces.py +0 -0
  40. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/state_update_transmission_channels.py +0 -0
  41. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/stateful_metrics.py +0 -0
  42. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/states.py +0 -0
  43. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/type.py +0 -0
  44. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Load/wiring.py +0 -0
  45. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/__init__.py +0 -0
  46. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/boundary_actions.py +0 -0
  47. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/control_actions.py +0 -0
  48. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/general.py +0 -0
  49. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/html.py +0 -0
  50. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/markdown.py +0 -0
  51. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/mechanisms.py +0 -0
  52. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/node_map.py +0 -0
  53. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/parameters.py +0 -0
  54. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/policies.py +0 -0
  55. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/spaces.py +0 -0
  56. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/state.py +0 -0
  57. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/tables.py +0 -0
  58. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/Reports/wiring.py +0 -0
  59. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/__init__.py +0 -0
  60. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/schema.py +0 -0
  61. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping/schema.schema.json +0 -0
  62. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping.egg-info/SOURCES.txt +0 -0
  63. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping.egg-info/dependency_links.txt +0 -0
  64. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/src/math_spec_mapping.egg-info/requires.txt +0 -0
  65. {math_spec_mapping-0.3.6 → math_spec_mapping-0.3.7}/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.3.6
3
+ Version: 0.3.7
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
@@ -45,8 +45,9 @@ Writing mathematical specifications can be a difficult process, especially when
45
45
  ```mermaid
46
46
  graph TD
47
47
  A[JSON Object \n\n Each spec has a repo for tracking changes \n Must conform to the json specification \n Defines all aspects of the spec including blocks, spaces and actions] -->B[MSML Object \n\n JSON file is parsed, with validations and mappings along the way \n Can show different views on the fly]
48
- B --> C[Report Outputs \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ]
49
-
48
+ B --> C[Report Outputs & Obsidian Directory \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ\n Also builds an entire Obsidian directory of all components as linked notes]
49
+ D[Python Function Implementations \n\n Optional enhancement to actually execute code\n Done for each referenced policy option, mechanism, etc. \n Just needs a function definition for each] --> B
50
+ B --> E[Python Wirings & Simulations \n\n MSML can be used to run blocks \n Wirings automatically work to pass between domain/codomains \n Entire simulations can be built up as composed wirings]
50
51
  ```
51
52
 
52
53
  ## MSML in the Engineering Lifecycle
@@ -30,8 +30,9 @@ Writing mathematical specifications can be a difficult process, especially when
30
30
  ```mermaid
31
31
  graph TD
32
32
  A[JSON Object \n\n Each spec has a repo for tracking changes \n Must conform to the json specification \n Defines all aspects of the spec including blocks, spaces and actions] -->B[MSML Object \n\n JSON file is parsed, with validations and mappings along the way \n Can show different views on the fly]
33
- B --> C[Report Outputs \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ]
34
-
33
+ B --> C[Report Outputs & Obsidian Directory \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ\n Also builds an entire Obsidian directory of all components as linked notes]
34
+ D[Python Function Implementations \n\n Optional enhancement to actually execute code\n Done for each referenced policy option, mechanism, etc. \n Just needs a function definition for each] --> B
35
+ B --> E[Python Wirings & Simulations \n\n MSML can be used to run blocks \n Wirings automatically work to pass between domain/codomains \n Entire simulations can be built up as composed wirings]
35
36
  ```
36
37
 
37
38
  ## MSML in the Engineering Lifecycle
@@ -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.3.6"
6
+ version = "0.3.7"
7
7
  authors = [
8
8
  { name="Sean McOwen", email="Sean@Block.Science" },
9
9
  ]
@@ -7,6 +7,7 @@ from .BoundaryAction import BoundaryAction
7
7
  import os
8
8
  from copy import deepcopy
9
9
  import shutil
10
+ import pandas as pd
10
11
 
11
12
 
12
13
  class MathSpec:
@@ -469,6 +470,75 @@ class MathSpec:
469
470
  with open(path, "w") as f:
470
471
  f.write(out)
471
472
 
473
+ def run_experiment(
474
+ self,
475
+ experiment,
476
+ params_base,
477
+ state_base,
478
+ post_processing_function,
479
+ state_preperation_functions=None,
480
+ metrics_functions=None,
481
+ ):
482
+ if experiment["Param Modifications"]:
483
+ params_base = deepcopy(params_base)
484
+ for key in experiment["Param Modifications"]:
485
+ params_base[key] = experiment["Param Modifications"][key]
486
+ msi = self.build_implementation(params_base)
487
+ state, params = msi.prepare_state_and_params(
488
+ state_base,
489
+ params_base,
490
+ state_preperation_functions=state_preperation_functions,
491
+ )
492
+
493
+ state = msi.execute_blocks(state, params, experiment["Blocks"])
494
+ df = post_processing_function(state, params)
495
+
496
+ if metrics_functions:
497
+ metrics = {}
498
+ for metrics_function in metrics_functions:
499
+ metrics_function(metrics, state, params, df)
500
+ metrics = pd.Series(metrics)
501
+ else:
502
+ metrics = None
503
+
504
+ return state, params, msi, df, metrics
505
+
506
+ def run_experiments(
507
+ self,
508
+ experiments,
509
+ params_base,
510
+ state_base,
511
+ post_processing_function,
512
+ state_preperation_functions=None,
513
+ metrics_functions=None,
514
+ ):
515
+ state_l = []
516
+ params_l = []
517
+ df_l = []
518
+ metrics_l = []
519
+ for experiment in experiments:
520
+ for i in range(experiment["Monte Carlo Runs"]):
521
+ state, params, msi, df, metrics = self.run_experiment(
522
+ experiment,
523
+ params_base,
524
+ state_base,
525
+ post_processing_function,
526
+ state_preperation_functions=state_preperation_functions,
527
+ metrics_functions=metrics_functions,
528
+ )
529
+ df["Monte Carlo Run"] = i + 1
530
+ df["Experiment"] = experiment["Name"]
531
+ metrics.loc["Monte Carlo Run"] = i + 1
532
+ metrics.loc["Experiment"] = experiment["Name"]
533
+ metrics.name = "{}-{}".format(experiment["Name"], i + 1)
534
+ state_l.append(state)
535
+ params_l.append(params)
536
+ df_l.append(df)
537
+ metrics_l.append(metrics)
538
+ df = pd.concat(df_l)
539
+ metrics = pd.concat(metrics_l, axis=1).T
540
+ return df, metrics, state_l, params_l
541
+
472
542
  def metaprogramming_python_states(
473
543
  self, model_directory, overwrite=False, default_values=None
474
544
  ):
@@ -698,6 +768,7 @@ class MathSpecImplementation:
698
768
  self.mechanisms = self.load_mechanisms()
699
769
  self.stateful_metrics = self.load_stateful_metrics()
700
770
  self.load_wiring()
771
+ self.load_components()
701
772
 
702
773
  def load_control_actions(self):
703
774
  control_actions = {}
@@ -776,6 +847,9 @@ class MathSpecImplementation:
776
847
 
777
848
  def load_single_wiring(self, wiring):
778
849
  hold = wiring
850
+ domain_sizes = {}
851
+ for x in wiring.components:
852
+ domain_sizes[x.name] = len(x.domain)
779
853
  components = [x.name for x in wiring.components]
780
854
  if wiring.block_type == "Stack Block":
781
855
 
@@ -795,10 +869,17 @@ class MathSpecImplementation:
795
869
  spaces_mapping[x].append(i)
796
870
 
797
871
  def wiring(state, params, spaces):
872
+ spaces_mapping_temp = deepcopy(spaces_mapping)
798
873
  codomain = []
799
874
  for component in components:
800
- if component in spaces_mapping:
801
- spaces_i = [spaces[i] for i in spaces_mapping[component]]
875
+ if component in spaces_mapping_temp:
876
+ spaces_i = [spaces[i] for i in spaces_mapping_temp[component]][
877
+ : domain_sizes[component]
878
+ ]
879
+ # Fix for repeated block names
880
+ spaces_mapping_temp[component] = spaces_mapping_temp[component][
881
+ domain_sizes[component] :
882
+ ]
802
883
  else:
803
884
  assert component in [
804
885
  x.name for x in hold.domain_blocks_empty
@@ -926,9 +1007,28 @@ class MathSpecImplementation:
926
1007
  len(shouldnt_be_in_params) == 0
927
1008
  ), "The following parameters are extra: {}".format(shouldnt_be_in_params)
928
1009
 
929
- def prepare_state_and_params(self, state, params):
1010
+ def prepare_state_and_params(self, state, params, state_preperation_functions=None):
930
1011
  self.validate_state_and_params(state, params)
931
1012
  state = deepcopy(state)
932
1013
  params = deepcopy(params)
933
1014
  state["Stateful Metrics"] = self.stateful_metrics
1015
+ if state_preperation_functions:
1016
+ for f in state_preperation_functions:
1017
+ state = f(state)
1018
+ assert (
1019
+ state is not None
1020
+ ), "A state must be returned from the state preperation functions"
934
1021
  return state, params
1022
+
1023
+ def load_components(self):
1024
+ self.components = {}
1025
+ self.components.update(self.control_actions)
1026
+ self.components.update(self.boundary_actions)
1027
+ self.components.update(self.policies)
1028
+ self.components.update(self.mechanisms)
1029
+ self.components.update(self.wiring)
1030
+
1031
+ def execute_blocks(self, state, params, blocks):
1032
+ for block in blocks:
1033
+ self.components[block](state, params, [])
1034
+ return state
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: math-spec-mapping
3
- Version: 0.3.6
3
+ Version: 0.3.7
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
@@ -45,8 +45,9 @@ Writing mathematical specifications can be a difficult process, especially when
45
45
  ```mermaid
46
46
  graph TD
47
47
  A[JSON Object \n\n Each spec has a repo for tracking changes \n Must conform to the json specification \n Defines all aspects of the spec including blocks, spaces and actions] -->B[MSML Object \n\n JSON file is parsed, with validations and mappings along the way \n Can show different views on the fly]
48
- B --> C[Report Outputs \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ]
49
-
48
+ B --> C[Report Outputs & Obsidian Directory \n\n Automatically build reports for the full spec or subviews \n Example: all blocks with an effect on variable XYZ\n Also builds an entire Obsidian directory of all components as linked notes]
49
+ D[Python Function Implementations \n\n Optional enhancement to actually execute code\n Done for each referenced policy option, mechanism, etc. \n Just needs a function definition for each] --> B
50
+ B --> E[Python Wirings & Simulations \n\n MSML can be used to run blocks \n Wirings automatically work to pass between domain/codomains \n Entire simulations can be built up as composed wirings]
50
51
  ```
51
52
 
52
53
  ## MSML in the Engineering Lifecycle