Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| from datasets import load_dataset | |
| from sklearn.ensemble import RandomForestRegressor | |
| from sklearn.metrics import r2_score | |
| import matplotlib.pyplot as plt | |
| # Загрузка датасета | |
| ds = load_dataset("QSBench/QSBench-Core-v1.0.0-demo") | |
| # Функция для отображения данных выбранного сплита | |
| def show_data(split): | |
| df = pd.DataFrame(ds[split]) | |
| return df.head(10) | |
| # Функция для обучения модели | |
| def train_and_plot(): | |
| feature_cols = ["total_gates", "gate_entropy", "meyer_wallach"] | |
| target_col = "ideal_expval_Z_global" | |
| X_train = pd.DataFrame(ds["train"])[feature_cols] | |
| y_train = pd.DataFrame(ds["train"])[target_col] | |
| X_test = pd.DataFrame(ds["test"])[feature_cols] | |
| y_test = pd.DataFrame(ds["test"])[target_col] | |
| model = RandomForestRegressor(n_estimators=100, random_state=42) | |
| model.fit(X_train, y_train) | |
| y_pred = model.predict(X_test) | |
| r2 = r2_score(y_test, y_pred) | |
| fig, ax = plt.subplots() | |
| ax.scatter(y_test, y_pred, alpha=0.5) | |
| ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'r--') | |
| ax.set_xlabel("True value") | |
| ax.set_ylabel("Predicted") | |
| ax.set_title(f"Predictions vs. Truth (R² = {r2:.4f})") | |
| return fig | |
| with gr.Blocks(title="QSBench Demo Explorer") as demo: | |
| gr.Markdown(""" | |
| # QSBench Core Demo Explorer | |
| Interactive demo of the **QSBench Core Demo** dataset – 200 synthetic quantum circuits (6 qubits, depth 4). | |
| This space shows how to load the data, inspect it, and train a simple model on the ideal expectation values. | |
| 👉 **Full datasets (up to 200k samples, noisy versions, 10‑qubit transpilation packs) are available for purchase.** | |
| [Visit the QSBench website](https://qsbench.github.io/) | |
| """) | |
| with gr.Tabs(): | |
| with gr.TabItem("Data Explorer"): | |
| split_selector = gr.Dropdown(choices=["train", "validation", "test"], label="Choose a split", value="train") | |
| data_table = gr.Dataframe() | |
| split_selector.change(fn=show_data, inputs=split_selector, outputs=data_table) | |
| with gr.TabItem("Model Demo"): | |
| train_button = gr.Button("Train Random Forest") | |
| plot_output = gr.Plot() | |
| train_button.click(fn=train_and_plot, outputs=plot_output) | |
| gr.Markdown("---") | |
| gr.Markdown("### Get the full datasets\n- **QSBench Core** – 75k clean circuits (8 qubits)\n- **Depolarizing Noise Pack** – 150k circuits with depolarizing noise\n- **Amplitude Damping Pack** – 150k circuits with T1‑like relaxation\n- **Transpilation Hardware Pack** – 200k circuits (10 qubits) with hardware‑aware transpilation\n\n🔗 [Browse all datasets and purchase licenses](https://qsbench.github.io/)") | |
| demo.launch() |