Upload download_dataset.py
Browse files- download_dataset.py +82 -0
download_dataset.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from mlcroissant import Dataset
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
# Load dataset (using local JSON-LD file)
|
| 6 |
+
ds = Dataset(jsonld="chipbench_meta_data.json")
|
| 7 |
+
|
| 8 |
+
# Get test cases record set
|
| 9 |
+
# test_cases = ds.records("verilog_file")
|
| 10 |
+
|
| 11 |
+
# Function to create directories
|
| 12 |
+
def ensure_dir(file_path):
|
| 13 |
+
directory = os.path.dirname(file_path)
|
| 14 |
+
if directory and not os.path.exists(directory):
|
| 15 |
+
os.makedirs(directory)
|
| 16 |
+
|
| 17 |
+
# Process Verilog files
|
| 18 |
+
for case in ds.records("verilog_file"):
|
| 19 |
+
case_name = case["verilog_file/design_name"]
|
| 20 |
+
verilog_content = case["verilog_file/verilog_content"]
|
| 21 |
+
verilog_path = case["verilog_file/verilog_path"]
|
| 22 |
+
print(f"Creating Verilog file: {verilog_path}")
|
| 23 |
+
ensure_dir(verilog_path)
|
| 24 |
+
with open(verilog_path, 'w') as f:
|
| 25 |
+
# Convert bytes to str if necessary
|
| 26 |
+
if isinstance(verilog_content, bytes):
|
| 27 |
+
verilog_content = verilog_content.decode('utf-8')
|
| 28 |
+
f.write(verilog_content)
|
| 29 |
+
|
| 30 |
+
# Process SDC files
|
| 31 |
+
for sdc_case in ds.records("sdc_file"):
|
| 32 |
+
sdc_name = sdc_case["sdc_file/design_name"]
|
| 33 |
+
sdc_content = sdc_case["sdc_file/sdc_content"]
|
| 34 |
+
sdc_path = sdc_case["sdc_file/sdc_path"]
|
| 35 |
+
print(f"Creating SDC file: {sdc_path}")
|
| 36 |
+
ensure_dir(sdc_path)
|
| 37 |
+
with open(sdc_path, 'w') as f:
|
| 38 |
+
# Convert bytes to str if necessary
|
| 39 |
+
if isinstance(sdc_content, bytes):
|
| 40 |
+
sdc_content = sdc_content.decode('utf-8')
|
| 41 |
+
f.write(sdc_content)
|
| 42 |
+
|
| 43 |
+
# Process LEF files
|
| 44 |
+
for lef_case in ds.records("lef_file"):
|
| 45 |
+
lef_name = lef_case["lef_file/design_name"]
|
| 46 |
+
lef_content = lef_case["lef_file/lef_content"]
|
| 47 |
+
lef_path = lef_case["lef_file/lef_paths"]
|
| 48 |
+
print(f"Creating LEF file: {lef_path}")
|
| 49 |
+
ensure_dir(lef_path)
|
| 50 |
+
with open(lef_path, 'w') as f:
|
| 51 |
+
# Convert bytes to str if necessary
|
| 52 |
+
if isinstance(lef_content, bytes):
|
| 53 |
+
lef_content = lef_content.decode('utf-8')
|
| 54 |
+
f.write(lef_content)
|
| 55 |
+
|
| 56 |
+
# Process DEF files
|
| 57 |
+
for def_case in ds.records("def_file"):
|
| 58 |
+
def_name = def_case["def_file/design_name"]
|
| 59 |
+
def_content = def_case["def_file/def_content"]
|
| 60 |
+
def_path = def_case["def_file/def_paths"]
|
| 61 |
+
print(f"Creating DEF file: {def_path}")
|
| 62 |
+
ensure_dir(def_path)
|
| 63 |
+
with open(def_path, 'w') as f:
|
| 64 |
+
# Convert bytes to str if necessary
|
| 65 |
+
if isinstance(def_content, bytes):
|
| 66 |
+
def_content = def_content.decode('utf-8')
|
| 67 |
+
f.write(def_content)
|
| 68 |
+
|
| 69 |
+
# Process Liberty files
|
| 70 |
+
for liberty_case in ds.records("lib_file"):
|
| 71 |
+
liberty_name = liberty_case["lib_file/design_name"]
|
| 72 |
+
liberty_content = liberty_case["lib_file/lib_content"]
|
| 73 |
+
liberty_path = liberty_case["lib_file/lib_paths"]
|
| 74 |
+
print(f"Creating Liberty file: {liberty_path}")
|
| 75 |
+
ensure_dir(liberty_path)
|
| 76 |
+
with open(liberty_path, 'w') as f:
|
| 77 |
+
# Convert bytes to str if necessary
|
| 78 |
+
if isinstance(liberty_content, bytes):
|
| 79 |
+
liberty_content = liberty_content.decode('utf-8')
|
| 80 |
+
f.write(liberty_content)
|
| 81 |
+
|
| 82 |
+
print("All files created successfully!")
|