Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e46f778
Add Error Budget Optimization
tobi-forster Apr 13, 2025
3a7e7f8
add data and models
tobi-forster Apr 15, 2025
861b245
Merge remote-tracking branch 'origin/main' into Error_Budget_Optimiza…
tobi-forster May 8, 2025
4b5b285
Added README.md
tobi-forster May 8, 2025
296709f
fixing file path
tobi-forster Jul 1, 2025
f6fc47c
Merge remote-tracking branch 'origin/main' into Error_Budget_Optimiza…
tobi-forster Jul 18, 2025
9164121
Improved structure
tobi-forster Jul 23, 2025
80081b1
Adding the error budget optimization approach to the README.
tobi-forster Jul 24, 2025
2accbd0
Improve code structure.
tobi-forster Jul 24, 2025
4582674
ZIP MQTBench Folder for improved structure.
tobi-forster Jul 24, 2025
f689c1a
Added comment on dependencies
tobi-forster Jul 24, 2025
9d0f87a
Added comment on dependencies
tobi-forster Jul 24, 2025
d730e47
🎨 pre-commit fixes
pre-commit-ci[bot] Jul 24, 2025
79a711c
Improve code structure.
tobi-forster Jul 24, 2025
be19809
excluded some capitalization checks.
tobi-forster Jul 24, 2025
fcdfd7a
Removing additional README.
tobi-forster Jul 24, 2025
1514fe7
removed unused variables
tobi-forster Jul 25, 2025
0932c46
Update resource_estimation/Error_Budget_Optimization/generate_data.py
tobi-forster Aug 2, 2025
03a683c
Update resource_estimation/Error_Budget_Optimization/generate_data.py
tobi-forster Aug 2, 2025
e484d92
Improve code structure
tobi-forster Aug 2, 2025
2ab9ebd
Corrected type annotations and improved code structure.
tobi-forster Aug 5, 2025
ee0710e
Add function to generate benchmarks.
tobi-forster Aug 6, 2025
5572866
Improved code structure and adjusted pre-commit settings.
tobi-forster Aug 11, 2025
918b6da
🚚 proper naming for folder
burgholzer Aug 11, 2025
6034fe3
🩹 fix mypy linter configuration in pre-commit
burgholzer Aug 11, 2025
9ab0d02
♻️ adjust for MQT Bench v2
burgholzer Aug 11, 2025
15f61d3
🎨 use list comprehension for benchmark generation
burgholzer Aug 11, 2025
5df4233
🎨 improve code quality in data generation
burgholzer Aug 11, 2025
563dd39
🔧 simplify ruff configuration
burgholzer Aug 11, 2025
e9d72be
🎨 improve code quality for evaluation code
burgholzer Aug 11, 2025
087b1ff
🔒 update lockfile
burgholzer Aug 11, 2025
133e33b
♻️ stream files and circuits instead of loading everything in memory
burgholzer Aug 11, 2025
322de25
Support newer versions of qsharp qiskit and mqt.bench and adding the …
tobi-forster Aug 12, 2025
738b9d5
Potential fix for code scanning alert no. 2: Potentially uninitialize…
tobi-forster Aug 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ repos:
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest|Mqt|Tum
exclude: .pre-commit-config.yaml
exclude: .pre-commit-config.yaml|\.zip$|\.pkl$

# Check best practices for scientific Python code
- repo: https://github.com/scientific-python/cookie
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<p align="center">
<a href="https://mqt.readthedocs.io">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/cda-tum/mqt/main/docs/_static/mqt_light.png" width="60%">
<img src="https://raw.githubusercontent.com/cda-tum/mqt/main/docs/_static/mqt_dark.png" width="60%">
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/munich-quantum-toolkit/.github/refs/heads/main/docs/_static/logo-mqt-dark.svg" width="60%">
<img src="https://raw.githubusercontent.com/munich-quantum-toolkit/.github/refs/heads/main/docs/_static/logo-mqt-light.svg" width="60%" alt="MQT Logo">
</picture>
</a>
</p>
Expand Down Expand Up @@ -133,6 +133,16 @@ In the `equivalence_checking` module, our approach to this problem by utilizing

These two implementations are provided by the functions `try_parameter_combinations()` and `find_counter_examples()`, respectively. Examples for their usages are shown in `notebooks/equivalence_checking/example.ipynb`.

# Improving Hardware Requirements for Fault-Tolerant Quantum Computing by Optimizing Error Budget Distributions

Applying error correction to execute quantum circuits fault-tolerantly induces massive overheads in the required physical resources, often in the orders of magnitude. This leads to thousands of qubits already for toy-sized quantum applications. Obviously, these need to be reduced, for which the so-called error budget can be a particular lever. Even though error correction is applied, a certain error rate still remains in the execution of the quantum circuit. Hence, the end user defines a maximum tolerated error rate, the error budget, for the quantum application to be considered by the compiler. Since an error-corrected quantum circuit consists of different parts, this error budget is distributed among these parts. The way how it is distributed can have a significant effect on the resulting required resources. To find an efficient distribution, we use resource estimation to evaluate different distributions as well as a machine learning model approach that automatically determines such efficient distributions for a given quantum circuit.

<p align="center">
<img src="img/error_budget_approach.png" height=150px>
</p>

The implementation of the approach can be found under `resource_estimation/Error_Budget_Optimization`. An example usage of the implementation is shown in the `example_use.ipynb` notebook.

# Usage

MQT ProblemSolver is available via [PyPI](https://pypi.org/project/mqt.problemsolver/):
Expand Down
Binary file added img/error_budget_approach.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
116 changes: 116 additions & 0 deletions resource_estimation/Error_Budget_Optimization/evaluate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np
from qsharp.estimator import ErrorBudgetPartition, EstimatorParams, LogicalCounts


def evaluate(X, Y, total_budget):
"""
Evaluates the impact of different error budget partitions on quantum resource estimates.
Args:
X: A 2D array where each row contains quantum circuit logical counts (e.g., numQubits, tCount, rotationCount, etc.).
Y: A 2D array where each row contains error budgetds for logical, t_states, and rotations.
total_budget: The total error budget to be distributed among logical, t_states, and rotations.
Returns:
qubits_diffs: List of relative differences in physical qubits compared to the default budget distribution.
runtime_diffs: List of relative differences in runtime compared to the default budget distribution.
product_diffs: List of relative differences in the product of qubits and runtime compared to the default budget distribution.
qubits_list: List of estimated physical qubits for each parameter set.
runtime_list: List of estimated runtimes for each parameter set.
default_qubits_list: List of physical qubits using the default budget for each parameter set.
default_runtime_list: List of runtimes using the default budget for each parameter set.
"""

product_diffs = []
for i, params in enumerate(Y):
c = {}
c["numQubits"] = int(X[i, 0])
c["tCount"] = int(X[i, 1])
c["rotationCount"] = int(X[i, 2])
c["rotationDepth"] = int(X[i, 3])
c["cczCount"] = int(X[i, 4])
c["ccixCount"] = int(X[i, 5])
c["measurementCount"] = int(X[i, 6])
logical_counts = LogicalCounts(c)
params_sum = params[0] + params[1] + params[2]
params_normalized = [
params[0] / params_sum * total_budget,
params[1] / params_sum * total_budget,
params[2] / params_sum * total_budget,
]

parameters = EstimatorParams()
parameters.error_budget = ErrorBudgetPartition()
parameters.error_budget.logical = params_normalized[0]
parameters.error_budget.t_states = params_normalized[1]
parameters.error_budget.rotations = params_normalized[2]

default_parameters = EstimatorParams()
default_parameters.error_budget = total_budget

result = logical_counts.estimate(parameters)
default_result = logical_counts.estimate(default_parameters)
qubits = result["physicalCounts"]["physicalQubits"]
runtime = result["physicalCounts"]["runtime"]
default_qubits = default_result["physicalCounts"]["physicalQubits"]
default_runtime = default_result["physicalCounts"]["runtime"]

product_diff = ((qubits * runtime) - (default_qubits * default_runtime)) / (default_qubits * default_runtime)
if product_diff > 0:
product_diff = 0

product_diffs.append(product_diff)

return product_diffs


def plot_results(product_diffs, product_diffs_optimal, legend=False, bin_width=4):
"""
Plots histograms comparing predicted and optimal space-time differences.
This function visualizes the distribution of space-time differences (in percent)
for predicted and optimal product distributions. It overlays two histograms for
comparison and customizes axis ticks, labels, and legend.
Args:
product_diffs: List of space-time differences for predicted distributions.
product_diffs_optimal: List of space-time differences for best found distributions.
legend: Whether to display the legend on the plot. Defaults to False.
bin_width: Width of histogram bins. Defaults to 4.
Returns:
None. Displays the plot.
"""

product_diffs = [100 * i for i in product_diffs]
product_diffs_optimal = [100 * i for i in product_diffs_optimal]

all_data = product_diffs + product_diffs_optimal
data_min = min(all_data)
data_max = max(all_data)

data_min = min(0, data_min)
data_max += bin_width

bin_edges = np.arange(data_min, data_max + bin_width, bin_width)

np.arange(-100, 1, 20)
_fig, ax = plt.subplots(figsize=(5, 2.5))
ax.hist(
product_diffs_optimal,
bins=bin_edges,
color="steelblue",
edgecolor="black",
alpha=0.5,
label="Best Distributions Determined",
)
ax.hist(
product_diffs, bins=bin_edges, color="orange", edgecolor="black", alpha=0.5, label="Predicted Distributions"
)
ax.set_xlim(data_min, data_max)
ax.set_xticks([-100, -80, -60, -40, -20, 0])
ax.set_yticks([0, 40, 80, 120])
ax.set_xlabel("Space-Time Difference [%]", fontsize=15)
ax.tick_params(axis="both", which="major", labelsize=15)
if legend:
ax.legend(loc="upper left", fontsize=12)
plt.tight_layout()
plt.show()
108 changes: 108 additions & 0 deletions resource_estimation/Error_Budget_Optimization/example_use.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "bb93cfcc",
"metadata": {},
"outputs": [],
"source": [
"### Currently, please use the following versions for the approach:\n",
"### - qiskit==1.2.0\n",
"### - qsharp==1.9.0\n",
"\n",
"\n",
"import zipfile\n",
"\n",
"from evaluate import evaluate, plot_results\n",
"from generate_data import generate_data\n",
"from training import train"
]
},
{
"cell_type": "markdown",
"id": "f3e4a6d5",
"metadata": {},
"source": [
"## Data Generation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2116443e",
"metadata": {},
"outputs": [],
"source": [
"total_error_budget = 0.1\n",
"number_of_randomly_generated_distributions = 1000\n",
"path = \"MQTBench\"\n",
"\n",
"with zipfile.ZipFile(f\"{path}.zip\", \"r\") as zip_ref:\n",
" zip_ref.extractall(path)\n",
"\n",
"data = generate_data(total_error_budget, number_of_randomly_generated_distributions, path)"
]
},
{
"cell_type": "markdown",
"id": "7af169cb",
"metadata": {},
"source": [
"## Training"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "675f4541",
"metadata": {},
"outputs": [],
"source": [
"model, X_test, Y_test = train(data)"
]
},
{
"cell_type": "markdown",
"id": "6d4021ca",
"metadata": {},
"source": [
"## Evaluation"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18ac8807",
"metadata": {},
"outputs": [],
"source": [
"Y_pred = model.predict(X_test)\n",
"product_diffs = evaluate(X_test, Y_pred, total_error_budget)\n",
"product_diffs_dataset = evaluate(X_test, Y_test, total_error_budget)\n",
"\n",
"plot_results(product_diffs, product_diffs_dataset, legend=True, bin_width=4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading