Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Libraries:
Datasets
pandas
License:
ChiPBench-D / download_dataset.py
ZhaojieTu's picture
Upload download_dataset.py
8817574 verified
import os
from mlcroissant import Dataset
import re
# Load dataset (using local JSON-LD file)
ds = Dataset(jsonld="chipbench_meta_data.json")
# Get test cases record set
# test_cases = ds.records("verilog_file")
# Function to create directories
def ensure_dir(file_path):
directory = os.path.dirname(file_path)
if directory and not os.path.exists(directory):
os.makedirs(directory)
# Process Verilog files
for case in ds.records("verilog_file"):
case_name = case["verilog_file/design_name"]
verilog_content = case["verilog_file/verilog_content"]
verilog_path = case["verilog_file/verilog_path"]
print(f"Creating Verilog file: {verilog_path}")
ensure_dir(verilog_path)
with open(verilog_path, 'w') as f:
# Convert bytes to str if necessary
if isinstance(verilog_content, bytes):
verilog_content = verilog_content.decode('utf-8')
f.write(verilog_content)
# Process SDC files
for sdc_case in ds.records("sdc_file"):
sdc_name = sdc_case["sdc_file/design_name"]
sdc_content = sdc_case["sdc_file/sdc_content"]
sdc_path = sdc_case["sdc_file/sdc_path"]
print(f"Creating SDC file: {sdc_path}")
ensure_dir(sdc_path)
with open(sdc_path, 'w') as f:
# Convert bytes to str if necessary
if isinstance(sdc_content, bytes):
sdc_content = sdc_content.decode('utf-8')
f.write(sdc_content)
# Process LEF files
for lef_case in ds.records("lef_file"):
lef_name = lef_case["lef_file/design_name"]
lef_content = lef_case["lef_file/lef_content"]
lef_path = lef_case["lef_file/lef_paths"]
print(f"Creating LEF file: {lef_path}")
ensure_dir(lef_path)
with open(lef_path, 'w') as f:
# Convert bytes to str if necessary
if isinstance(lef_content, bytes):
lef_content = lef_content.decode('utf-8')
f.write(lef_content)
# Process DEF files
for def_case in ds.records("def_file"):
def_name = def_case["def_file/design_name"]
def_content = def_case["def_file/def_content"]
def_path = def_case["def_file/def_paths"]
print(f"Creating DEF file: {def_path}")
ensure_dir(def_path)
with open(def_path, 'w') as f:
# Convert bytes to str if necessary
if isinstance(def_content, bytes):
def_content = def_content.decode('utf-8')
f.write(def_content)
# Process Liberty files
for liberty_case in ds.records("lib_file"):
liberty_name = liberty_case["lib_file/design_name"]
liberty_content = liberty_case["lib_file/lib_content"]
liberty_path = liberty_case["lib_file/lib_paths"]
print(f"Creating Liberty file: {liberty_path}")
ensure_dir(liberty_path)
with open(liberty_path, 'w') as f:
# Convert bytes to str if necessary
if isinstance(liberty_content, bytes):
liberty_content = liberty_content.decode('utf-8')
f.write(liberty_content)
print("All files created successfully!")