QSBench commited on
Commit
76cdd53
·
verified ·
1 Parent(s): 048fad7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -38,7 +38,7 @@ REPO_CONFIG = {
38
  }
39
  }
40
 
41
- # Колонки, которые НЕ являются фичами (системные, категориальные или таргеты)
42
  NON_FEATURE_COLS = {
43
  "sample_id", "sample_seed", "circuit_hash", "split", "circuit_qasm",
44
  "qasm_raw", "qasm_transpiled", "circuit_type_resolved", "circuit_type_requested",
@@ -79,21 +79,21 @@ def get_methodology_content(ds_name: str):
79
  """
80
 
81
  def sync_ml_metrics(ds_name: str):
82
- """Динамически находит все доступные числовые метрики (фичи) из CSV/Dataset"""
83
  assets = load_all_assets(ds_name)
84
  df = assets["df"]
85
 
86
- # Извлекаем все числовые колонки
87
  numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
88
 
89
- # Фильтруем: убираем системные ID и таргеты (всё, что начинается на ideal/noisy/error/sign)
90
  valid_features = [
91
  c for c in numeric_cols
92
  if c not in NON_FEATURE_COLS
93
  and not any(prefix in c for prefix in ["ideal_", "noisy_", "error_", "sign_"])
94
  ]
95
 
96
- # Приоритетные метрики для выбора "по умолчанию"
97
  top_tier = ["gate_entropy", "meyer_wallach", "adjacency", "depth", "total_gates", "cx_count"]
98
  defaults = [f for f in top_tier if f in valid_features]
99
 
@@ -104,7 +104,7 @@ def train_model(ds_name: str, features: List[str]):
104
  assets = load_all_assets(ds_name)
105
  df = assets["df"]
106
 
107
- # Используем глобальное значение Z как таргет
108
  target = "ideal_expval_Z_global"
109
 
110
  train_df = df.dropna(subset=features + [target])
@@ -125,7 +125,7 @@ def train_model(ds_name: str, features: List[str]):
125
 
126
  # 2. Feature Importance
127
  imp = model.feature_importances_
128
- # Берем топ-10 если их много, или все если мало
129
  top_n = min(len(features), 10)
130
  idx = np.argsort(imp)[-top_n:]
131
  axes[1].barh([features[i] for i in idx], imp[idx], color='#27ae60')
@@ -168,7 +168,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="QSBench Hub") as demo:
168
  with gr.Row():
169
  with gr.Column(scale=1):
170
  ml_ds_sel = gr.Dropdown(list(REPO_CONFIG.keys()), value="Core (Clean)", label="Select Dataset")
171
- # Динамический список метрик, извлекаемый из CSV
172
  ml_feat_sel = gr.CheckboxGroup(label="Available Metrics (extracted from CSV)", choices=[])
173
  train_btn = gr.Button("Execute Baseline", variant="primary")
174
  with gr.Column(scale=2):
@@ -189,7 +189,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="QSBench Hub") as demo:
189
  # Explorer
190
  ds_sel.change(update_explorer, [ds_sel, sp_sel], [sp_sel, data_view, c_raw, c_tr, meta_txt])
191
 
192
- # ML Tab: Динамическое обновление метрик
193
  ml_ds_sel.change(sync_ml_metrics, [ml_ds_sel], [ml_feat_sel])
194
  train_btn.click(train_model, [ml_ds_sel, ml_feat_sel], [p_out, t_out])
195
 
 
38
  }
39
  }
40
 
41
+ # Columns that are NOT features (system, categorical, or targets)
42
  NON_FEATURE_COLS = {
43
  "sample_id", "sample_seed", "circuit_hash", "split", "circuit_qasm",
44
  "qasm_raw", "qasm_transpiled", "circuit_type_resolved", "circuit_type_requested",
 
79
  """
80
 
81
  def sync_ml_metrics(ds_name: str):
82
+ """Dynamically finds all available numerical metrics (features) from CSV/Dataset"""
83
  assets = load_all_assets(ds_name)
84
  df = assets["df"]
85
 
86
+ # Extract all numeric columns
87
  numeric_cols = df.select_dtypes(include=[np.number]).columns.tolist()
88
 
89
+ # Filter: remove system IDs and targets (anything starting with ideal/noisy/error/sign)
90
  valid_features = [
91
  c for c in numeric_cols
92
  if c not in NON_FEATURE_COLS
93
  and not any(prefix in c for prefix in ["ideal_", "noisy_", "error_", "sign_"])
94
  ]
95
 
96
+ # Priority metrics for "default" selection
97
  top_tier = ["gate_entropy", "meyer_wallach", "adjacency", "depth", "total_gates", "cx_count"]
98
  defaults = [f for f in top_tier if f in valid_features]
99
 
 
104
  assets = load_all_assets(ds_name)
105
  df = assets["df"]
106
 
107
+ # Use global Z value as target
108
  target = "ideal_expval_Z_global"
109
 
110
  train_df = df.dropna(subset=features + [target])
 
125
 
126
  # 2. Feature Importance
127
  imp = model.feature_importances_
128
+ # Take top 10 if there are many, or all if few
129
  top_n = min(len(features), 10)
130
  idx = np.argsort(imp)[-top_n:]
131
  axes[1].barh([features[i] for i in idx], imp[idx], color='#27ae60')
 
168
  with gr.Row():
169
  with gr.Column(scale=1):
170
  ml_ds_sel = gr.Dropdown(list(REPO_CONFIG.keys()), value="Core (Clean)", label="Select Dataset")
171
+ # Dynamic metrics list extracted from CSV
172
  ml_feat_sel = gr.CheckboxGroup(label="Available Metrics (extracted from CSV)", choices=[])
173
  train_btn = gr.Button("Execute Baseline", variant="primary")
174
  with gr.Column(scale=2):
 
189
  # Explorer
190
  ds_sel.change(update_explorer, [ds_sel, sp_sel], [sp_sel, data_view, c_raw, c_tr, meta_txt])
191
 
192
+ # ML Tab: Dynamic metrics update
193
  ml_ds_sel.change(sync_ml_metrics, [ml_ds_sel], [ml_feat_sel])
194
  train_btn.click(train_model, [ml_ds_sel, ml_feat_sel], [p_out, t_out])
195