1- kDimensionGeneralizationPasses = "dimension_generalization_passes"
2- kDataTypeGeneralizationPasses = "data_type_generalization_passes"
3-
41import json
52from pathlib import Path
63from typing import Union
74
5+ kDimensionGeneralizationPasses = "dimension_generalization_passes"
6+ kDataTypeGeneralizationPasses = "data_type_generalization_passes"
7+ kSymbolicDimensionReifier = "symbolic_dimension_reifier"
8+
9+
10+ def read_json (model_path ):
11+ """
12+ Read JSON from graph_net.json file.
13+
14+ Args:
15+ model_path: Path to model directory
16+
17+ Returns:
18+ Dictionary containing JSON data
19+ """
20+ graph_net_json_file_path = Path (f"{ model_path } /graph_net.json" )
21+ return json .loads (graph_net_json_file_path .read_text ())
22+
823
924def update_json (json_path : Union [str , Path ], updates : dict ) -> None :
1025 """
@@ -15,19 +30,35 @@ def update_json(json_path: Union[str, Path], updates: dict) -> None:
1530 updates: Dictionary of key-value pairs to update
1631 """
1732 json_path = Path (json_path )
18-
33+
1934 # Read existing JSON
2035 if json_path .exists ():
2136 with open (json_path , "r" ) as f :
2237 metadata = json .load (f )
2338 else :
2439 metadata = {}
25-
40+
2641 # Apply updates
2742 metadata .update (updates )
28-
43+
2944 # Atomic write: write to temp file then rename
3045 temp_path = json_path .with_suffix (".json.tmp" )
3146 with open (temp_path , "w" ) as f :
3247 json .dump (metadata , f , indent = 4 )
3348 temp_path .replace (json_path )
49+
50+
51+ # Backward compatibility: old interface using model_path, field, value
52+ def update_json_legacy (model_path , field , value ):
53+ """
54+ Legacy interface for updating a single field in graph_net.json.
55+
56+ Args:
57+ model_path: Path to model directory
58+ field: Field name to update
59+ value: Value to set
60+ """
61+ graph_net_json_file_path = Path (f"{ model_path } /graph_net.json" )
62+ graph_net_json = json .loads (graph_net_json_file_path .read_text ())
63+ graph_net_json [field ] = value
64+ graph_net_json_file_path .write_text (json .dumps (graph_net_json , indent = 4 ))
0 commit comments