From 348144e316f2eafc58d667c27abdec7287217725 Mon Sep 17 00:00:00 2001 From: satos Date: Thu, 5 Sep 2024 19:07:47 +0900 Subject: [PATCH] apply ruff check --fix --- misc/MV_python_integrator.py | 7 +++---- misc/dfa_lean.py | 1 - misc/learn_then_model_check.py | 4 ---- misc/mdp_model_check.py | 1 - src/ProbBlackBoxChecking.py | 9 ++------- src/StrategyBridge.py | 3 +-- src/prism_export_to_dot_model.py | 2 +- src/tests/Smc_test.py | 12 ++++++------ src/tests/StrategyBridge_test.py | 16 ++++++++-------- stat/scripts/plot_graph.py | 4 ---- 10 files changed, 21 insertions(+), 38 deletions(-) diff --git a/misc/MV_python_integrator.py b/misc/MV_python_integrator.py index 3227329..98a5db7 100644 --- a/misc/MV_python_integrator.py +++ b/misc/MV_python_integrator.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- from abc import ABC -import sys, random +import sys import socket import pickle import copy from py4j.java_gateway import JavaGateway, GatewayParameters, CallbackServerParameters -from aalpy.base import Automaton, AutomatonState from aalpy.SULs import MdpSUL from aalpy.utils import load_automaton_from_file from StrategyBridge import StrategyBridge @@ -24,8 +23,8 @@ def __init__(self): ) self.sul = MdpSUL(mdp) # == デバッグ用 == - self.prism_model_path = f"/Users/bo40/workspace/python/mc_exp.prism" - self.prism_adv_path = f"/Users/bo40/workspace/python/adv.tra" + self.prism_model_path = "/Users/bo40/workspace/python/mc_exp.prism" + self.prism_adv_path = "/Users/bo40/workspace/python/adv.tra" # ==== self.strategy_bridge = StrategyBridge( self.prism_adv_path, self.prism_model_path diff --git a/misc/dfa_lean.py b/misc/dfa_lean.py index e10965a..93c6040 100644 --- a/misc/dfa_lean.py +++ b/misc/dfa_lean.py @@ -1,5 +1,4 @@ from aalpy.utils import ( - load_automaton_from_file, save_automaton_to_file, visualize_automaton, generate_random_dfa, diff --git a/misc/learn_then_model_check.py b/misc/learn_then_model_check.py index 7d4ecf2..ef72655 100644 --- a/misc/learn_then_model_check.py +++ b/misc/learn_then_model_check.py @@ -4,11 +4,7 @@ from aalpy.oracles import RandomWalkEqOracle, RandomWordEqOracle from aalpy.learning_algs import run_stochastic_Lstar from aalpy.utils import ( - visualize_automaton, load_automaton_from_file, - model_check_experiment, - get_properties_file, - get_correct_prop_values, mdp_2_prism_format, ) from aalpy.automata.StochasticMealyMachine import smm_to_mdp_conversion diff --git a/misc/mdp_model_check.py b/misc/mdp_model_check.py index 1280189..d4617c0 100644 --- a/misc/mdp_model_check.py +++ b/misc/mdp_model_check.py @@ -4,7 +4,6 @@ from aalpy.oracles import RandomWalkEqOracle, RandomWordEqOracle from aalpy.learning_algs import run_stochastic_Lstar from aalpy.utils import ( - visualize_automaton, load_automaton_from_file, model_check_experiment, get_properties_file, diff --git a/src/ProbBlackBoxChecking.py b/src/ProbBlackBoxChecking.py index fe8b293..d2e3eee 100644 --- a/src/ProbBlackBoxChecking.py +++ b/src/ProbBlackBoxChecking.py @@ -3,22 +3,17 @@ import collections import os import shutil -from sys import prefix -from typing import List import aalpy.paths -from aalpy.base import Oracle, SUL +from aalpy.base import SUL from aalpy.automata import StochasticMealyMachine from aalpy.SULs import MdpSUL -from aalpy.oracles import RandomWalkEqOracle, RandomWordEqOracle +from aalpy.oracles import RandomWalkEqOracle from aalpy.learning_algs import run_stochastic_Lstar from aalpy.utils import ( load_automaton_from_file, mdp_2_prism_format, - get_properties_file, - get_correct_prop_values, ) from aalpy.automata.StochasticMealyMachine import smm_to_mdp_conversion -from aalpy.utils.HelperFunctions import print_observation_table from Smc import StatisticalModelChecker from StrategyBridge import StrategyBridge diff --git a/src/StrategyBridge.py b/src/StrategyBridge.py index cc67936..cb262e9 100644 --- a/src/StrategyBridge.py +++ b/src/StrategyBridge.py @@ -1,7 +1,6 @@ import re import random -import numpy as np -from typing import Dict, Tuple, Set, List +from typing import Dict, Tuple, List # Stateは多分本当はint State = int diff --git a/src/prism_export_to_dot_model.py b/src/prism_export_to_dot_model.py index db2d64b..eb8c6d5 100644 --- a/src/prism_export_to_dot_model.py +++ b/src/prism_export_to_dot_model.py @@ -49,7 +49,7 @@ def main(): name = name_of_labels[idx] if name == "init": initial_state = m[1] - if not name in except_names: + if name not in except_names: label_names.append(name) labels[m[1]] = "__".join(label_names) diff --git a/src/tests/Smc_test.py b/src/tests/Smc_test.py index e1b43da..a67445b 100644 --- a/src/tests/Smc_test.py +++ b/src/tests/Smc_test.py @@ -51,11 +51,11 @@ def test_initialize(self): automaton_type="mdp", ) sul = MdpSUL(mdp) - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) - spec_path = f"/Users/bo40/workspace/python/sandbox/shared_coin.ltl" + spec_path = "/Users/bo40/workspace/python/sandbox/shared_coin.ltl" smc = StatisticalModelChecker(sul, sb, spec_path) custom_print(smc.spec_monitor) @@ -77,11 +77,11 @@ def test_smc_run(self): automaton_type="mdp", ) sul = MdpSUL(mdp) - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) - spec_path = f"/Users/bo40/workspace/python/sandbox/shared_coin.ltl" + spec_path = "/Users/bo40/workspace/python/sandbox/shared_coin.ltl" smc = StatisticalModelChecker(sul, sb, spec_path, num_exec=5000) smc.run() diff --git a/src/tests/StrategyBridge_test.py b/src/tests/StrategyBridge_test.py index 97e874f..0c84094 100644 --- a/src/tests/StrategyBridge_test.py +++ b/src/tests/StrategyBridge_test.py @@ -4,8 +4,8 @@ class StrategyBridgeTestCase(unittest.TestCase): def test_initialize(self): - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) self.assertEqual(sb.initial_state, 0) @@ -25,8 +25,8 @@ def test_initialize(self): ) def test_next(self): - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) self.assertEqual(sb.next_action(), "go2") @@ -38,8 +38,8 @@ def test_next(self): # self.assertEqual(sb.history, [("go2", 'agree__c1_tails__c2_tails__six'), ("go2", 'agree__c1_tails__c2_tails__five')]) def test_reset(self): - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) sb.update_state("go2", "agree__c1_tails__c2_tails__six") @@ -52,8 +52,8 @@ def test_reset(self): # self.assertEqual(sb.history, []) def test_update_state_false(self): - sample_prism_model = f"/Users/bo40/workspace/python/mc_exp_sample.prism" - sample_prism_adv = f"/Users/bo40/workspace/python/adv_sample.tra" + sample_prism_model = "/Users/bo40/workspace/python/mc_exp_sample.prism" + sample_prism_adv = "/Users/bo40/workspace/python/adv_sample.tra" sb = StrategyBridge(sample_prism_adv, sample_prism_model) # TODO : implement this test diff --git a/stat/scripts/plot_graph.py b/stat/scripts/plot_graph.py index 4629af5..cb95fd3 100644 --- a/stat/scripts/plot_graph.py +++ b/stat/scripts/plot_graph.py @@ -1,13 +1,9 @@ import sys import os -import math import numpy as np -import matplotlib from matplotlib import pyplot as plt # Gaussian process regression -from sklearn.gaussian_process import GaussianProcessRegressor -from sklearn.gaussian_process.kernels import WhiteKernel, RBF stat_file = sys.argv[1] baseline_file = sys.argv[2]