Skip to content

Commit ffd6bca

Browse files
arhamchopraNijat K
authored andcommitted
Replace build with python-build, fix package order (Point72#358)
- build feedstock is deprecated: https://github.com/conda-forge/build-feedstock Signed-off-by: Arham Chopra <[email protected]>
1 parent 07a8850 commit ffd6bca

File tree

2 files changed

+364
-0
lines changed

2 files changed

+364
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 18,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import csp\n",
10+
"from datetime import datetime, timedelta\n",
11+
"\n",
12+
"from csp.adapters.parquet import ParquetOutputConfig, ParquetReader, ParquetWriter\n",
13+
"from typing import Dict, List\n",
14+
"\n",
15+
"class MySmolStruct(csp.Struct):\n",
16+
" v: str\n",
17+
" z: int = 12\n",
18+
"\n",
19+
"class MySillyStruct(csp.Struct):\n",
20+
" header: str = \"abad\"\n",
21+
" x: int\n",
22+
" ms: MySmolStruct\n",
23+
"\n",
24+
"\n",
25+
"class MyStruct(csp.Struct):\n",
26+
" x: int\n",
27+
" v: float = 1.0\n",
28+
" bb: MySillyStruct = MySillyStruct()\n",
29+
"\n",
30+
"\n",
31+
"@csp.node\n",
32+
"def dedup(real: csp.ts[\"T\"], hist: csp.ts[\"T\"], flag: csp.ts[bool]) -> csp.ts[\"T\"]:\n",
33+
" if csp.ticked(flag):\n",
34+
" csp.make_passive(hist)\n",
35+
" \n",
36+
" if csp.ticked(hist):\n",
37+
" return real\n",
38+
" \n",
39+
" if csp.ticked(real):\n",
40+
" return real\n",
41+
"\n",
42+
"\n",
43+
"# big_vals = [MyStruct(x=3) * 100]\n",
44+
"tup_size = 1_000_000\n",
45+
"# tups = [(timedelta(microseconds= i), MyStruct(x=3) ) for i in range(tup_size)]\n",
46+
"# tup2 = [(timedelta(microseconds = i), MyStruct(x=3) ) for i in range(tup_size)]\n",
47+
"\n",
48+
"path = \"/Users/neej/dev/csp/test_tup.pq\"\n",
49+
"path2 = \"/Users/neej/dev/csp/test_tup2.pq\"\n",
50+
"\n",
51+
"@csp.graph\n",
52+
"def write_vals():\n",
53+
"\n",
54+
" writer = ParquetWriter(\n",
55+
" file_name=path, timestamp_column_name=\"csp_time\", config=ParquetOutputConfig(allow_overwrite=True)\n",
56+
" )\n",
57+
" tups = [(timedelta(microseconds= i), MyStruct(x=3) ) for i in range(tup_size)]\n",
58+
" tups_csp = csp.curve(typ=MyStruct, data=tups)\n",
59+
" writer.publish_struct(tups_csp)\n",
60+
"\n",
61+
"csp.run(write_vals, starttime=datetime(2020, 1, 1), endtime=datetime(2099, 1, 1))\n",
62+
"\n",
63+
"@csp.graph\n",
64+
"def g_fast():\n",
65+
" # vals1 = csp.curve(typ=MyStruct, data=tups)\n",
66+
" # vals2 = csp.curve( typ=MyStruct, data=tup2 )\n",
67+
" struct_reader = ParquetReader(path, time_column=\"csp_time\")\n",
68+
" vals1 = struct_reader.subscribe_all(MyStruct)\n",
69+
"\n",
70+
" struct_reader2 = ParquetReader(path2, time_column=\"csp_time\")\n",
71+
" vals2 = struct_reader2.subscribe_all(MyStruct)\n",
72+
"\n",
73+
"\n",
74+
" flag = csp.const(True)\n",
75+
" filt1 = csp.filter(flag, vals1)\n",
76+
" res = csp.merge(filt1, vals2)\n",
77+
" csp.add_graph_output(\"res\", res)\n",
78+
"\n",
79+
"\n",
80+
"\n",
81+
"@csp.graph\n",
82+
"def g_slow():\n",
83+
" struct_reader = ParquetReader(path, time_column=\"csp_time\")\n",
84+
" vals1 = struct_reader.subscribe_all(MyStruct)\n",
85+
"\n",
86+
" struct_reader2 = ParquetReader(path2, time_column=\"csp_time\")\n",
87+
" vals2 = struct_reader2.subscribe_all(MyStruct)\n",
88+
"\n",
89+
" flag = csp.const(True)\n",
90+
" res = dedup(vals1, vals2, flag)\n",
91+
" csp.add_graph_output(\"res\", res)\n",
92+
"\n",
93+
"\n",
94+
"with csp.profiler.Profiler(cycle_file=\"cycle_data_slow.csv\", node_file=\"node_data_slow.csv\") as p:\n",
95+
" csp.run(g_slow, starttime=datetime(1970, 1, 1), endtime=datetime(2099, 1, 1))\n",
96+
"\n",
97+
"with csp.profiler.Profiler(cycle_file=\"cycle_data_fast.csv\", node_file=\"node_data_fast.csv\") as p:\n",
98+
" csp.run(g_fast, starttime=datetime(1970, 1, 1), endtime=datetime(2099, 1, 1))\n",
99+
"\n"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 19,
105+
"metadata": {},
106+
"outputs": [
107+
{
108+
"name": "stdout",
109+
"output_type": "stream",
110+
"text": [
111+
"CYCLE FAST\n",
112+
"\n",
113+
"Overall Execution Time Statistics:\n"
114+
]
115+
},
116+
{
117+
"data": {
118+
"text/html": [
119+
"<div><style>\n",
120+
".dataframe > thead > tr,\n",
121+
".dataframe > tbody > tr {\n",
122+
" text-align: right;\n",
123+
" white-space: pre-wrap;\n",
124+
"}\n",
125+
"</style>\n",
126+
"<small>shape: (1, 4)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>overall_mean_time_us</th><th>overall_variance_us</th><th>overall_std_dev_us</th><th>total_samples</th></tr><tr><td>f64</td><td>f64</td><td>f64</td><td>u32</td></tr></thead><tbody><tr><td>2.859916</td><td>7.21443</td><td>2.685969</td><td>1000001</td></tr></tbody></table></div>"
127+
],
128+
"text/plain": [
129+
"shape: (1, 4)\n",
130+
"┌──────────────────────┬─────────────────────┬────────────────────┬───────────────┐\n",
131+
"│ overall_mean_time_us ┆ overall_variance_us ┆ overall_std_dev_us ┆ total_samples │\n",
132+
"│ --- ┆ --- ┆ --- ┆ --- │\n",
133+
"│ f64 ┆ f64 ┆ f64 ┆ u32 │\n",
134+
"╞══════════════════════╪═════════════════════╪════════════════════╪═══════════════╡\n",
135+
"│ 2.859916 ┆ 7.21443 ┆ 2.685969 ┆ 1000001 │\n",
136+
"└──────────────────────┴─────────────────────┴────────────────────┴───────────────┘"
137+
]
138+
},
139+
"metadata": {},
140+
"output_type": "display_data"
141+
}
142+
],
143+
"source": [
144+
"import polars as pl\n",
145+
"\n",
146+
"from IPython.display import display\n",
147+
"\n",
148+
"# df = pl.read_csv(\"node_data_fast.csv\").group_by(\"Node Type\").agg(pl.col(\"Execution Time\").sum())\n",
149+
"# display(df)\n",
150+
"# df[\"Execution Time\"].sum()\n",
151+
"\n",
152+
"df = pl.read_csv(\"cycle_data_fast.csv\")\n",
153+
"# display(df)\n",
154+
"print(\"CYCLE FAST\")\n",
155+
"import numpy as np\n",
156+
"\n",
157+
"# Overall statistics across all node types\n",
158+
"overall_stats = df.select([\n",
159+
" (pl.col('Execution Time').mean() * 1_000_000).alias('overall_mean_time_us'),\n",
160+
" (pl.col('Execution Time').var() * 1_000_000 * 1_000_000).alias('overall_variance_us'), # multiply twice since variance is squared\n",
161+
" (pl.col('Execution Time').std() * 1_000_000).alias('overall_std_dev_us'),\n",
162+
" pl.col('Execution Time').count().alias('total_samples')\n",
163+
"]).with_columns([\n",
164+
" pl.col(['overall_mean_time_us', 'overall_variance_us', 'overall_std_dev_us'])\n",
165+
"])\n",
166+
"\n",
167+
"print(\"\\nOverall Execution Time Statistics:\")\n",
168+
"display(overall_stats)"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": 20,
174+
"metadata": {},
175+
"outputs": [
176+
{
177+
"name": "stdout",
178+
"output_type": "stream",
179+
"text": [
180+
"CYCLE SLOW\n",
181+
"\n",
182+
"Overall Execution Time Statistics:\n"
183+
]
184+
},
185+
{
186+
"data": {
187+
"text/html": [
188+
"<div><style>\n",
189+
".dataframe > thead > tr,\n",
190+
".dataframe > tbody > tr {\n",
191+
" text-align: right;\n",
192+
" white-space: pre-wrap;\n",
193+
"}\n",
194+
"</style>\n",
195+
"<small>shape: (1, 4)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>overall_mean_time_us</th><th>overall_variance_us</th><th>overall_std_dev_us</th><th>total_samples</th></tr><tr><td>f64</td><td>f64</td><td>f64</td><td>u32</td></tr></thead><tbody><tr><td>1.583237</td><td>5.8768</td><td>2.424211</td><td>1000001</td></tr></tbody></table></div>"
196+
],
197+
"text/plain": [
198+
"shape: (1, 4)\n",
199+
"┌──────────────────────┬─────────────────────┬────────────────────┬───────────────┐\n",
200+
"│ overall_mean_time_us ┆ overall_variance_us ┆ overall_std_dev_us ┆ total_samples │\n",
201+
"│ --- ┆ --- ┆ --- ┆ --- │\n",
202+
"│ f64 ┆ f64 ┆ f64 ┆ u32 │\n",
203+
"╞══════════════════════╪═════════════════════╪════════════════════╪═══════════════╡\n",
204+
"│ 1.583237 ┆ 5.8768 ┆ 2.424211 ┆ 1000001 │\n",
205+
"└──────────────────────┴─────────────────────┴────────────────────┴───────────────┘"
206+
]
207+
},
208+
"metadata": {},
209+
"output_type": "display_data"
210+
}
211+
],
212+
"source": [
213+
"import polars as pl\n",
214+
"\n",
215+
"from IPython.display import display\n",
216+
"\n",
217+
"df = pl.read_csv(\"cycle_data_slow.csv\")\n",
218+
"# display(df)\n",
219+
"print(\"CYCLE SLOW\")\n",
220+
"import numpy as np\n",
221+
"\n",
222+
"# Overall statistics across all node types\n",
223+
"overall_stats = df.select([\n",
224+
" (pl.col('Execution Time').mean() * 1_000_000).alias('overall_mean_time_us'),\n",
225+
" (pl.col('Execution Time').var() * 1_000_000 * 1_000_000).alias('overall_variance_us'), # multiply twice since variance is squared\n",
226+
" (pl.col('Execution Time').std() * 1_000_000).alias('overall_std_dev_us'),\n",
227+
" pl.col('Execution Time').count().alias('total_samples')\n",
228+
"]).with_columns([\n",
229+
" pl.col(['overall_mean_time_us', 'overall_variance_us', 'overall_std_dev_us'])\n",
230+
"])\n",
231+
"\n",
232+
"print(\"\\nOverall Execution Time Statistics:\")\n",
233+
"display(overall_stats)"
234+
]
235+
}
236+
],
237+
"metadata": {
238+
"kernelspec": {
239+
"display_name": "Python 3",
240+
"language": "python",
241+
"name": "python3"
242+
},
243+
"language_info": {
244+
"codemirror_mode": {
245+
"name": "ipython",
246+
"version": 3
247+
},
248+
"file_extension": ".py",
249+
"mimetype": "text/x-python",
250+
"name": "python",
251+
"nbconvert_exporter": "python",
252+
"pygments_lexer": "ipython3",
253+
"version": "3.12.5"
254+
}
255+
},
256+
"nbformat": 4,
257+
"nbformat_minor": 2
258+
}

csp/adapters/testing_csp.ipynb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 6,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"text/plain": [
11+
"{'a': '9'}"
12+
]
13+
},
14+
"execution_count": 6,
15+
"metadata": {},
16+
"output_type": "execute_result"
17+
}
18+
],
19+
"source": [
20+
"import csp\n",
21+
"from typing import Dict\n",
22+
"\n",
23+
"class A(csp.Struct):\n",
24+
" d: Dict[str, str] = {}\n",
25+
"\n",
26+
"x = A()\n",
27+
"x.d['a'] = '9'\n",
28+
"\n",
29+
"A().d\n",
30+
"x.d"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 4,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"data": {
40+
"text/plain": [
41+
"'{\"john\": 11, \"stevie\": 12, \"my_list\": [1, 2]}'"
42+
]
43+
},
44+
"execution_count": 4,
45+
"metadata": {},
46+
"output_type": "execute_result"
47+
}
48+
],
49+
"source": [
50+
"import json\n",
51+
"\n",
52+
"d = {'john': 11, 'stevie': 12, 'my_list': [1, 2]}\n",
53+
"\n",
54+
"x = json.dumps(d)\n",
55+
"\n",
56+
"with open('test.json', 'w') as f:\n",
57+
" f.write(x)\n",
58+
"x"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 10,
64+
"metadata": {},
65+
"outputs": [
66+
{
67+
"data": {
68+
"text/plain": [
69+
"11"
70+
]
71+
},
72+
"execution_count": 10,
73+
"metadata": {},
74+
"output_type": "execute_result"
75+
}
76+
],
77+
"source": [
78+
"with open(\"test.json\", 'r') as g:\n",
79+
" raw_str = g.read()\n",
80+
"\n",
81+
"json.loads(raw_str)['john']"
82+
]
83+
}
84+
],
85+
"metadata": {
86+
"kernelspec": {
87+
"display_name": "Python 3",
88+
"language": "python",
89+
"name": "python3"
90+
},
91+
"language_info": {
92+
"codemirror_mode": {
93+
"name": "ipython",
94+
"version": 3
95+
},
96+
"file_extension": ".py",
97+
"mimetype": "text/x-python",
98+
"name": "python",
99+
"nbconvert_exporter": "python",
100+
"pygments_lexer": "ipython3",
101+
"version": "3.12.5"
102+
}
103+
},
104+
"nbformat": 4,
105+
"nbformat_minor": 2
106+
}

0 commit comments

Comments
 (0)