Spaces:
Running
Running
Nikolay Yankovich commited on
Commit ·
23e7f59
1
Parent(s): 0090949
fix
Browse files
app.py
CHANGED
|
@@ -1,23 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 4 |
from datasets import load_dataset
|
| 5 |
from sklearn.ensemble import RandomForestRegressor
|
| 6 |
from sklearn.metrics import r2_score
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
-
# Загру
|
| 10 |
ds = load_dataset("QSBench/QSBench-Core-v1.0.0-demo")
|
| 11 |
|
| 12 |
-
# Функция для отображения данных выбранного сплита
|
| 13 |
def show_data(split):
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
# Функция для обучения модели
|
| 18 |
-
def
|
| 19 |
feature_cols = ["total_gates", "gate_entropy", "meyer_wallach"]
|
| 20 |
target_col = "ideal_expval_Z_global"
|
|
|
|
| 21 |
X_train = pd.DataFrame(ds["train"])[feature_cols]
|
| 22 |
y_train = pd.DataFrame(ds["train"])[target_col]
|
| 23 |
X_test = pd.DataFrame(ds["test"])[feature_cols]
|
|
@@ -36,25 +40,50 @@ def train_and_plot():
|
|
| 36 |
ax.set_title(f"Predictions vs. Truth (R² = {r2:.4f})")
|
| 37 |
return fig
|
| 38 |
|
|
|
|
| 39 |
with gr.Blocks(title="QSBench Demo Explorer") as demo:
|
| 40 |
gr.Markdown("""
|
| 41 |
# QSBench Core Demo Explorer
|
| 42 |
-
Interactive demo of the **QSBench Core Demo** dataset – 200 synthetic quantum circuits (6 qubits, depth 4).
|
| 43 |
This space shows how to load the data, inspect it, and train a simple model on the ideal expectation values.
|
| 44 |
|
| 45 |
👉 **Full datasets (up to 200k samples, noisy versions, 10‑qubit transpilation packs) are available for purchase.**
|
| 46 |
[Visit the QSBench website](https://qsbench.github.io/)
|
| 47 |
""")
|
|
|
|
| 48 |
with gr.Tabs():
|
| 49 |
with gr.TabItem("Data Explorer"):
|
| 50 |
-
split_selector = gr.Dropdown(
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with gr.TabItem("Model Demo"):
|
| 54 |
train_button = gr.Button("Train Random Forest")
|
| 55 |
plot_output = gr.Plot()
|
| 56 |
-
train_button.click(fn=
|
|
|
|
| 57 |
gr.Markdown("---")
|
| 58 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from datasets import load_dataset
|
| 4 |
from sklearn.ensemble import RandomForestRegressor
|
| 5 |
from sklearn.metrics import r2_score
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
|
| 8 |
+
# Загружаем датасет один раз при старте
|
| 9 |
ds = load_dataset("QSBench/QSBench-Core-v1.0.0-demo")
|
| 10 |
|
| 11 |
+
# Функция для отображения таблицы данных выбранного сплита
|
| 12 |
def show_data(split):
|
| 13 |
+
try:
|
| 14 |
+
df = pd.DataFrame(ds[split])
|
| 15 |
+
# Показываем первые 10 строк, все колонки
|
| 16 |
+
return df.head(10)
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"Error loading data: {e}"
|
| 19 |
|
| 20 |
+
# Функция для обучения модели и создания графика
|
| 21 |
+
def train_model():
|
| 22 |
feature_cols = ["total_gates", "gate_entropy", "meyer_wallach"]
|
| 23 |
target_col = "ideal_expval_Z_global"
|
| 24 |
+
|
| 25 |
X_train = pd.DataFrame(ds["train"])[feature_cols]
|
| 26 |
y_train = pd.DataFrame(ds["train"])[target_col]
|
| 27 |
X_test = pd.DataFrame(ds["test"])[feature_cols]
|
|
|
|
| 40 |
ax.set_title(f"Predictions vs. Truth (R² = {r2:.4f})")
|
| 41 |
return fig
|
| 42 |
|
| 43 |
+
# Интерфейс
|
| 44 |
with gr.Blocks(title="QSBench Demo Explorer") as demo:
|
| 45 |
gr.Markdown("""
|
| 46 |
# QSBench Core Demo Explorer
|
| 47 |
+
Interactive demo of the **QSBench Core Demo** dataset – 200 synthetic quantum circuits (6 qubits, depth 4).
|
| 48 |
This space shows how to load the data, inspect it, and train a simple model on the ideal expectation values.
|
| 49 |
|
| 50 |
👉 **Full datasets (up to 200k samples, noisy versions, 10‑qubit transpilation packs) are available for purchase.**
|
| 51 |
[Visit the QSBench website](https://qsbench.github.io/)
|
| 52 |
""")
|
| 53 |
+
|
| 54 |
with gr.Tabs():
|
| 55 |
with gr.TabItem("Data Explorer"):
|
| 56 |
+
split_selector = gr.Dropdown(
|
| 57 |
+
choices=["train", "validation", "test"],
|
| 58 |
+
label="Choose a split",
|
| 59 |
+
value="train"
|
| 60 |
+
)
|
| 61 |
+
data_table = gr.Dataframe(
|
| 62 |
+
label="First 10 rows",
|
| 63 |
+
interactive=False
|
| 64 |
+
)
|
| 65 |
+
split_selector.change(
|
| 66 |
+
fn=show_data,
|
| 67 |
+
inputs=split_selector,
|
| 68 |
+
outputs=data_table
|
| 69 |
+
)
|
| 70 |
+
# Загружаем данные по умолчанию при старте
|
| 71 |
+
demo.load(fn=lambda: show_data("train"), outputs=data_table)
|
| 72 |
+
|
| 73 |
with gr.TabItem("Model Demo"):
|
| 74 |
train_button = gr.Button("Train Random Forest")
|
| 75 |
plot_output = gr.Plot()
|
| 76 |
+
train_button.click(fn=train_model, outputs=plot_output)
|
| 77 |
+
|
| 78 |
gr.Markdown("---")
|
| 79 |
+
gr.Markdown("""
|
| 80 |
+
### Get the full datasets
|
| 81 |
+
- **QSBench Core** – 75k clean circuits (8 qubits)
|
| 82 |
+
- **Depolarizing Noise Pack** – 150k circuits with depolarizing noise
|
| 83 |
+
- **Amplitude Damping Pack** – 150k circuits with T1‑like relaxation
|
| 84 |
+
- **Transpilation Hardware Pack** – 200k circuits (10 qubits) with hardware‑aware transpilation
|
| 85 |
+
|
| 86 |
+
🔗 [Browse all datasets and purchase licenses](https://qsbench.github.io/)
|
| 87 |
+
""")
|
| 88 |
|
| 89 |
demo.launch()
|