Skip to content

Commit

Permalink
🚨 fixed ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nquetschlich committed Jan 2, 2025
1 parent 2decd88 commit 874dd58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 6 additions & 4 deletions tests/compilation/test_predictor_rl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import re
from pathlib import Path

import pytest
Expand All @@ -23,7 +24,7 @@ def test_predictor_env_reset_from_string() -> None:

def test_predictor_env_esp_error() -> None:
"""Test the predictor environment with ESP as figure of merit and missing calibration data."""
with pytest.raises(ValueError, match="Missing calibration data for ESP calculation on ibm_montreal."):
with pytest.raises(ValueError, match=re.escape("Missing calibration data for ESP calculation on ibm_montreal.")):
rl.Predictor(figure_of_merit="estimated_success_probability", device_name="ibm_montreal")


Expand All @@ -42,7 +43,8 @@ def test_qcompile_with_newly_trained_models() -> None:
model_path = Path(rl.helper.get_path_trained_model() / (model_name + ".zip"))
if not model_path.exists():
with pytest.raises(
FileNotFoundError, match="The RL model is not trained yet. Please train the model before using it."
FileNotFoundError,
match=re.escape("The RL model is not trained yet. Please train the model before using it."),
):
rl.qcompile(qc, figure_of_merit=figure_of_merit, device_name=device)

Expand All @@ -61,7 +63,7 @@ def test_qcompile_with_newly_trained_models() -> None:
def test_qcompile_with_false_input() -> None:
"""Test the qcompile function with false input."""
qc = get_benchmark("dj", 1, 5)
with pytest.raises(ValueError, match="figure_of_merit must not be None if predictor_singleton is None."):
with pytest.raises(ValueError, match=re.escape("figure_of_merit must not be None if predictor_singleton is None.")):
rl.helper.qcompile(qc, None, "quantinuum_h2")
with pytest.raises(ValueError, match="device_name must not be None if predictor_singleton is None."):
with pytest.raises(ValueError, match=re.escape("device_name must not be None if predictor_singleton is None.")):
rl.helper.qcompile(qc, "expected_fidelity", None)
6 changes: 5 additions & 1 deletion tests/device_selection/test_helper_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest

from mqt.bench import benchmark_generator
Expand All @@ -10,7 +12,9 @@

def test_load_and_save_training_data() -> None:
"""Test the loading and saving of the training data."""
with pytest.raises(FileNotFoundError, match="Training data not found. Please run the training script first."):
with pytest.raises(
FileNotFoundError, match=re.escape("Training data not found. Please run the training script first.")
):
ml.helper.load_training_data("false_input") # type: ignore[arg-type]

training_data, names_list, scores_list = ml.helper.load_training_data()
Expand Down
5 changes: 3 additions & 2 deletions tests/device_selection/test_predictor_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import re
import sys
from pathlib import Path
from typing import Literal
Expand Down Expand Up @@ -39,7 +40,7 @@ def test_train_and_predictor_random_forest_classifier() -> None:
assert 0 <= elem <= 1

with pytest.raises(
FileNotFoundError, match="The ML model is not trained yet. Please train the model before using it."
FileNotFoundError, match=re.escape("The ML model is not trained yet. Please train the model before using it.")
):
ml.helper.predict_device_for_figure_of_merit(qc, "false_input") # type: ignore[arg-type]

Expand Down Expand Up @@ -99,7 +100,7 @@ def test_compile_all_circuits_for_dev_and_fom() -> None:
dump(qc, f)

if sys.platform == "win32":
with pytest.warns(RuntimeWarning, match="Timeout is not supported on Windows."):
with pytest.warns(RuntimeWarning, match=re.escape("Timeout is not supported on Windows.")):
predictor.compile_all_circuits_devicewise(
device_name="ionq_harmony",
timeout=100,
Expand Down

0 comments on commit 874dd58

Please sign in to comment.