Skip to content

Commit f2884fc

Browse files
authored
Merge pull request #631 from BlockScience/0.4.2
0.4.2
2 parents bf10869 + 70ca645 commit f2884fc

File tree

12 files changed

+397
-6
lines changed

12 files changed

+397
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ One good example is the [wiring report](https://github.com/BlockScience/Predator
1212

1313
## Installing the library
1414

15-
To install the library, simply pip install by running "pip install math_spec_mapping"
15+
To install the library, simply pip install by running "pip install math-spec-mapping". The pypi package can be found [here](https://pypi.org/project/math-spec-mapping/).
1616

1717
## Why MSML?
1818

dev/TypedDictionary.ipynb

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 31,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from typing import TypedDict\n",
10+
"\n"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 33,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"a = TypedDict(\"EntityType\", {\"Words\": str, \"Total Length\": int})"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 39,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"a.__repr__ = lambda x: \"A\""
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 48,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"ename": "TypeError",
38+
"evalue": "dict expected at most 1 argument, got 2",
39+
"output_type": "error",
40+
"traceback": [
41+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
42+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
43+
"\u001b[0;32m/var/folders/y0/fwkpk2ps087b_2qxvhjstrfr0000gn/T/ipykernel_57262/3336926982.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mTypedDict2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"EntityType\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m\"Words\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Total Length\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
44+
"\u001b[0;31mTypeError\u001b[0m: dict expected at most 1 argument, got 2"
45+
]
46+
}
47+
],
48+
"source": [
49+
"class TypedDict2(TypedDict):\n",
50+
" def __init__(self, typename, fields):\n",
51+
" super().__init__(typename, fields)\n",
52+
" def __repr__(self) -> str:\n",
53+
" return f\"CustomTypedDict({super().__repr__()})\"\n",
54+
" \n",
55+
" \n",
56+
"TypedDict2(\"EntityType\", {\"Words\": str, \"Total Length\": int})"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"\"Volume_per_Unit\"\n",
66+
"\n",
67+
"\"VolumeperUnit\""
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 49,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"data": {
77+
"text/plain": [
78+
"{'Words': str, 'Total Length': int}"
79+
]
80+
},
81+
"execution_count": 49,
82+
"metadata": {},
83+
"output_type": "execute_result"
84+
}
85+
],
86+
"source": [
87+
"TypedDict2({\"Words\": str, \"Total Length\": int})"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": 50,
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"class Test(TypedDict):\n",
97+
" Words: str\n",
98+
" Total_Length: int"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 47,
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"name": "stdout",
108+
"output_type": "stream",
109+
"text": [
110+
"<class '__main__.Test'>\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"print(Test)"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {},
122+
"outputs": [],
123+
"source": []
124+
}
125+
],
126+
"metadata": {
127+
"kernelspec": {
128+
"display_name": "BlockScience",
129+
"language": "python",
130+
"name": "python3"
131+
},
132+
"language_info": {
133+
"codemirror_mode": {
134+
"name": "ipython",
135+
"version": 3
136+
},
137+
"file_extension": ".py",
138+
"mimetype": "text/x-python",
139+
"name": "python",
140+
"nbconvert_exporter": "python",
141+
"pygments_lexer": "ipython3",
142+
"version": "3.9.12"
143+
}
144+
},
145+
"nbformat": 4,
146+
"nbformat_minor": 2
147+
}

docs/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: FAQ
33
layout: page
4-
nav_order: 5
4+
nav_order: 6
55
---
66

77
The following are frequently asked questions with regards to MSML.

docs/cadCADBuilder.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: cadCAD Builder
3+
layout: page
4+
nav_order: 5
5+
---
6+
7+
MSML provides interfaces for creating cadCAD style models that don't require end users poking around the actual code to use. The idea is that it provides a layer for data scientists to experiment just with toggling starting state and parameters and executing pre-packaged models.
8+
9+
## Components
10+
11+
### Inputs
12+
13+
The following is required for building the cadCAD model:
14+
15+
1. A math spec object with code bindings
16+
2. A list of blocks which should be executed for each timestep
17+
3. What state preparation and parameter preparation functions should be included to automatically run on experiment creation
18+
19+
20+
### Outputs
21+
22+
The following is outputted by the creation function:
23+
24+
1. State Space: The nested and typed dictionary of all types for the state in the simulation that the data scientist needs to define
25+
2. Parameter Space: The dictionary of parameters that the data scientist needs to define
26+
3. Model: The executable model that can spawn experiments to run given valid state space and parameter space passed
27+
28+
## Creating a cadCAD Model in a Notebook
29+
30+
The [template notebook on building cadCAD models](https://github.com/BlockScience/MSML-Template/blob/main/notebooks/Build%20cadCAD.ipynb) shows how to create a cadCAD model from an MSML model.
31+
32+
## Using cadCAD Model Repositories
33+
34+
A recommended design pattern is to have MSML developers create a batch of cadCAD models to be run within a cadCADModels folder [similar to the template](https://github.com/BlockScience/MSML-Template/tree/main/cadCADModels).
35+
36+
The template also has an example of running the pre-built cadCAD models [here](https://github.com/BlockScience/MSML-Template/blob/main/notebooks/Pre-built%20cadCAD.ipynb).
37+
38+
39+
## Model Functionality
40+
41+
### Experiment Creation
42+
43+
- To create an experiment, one runs model.create_experiment(state, params) and passes in a valid state and parameter dictionary
44+
- The record_trajectory flag if set to true will record the state after each step of the simulation
45+
- The use_deepcopy flag if set to true will use deepcopy for the trajectory recording
46+
47+
48+
### Running Experiments
49+
50+
- Using experiment.run(T) where T is the number of time steps will advance the simulations that many timesteps
51+
- If record_trajectory was set to true then the trajectories can be accessed from experiment.trajectories, if not you can always access the current state of the experiment by calling experiment.state
52+
53+
### Batch Experiments
54+
55+
- Batch experiments can be created and run through model.create_batch_experiments(...). An example of it is shown in the pre-built cadCAD notebook.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44
[project]
55
name = "math-spec-mapping"
6-
version = "0.4.1.2"
6+
version = "0.4.2"
77
authors = [
88
{ name="Sean McOwen", email="[email protected]" },
99
]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Concept Math Specs Ideation
2+
3+
## Executive Summary
4+
5+
- The following research note defines out the most parsimonious schemas and relations for a concept math spec
6+
- The idea is that this can be further enhanced and plugged into other interoperable workflows
7+
- For example, schemas for the spaces can be added in at a further point and potentially have specified types
8+
9+
## Proposed JSON Schema
10+
11+
### Space
12+
13+
1. Name: PrimaryKey, string
14+
2. Description: Optional, string
15+
16+
### Block
17+
18+
1. Name: PrimaryKey, string
19+
2. Description: Optional, string
20+
3. Domain: ForeignKeys to Space.Name, List[string]
21+
4. Codomain: ForeignKeys to Space.Name, List[string]
22+
23+
### Wiring
24+
25+
- Might need a name or something for IDs
26+
- Might want to consider allowing multiple target and source ports
27+
28+
#### Option 1:
29+
30+
1. Source: string, such as "BlockA-1" for second port of BlockA codomain
31+
2. Target: string, such as "BlockB-0" for first port of BlockB domain
32+
33+
#### Option 2:
34+
35+
1. SourceBlock: ForeignKey to Block.Name, string
36+
2. TargetBlock: ForeignKey to Block.Name, string
37+
3. Source Port: Related to SourceBlock.Codomain as the index, integer
38+
4. Target Port: Related to TargetBlock.Domain as the index, integer
39+
40+
41+
### Systems
42+
43+
1. Name: PrimaryKey, string
44+
2. Description: Optional, string
45+
3. Wirings: ForeignKeys to Wiring, List[strings]
46+
47+
48+
## Current MSML Wiring & Comparison
49+
50+
- Currently a wiring needs two components - the type (either stack or parallel) and the components, a list of blocks or wirings (there is a recursive wiring builder that makes sure the wirings get created in the right order)
51+
- For a stack block, all adjacent blocks have validations that domain and codomain map
52+
- Internally, all the port wirings are automatically built out for both mapping as well as execution
53+
- Wirings in this way can be built out to automatically map to the proposed "Wiring" schema in concept specs or potentially changed
54+
- The wirings are similar to a DAG
55+
- A stack block wiring has domain of the first component and codomain of the last component
56+
- A parallel block has the summation of component domains and component codomains
57+
- There are future potential wiring types such as a looping block or having a notation for multiple outputs of the spaces, i.e. similar to if we have 1-N outputs that are variable between a block but they all follow the same codomain space schema
58+
59+
60+
## Proposed Relational Schema V2
61+
62+
### Space
63+
64+
1. ID: PrimaryKey
65+
2. Name: string
66+
3. Description: Optional, string
67+
68+
### Block
69+
70+
1. ID: PrimaryKey
71+
2. Name: string
72+
3. Description: Optional, string
73+
74+
### Ports
75+
76+
1. ID: PrimaryKey
77+
2. Name: string
78+
3. Index: Integer
79+
4. Space: ForeignKey to Space.Name, string
80+
81+
### Terminals
82+
83+
1. ID: PrimaryKey
84+
2. Name: string
85+
3. Index: Integer
86+
4. Space: ForeignKey to Space.Name, string
87+
88+
## Proposed Schema V2
89+
90+
### Space
91+
92+
{"ID": PrimaryKey,
93+
"Name": string,
94+
"Description": string}
95+
96+
### Block
97+
98+
{"ID": PrimaryKey,
99+
"Name": string,
100+
"Description": string,
101+
"Domain": List[Space.ID],
102+
"Codomain": List[Space.ID]}
103+
104+
## Concrete Block
105+
106+
{"ID": PrimaryKey,
107+
"Name": string,
108+
"Description": string,
109+
"Parent": Block.ID}
110+
111+
- It is legal to have many to one concrete blocks of abstract blocks
112+
113+
## Wire (Concrete Space)
114+
115+
{"ID": PrimaryKey,
116+
"Parent": Space.ID,
117+
"SourceBlock": ConcreteBlock.ID,
118+
"TargetBlock": ConcreteBlock.ID,
119+
"SourceIndex": int,
120+
"TargetIndex": int}
121+
122+
- Check matches up
123+
124+
## System
125+
126+
{"ConcreteBlocks": List[ConcreteBlock.ID],
127+
"Wires": List[Wire.ID]}
128+
129+
- Check that:
130+
- All of the ports/domain need to be filled
131+
- All domain ports only get one input
132+
- Terminals can go 0...N ports (and they would just be sending replicas of the same output)

0 commit comments

Comments
 (0)