Skip to content

Commit 933deaf

Browse files
committed
feat: added methods for showing better contributions + added fabublox info + updated tut1 and tut3p5 and wishlist
1 parent 2587e90 commit 933deaf

File tree

5 files changed

+552
-197
lines changed

5 files changed

+552
-197
lines changed

squadds/core/db.py

Lines changed: 135 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def view_datasets(self):
300300
table = list(map(list, zip(*table)))
301301

302302
# Print the table with headers
303-
print(tabulate(table, headers=["Component", "Component Name", "Data Available", "Component Image"],tablefmt="fancy_grid"))
303+
print(tabulate(table, headers=["Component", "Component Name", "Data Available", "Component Image"],tablefmt="grid"))
304304

305305
def get_dataset_info(self, component=None, component_name=None, data_type=None):
306306
"""
@@ -361,35 +361,51 @@ def get_dataset_info(self, component=None, component_name=None, data_type=None):
361361

362362
def view_all_contributors(self):
363363
"""
364-
View all unique contributors and their relevant information.
364+
View all unique contributors and their relevant information from simulation configurations.
365365
366-
This method iterates through the configurations and extracts the relevant information
366+
This method iterates through the simulation configurations and extracts the relevant information
367367
of each contributor. It checks if the combination of uploader, PI, group, and institution
368368
is already in the list of unique contributors. If not, it adds the relevant information
369-
to the list. Finally, it prints the list of unique contributors in a tabular format.
369+
to the list. Finally, it prints the list of unique contributors in a tabular format with a banner.
370+
"""
371+
view_contributors_from_rst('../docs/source/developer/index.rst')
372+
373+
def view_all_simulation_contributors(self):
374+
"""
375+
View all unique simulation contributors and their relevant information.
370376
"""
371377
# Placeholder for the full contributor info
372378
unique_contributors_info = []
373379

380+
banner = "=" * 80
381+
title = "SIMULATION DATA CONTRIBUTORS"
382+
print(f"\n{banner}\n{title.center(80)}\n{banner}\n")
383+
374384
for config in self.configs:
375385
dataset = load_dataset(self.repo_name, config)["train"]
376386
configs_contrib_info = dataset["contributor"]
377-
387+
378388
for contrib_info in configs_contrib_info:
379389
# Extracting the relevant information
380-
relevant_info = {key: contrib_info[key] for key in ['uploader', 'PI', 'group', 'institution']}
381-
relevant_info['config'] = config # Add the config to the relevant info
390+
relevant_info = {
391+
"Uploader": contrib_info.get('uploader', 'N/A'),
392+
"PI": contrib_info.get('PI', 'N/A'),
393+
"Group": contrib_info.get('group', 'N/A'),
394+
"Institution": contrib_info.get('institution', 'N/A'),
395+
"Config": config # Add the config to the relevant info
396+
}
382397

383398
# Check if this combination of info is already in the list
384-
if not any(existing_info['config'] == config and
385-
existing_info['uploader'] == relevant_info['uploader'] and
386-
existing_info['PI'] == relevant_info['PI'] and
387-
existing_info['group'] == relevant_info['group'] and
388-
existing_info['institution'] == relevant_info['institution']
389-
for existing_info in unique_contributors_info):
399+
if not any(existing_info['Config'] == config and
400+
existing_info['Uploader'] == relevant_info['Uploader'] and
401+
existing_info['PI'] == relevant_info['PI'] and
402+
existing_info['Group'] == relevant_info['Group'] and
403+
existing_info['Institution'] == relevant_info['Institution']
404+
for existing_info in unique_contributors_info):
390405
unique_contributors_info.append(relevant_info)
391406

392-
print(tabulate(unique_contributors_info, headers="keys", tablefmt="fancy_grid"))
407+
print(tabulate(unique_contributors_info, headers="keys", tablefmt="grid"))
408+
print(f"\n{banner}\n") # End with a banner
393409

394410
def get_measured_devices(self):
395411
"""
@@ -450,7 +466,7 @@ def view_measured_devices(self):
450466
rows = [[device_info[header] for header in headers] for device_info in all_devices_info]
451467

452468
# Print the table with tabulate
453-
print(tabulate(rows, headers=headers, tablefmt="fancy_grid", stralign="left", numalign="left"))
469+
print(tabulate(rows, headers=headers, tablefmt="grid", stralign="left", numalign="left"))
454470

455471
def view_contributors_of_config(self, config):
456472
"""
@@ -472,22 +488,36 @@ def view_contributors_of_config(self, config):
472488
if relevant_info not in unique_contributors_info:
473489
unique_contributors_info.append(relevant_info)
474490

475-
print(tabulate(unique_contributors_info, headers='keys', tablefmt="fancy_grid"))
491+
print(tabulate(unique_contributors_info, headers='keys', tablefmt="grid"))
476492

477-
def view_contributors_of(self, component=None, component_name=None, data_type=None):
493+
def view_contributors_of(self, component=None, component_name=None, data_type=None, measured_device_name=None):
478494
"""
479495
View contributors of a specific component, component name, and data type.
480496
481497
Args:
482498
component (str): The component of interest.
483499
component_name (str): The name of the component.
484500
data_type (str): The type of data.
501+
measured_device_name (str): The name of the measured device.
485502
486503
Returns:
487504
None
488505
"""
489506
config = component + "-" + component_name + "-" + data_type
490-
self.view_contributors_of_config(config)
507+
try:
508+
print("="*80)
509+
print(f"\t\t\tMeasured Device Contributor(s):")
510+
print("="*80)
511+
self.view_device_contributors_of(component, component_name, data_type)
512+
except:
513+
pass
514+
try:
515+
print("="*80)
516+
print(f"\t\t\tSimulation Data Contributor(s):")
517+
print("="*80)
518+
self.view_contributors_of_config(config)
519+
except:
520+
pass
491521

492522
def view_simulation_results(self, device_name):
493523
"""
@@ -508,7 +538,44 @@ def view_simulation_results(self, device_name):
508538
return sim_results
509539
return {}
510540

511-
def view_reference_device_of(self, component=None, component_name=None, data_type=None):
541+
def get_device_contributors_of(self, component=None, component_name=None, data_type=None):
542+
"""
543+
View the reference/source experimental device that was used to validate a specific simulation configuration.
544+
545+
Args:
546+
component (str): The component of interest.
547+
component_name (str): The name of the component.
548+
data_type (str): The type of data.
549+
550+
Returns:
551+
dict: The relevant contributor information.
552+
"""
553+
if not (component and component_name and data_type):
554+
return "Component, component_name, and data_type must all be provided."
555+
556+
config = f"{component}-{component_name}-{data_type}"
557+
dataset = load_dataset(self.repo_name, 'measured_device_database')["train"]
558+
559+
for entry in zip(dataset["contrib_info"], dataset["sim_results"]):
560+
contrib_info, sim_results = entry
561+
562+
if config in sim_results:
563+
relevant_info = {
564+
"Foundry": contrib_info.get("foundry", "N/A"),
565+
"PI": contrib_info.get("PI", "N/A"),
566+
"Group": contrib_info.get("group", "N/A"),
567+
"Institution": contrib_info.get("institution", "N/A"),
568+
"Measured By": ", ".join(contrib_info.get("measured_by", [])),
569+
"Reference Device Name": contrib_info.get("name", "N/A"),
570+
"Uploader": contrib_info.get("uploader", "N/A")
571+
}
572+
573+
print(tabulate(relevant_info.items(), tablefmt="grid"))
574+
return relevant_info
575+
576+
return None
577+
578+
def view_device_contributors_of(self, component=None, component_name=None, data_type=None):
512579
"""
513580
View the reference/source experimental device that was used to validate a specific simulation configuration.
514581
@@ -518,7 +585,42 @@ def view_reference_device_of(self, component=None, component_name=None, data_typ
518585
data_type (str): The type of data.
519586
520587
Returns:
521-
str: the name of the experimentally validated reference device, or an error message if not found.
588+
str: The name of the experimentally validated reference device, or an error message if not found.
589+
"""
590+
if not (component and component_name and data_type):
591+
return "Component, component_name, and data_type must all be provided."
592+
593+
config = f"{component}-{component_name}-{data_type}"
594+
dataset = load_dataset(self.repo_name, 'measured_device_database')["train"]
595+
596+
for entry in zip(dataset["contrib_info"], dataset["sim_results"]):
597+
contrib_info, sim_results = entry
598+
599+
if config in sim_results:
600+
relevant_info = {
601+
"Foundry": contrib_info.get("foundry", "N/A"),
602+
"PI": contrib_info.get("PI", "N/A"),
603+
"Group": contrib_info.get("group", "N/A"),
604+
"Institution": contrib_info.get("institution", "N/A"),
605+
"Measured By": ", ".join(contrib_info.get("measured_by", [])),
606+
"Reference Device Name": contrib_info.get("name", "N/A"),
607+
"Uploader": contrib_info.get("uploader", "N/A")
608+
}
609+
610+
print(tabulate(relevant_info.items(), tablefmt="grid"))
611+
612+
return "The reference device could not be retrieved."
613+
614+
615+
def view_reference_device_of(self, component=None, component_name=None, data_type=None):
616+
"""
617+
View the reference/source experimental device that was used to validate a specific simulation configuration.
618+
619+
Args:
620+
component (str): The component of interest.
621+
component_name (str): The name of the component.
622+
data_type (str): The type of data.
623+
522624
"""
523625
if not (component and component_name and data_type):
524626
return "Component, component_name, and data_type must all be provided."
@@ -540,12 +642,10 @@ def view_reference_device_of(self, component=None, component_name=None, data_typ
540642
}
541643
combined_info.update(contrib_info)
542644

543-
print(tabulate(combined_info.items(), headers=["Key", "Value"], tablefmt="grid"))
544-
return contrib_info['name']
645+
print(tabulate(combined_info.items(), tablefmt="grid"))
545646

546-
return "The reference device could not be retrieved."
547647

548-
def get_recipe_of(self, device_name):
648+
def view_recipe_of(self, device_name):
549649
"""
550650
Retrieve the foundry and fabrication recipe information for a specified device.
551651
@@ -557,14 +657,18 @@ def get_recipe_of(self, device_name):
557657
"""
558658
dataset = load_dataset(self.repo_name, 'measured_device_database')["train"]
559659

560-
for contrib_info, foundry, recipe in zip(dataset["contrib_info"], dataset["foundry"], dataset["fabrication_recipe"]):
660+
for contrib_info, foundry, recipe, github_url in zip(dataset["contrib_info"], dataset["foundry"], dataset["fabrication_recipe"], dataset["design_code"],):
561661
if contrib_info['name'] == device_name:
562-
return {
563-
"Foundry": foundry,
564-
"Fabrication Recipe": recipe
565-
}
662+
# append tree/main/Fabrication to the github_url
663+
github_url = f"{github_url}/tree/main/Fabrication"
664+
# Prepare the data for tabulation
665+
data = [["Foundry", foundry], ["Fabublox Link", recipe], ["Fabrication Recipe Links", github_url]]
666+
667+
# Print the data in a tabulated format
668+
print(tabulate(data, tablefmt="grid"))
669+
return
566670

567-
return {"Error": "Device not found in the dataset."}
671+
print("Error: Device not found in the dataset.")
568672

569673
def view_reference_devices(self):
570674
"""
@@ -590,7 +694,7 @@ def view_reference_devices(self):
590694
if relevant_info not in unique_contributors_info:
591695
unique_contributors_info.append(relevant_info)
592696

593-
print(tabulate(unique_contributors_info, headers='keys', tablefmt="fancy_grid"))
697+
print(tabulate(unique_contributors_info, headers='keys', tablefmt="grid"))
594698

595699

596700
def select_components(self, component_dict=None):

squadds/core/utils.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
import getpass
22
import os
33
import platform
4+
import re
45
import shutil
56
import urllib.parse
67
import webbrowser
78

89
import numpy as np
910
import pandas as pd
1011
from huggingface_hub import HfApi, HfFolder
12+
from tabulate import tabulate
1113

1214
from squadds.core.globals import ENV_FILE_PATH
1315

1416

17+
def view_contributors_from_rst(rst_file_path):
18+
"""
19+
Extract and print relevant contributor information from the index.rst file.
20+
21+
Args:
22+
rst_file_path (str): The path to the `index.rst` file.
23+
24+
Returns:
25+
None
26+
"""
27+
28+
contributors_data = []
29+
30+
with open(rst_file_path, 'r') as file:
31+
content = file.read()
32+
33+
# Find the Contributors section
34+
contributors_match = re.search(r'Contributors\s+-{3,}\s+(.*?)(\n\n|$)', content, re.S)
35+
if contributors_match:
36+
contributors_section = contributors_match.group(1).strip()
37+
38+
# Extract individual contributor entries
39+
contributor_entries = contributors_section.split("\n| ")
40+
41+
for entry in contributor_entries:
42+
if entry.strip():
43+
# Extract name, institution, and contribution
44+
match = re.match(r'\*\*(.*?)\*\* \((.*?)\) - (.*)', entry.strip())
45+
if match:
46+
name = match.group(1)
47+
institution = match.group(2)
48+
contribution = match.group(3)
49+
contributors_data.append([name, institution, contribution])
50+
51+
if contributors_data:
52+
headers = ["Name", "Institution", "Contribution"]
53+
print(tabulate(contributors_data, headers=headers, tablefmt="grid"))
54+
else:
55+
print("No contributors found in the RST file.")
56+
57+
1558
def save_intermediate_df(df, filename, file_idx):
1659
"""
1760
Save the intermediate DataFrame to disk in Parquet format.

0 commit comments

Comments
 (0)