Skip to content

Commit 49b80a7

Browse files
Formalise ABCs
1 parent c8f9dd3 commit 49b80a7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

causal_testing/surrogate/causal_surrogate_assisted.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Module containing classes to define and run causal surrogate assisted test cases"""
22

3-
from abc import ABC
3+
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
55
from typing import Callable, Any
66

@@ -11,7 +11,7 @@
1111

1212

1313
@dataclass
14-
class SimulationResult(ABC):
14+
class SimulationResult:
1515
"""Data class holding the data and result metadata of a simulation"""
1616

1717
data: dict
@@ -20,39 +20,44 @@ class SimulationResult(ABC):
2020

2121

2222
@dataclass
23-
class SearchFitnessFunction(ABC):
23+
class SearchFitnessFunction:
2424
"""Data class containing the Fitness function and related model"""
2525

2626
fitness_function: Any
2727
surrogate_model: CubicSplineRegressionEstimator
2828

2929

30-
class SearchAlgorithm:
30+
class SearchAlgorithm(ABC):
3131
"""Class to be inherited with the search algorithm consisting of a search function and the fitness function of the
3232
space to be searched"""
3333

34+
@abstractmethod
3435
def generate_fitness_functions(self, surrogate_models: list[Estimator]) -> list[SearchFitnessFunction]:
3536
"""Generates the fitness function of the search space
3637
:param surrogate_models: A list of CubicSplineRegressionEstimator generated for each edge of the DAG
3738
:return: A list of fitness functions mapping to each of the surrogate models in the input"""
3839

40+
@abstractmethod
3941
def search(self, fitness_functions: list[SearchFitnessFunction], specification: CausalSpecification) -> list:
4042
"""Function which implements a search routine which searches for the optimal fitness value for the specified
4143
scenario
4244
:param fitness_functions: The fitness function to be optimised
4345
:param specification: The Causal Specification (combination of Scenario and Causal Dag)"""
4446

4547

46-
class Simulator:
48+
class Simulator(ABC):
4749
"""Class to be inherited with Simulator specific functions to start, shutdown and run the simulation with the give
4850
config file"""
4951

52+
@abstractmethod
5053
def startup(self, **kwargs):
5154
"""Function that when run, initialises and opens the Simulator"""
5255

56+
@abstractmethod
5357
def shutdown(self, **kwargs):
5458
"""Function to safely exit and shutdown the Simulator"""
5559

60+
@abstractmethod
5661
def run_with_config(self, configuration: Any) -> SimulationResult:
5762
"""Run the simulator with the given configuration and return the results in the structure of a
5863
SimulationResult

0 commit comments

Comments
 (0)