1- import tabulate
2- from typing import Union
1+ import prettytable
32from pydantic import BaseModel , Field , field_validator
3+ from typing import Union
4+
45from RAT .utils .enums import ParallelOptions , Procedures , DisplayOptions , BoundHandlingOptions , StrategyOptions
56
67
7- class BaseProcedure (BaseModel , validate_assignment = True , extra = 'forbid' ):
8- """
9- Defines the base class with properties used in all five procedures.
10- """
8+ class BaseProcedure (BaseModel , validate_assignment = True , extra = 'forbid' ):
9+ """Defines the base class with properties used in all five procedures."""
1110 parallel : ParallelOptions = ParallelOptions .Single
1211 calcSldDuringFit : bool = False
13- resamPars : list [float ] = Field ([0.9 , 50 ], min_length = 2 , max_length = 2 )
12+ resamPars : list [float ] = Field ([0.9 , 50 ], min_length = 2 , max_length = 2 )
1413 display : DisplayOptions = DisplayOptions .Iter
1514
1615 @field_validator ("resamPars" )
16+ @classmethod
1717 def check_resamPars (cls , resamPars ):
1818 if not 0 < resamPars [0 ] < 1 :
1919 raise ValueError ('resamPars[0] must be between 0 and 1' )
@@ -22,63 +22,53 @@ def check_resamPars(cls, resamPars):
2222 return resamPars
2323
2424
25- class Calculate (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
26- """
27- Defines the class for the calculate procedure.
28- """
29- procedure : Procedures = Field (Procedures .Calculate , frozen = True )
25+ class Calculate (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
26+ """Defines the class for the calculate procedure."""
27+ procedure : Procedures = Field (Procedures .Calculate , frozen = True )
3028
3129
32- class Simplex (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
33- """
34- Defines the class for the simplex procedure.
35- """
36- procedure : Procedures = Field (Procedures .Simplex , frozen = True )
37- tolX : float = Field (1e-6 , gt = 0 )
38- tolFun : float = Field (1e-6 , gt = 0 )
39- maxFunEvals : int = Field (10000 , gt = 0 )
40- maxIter : int = Field (1000 , gt = 0 )
30+ class Simplex (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
31+ """Defines the class for the simplex procedure."""
32+ procedure : Procedures = Field (Procedures .Simplex , frozen = True )
33+ tolX : float = Field (1.0e-6 , gt = 0.0 )
34+ tolFun : float = Field (1.0e-6 , gt = 0.0 )
35+ maxFunEvals : int = Field (10000 , gt = 0 )
36+ maxIter : int = Field (1000 , gt = 0 )
4137 updateFreq : int = - 1
4238 updatePlotFreq : int = - 1
4339
4440
45- class DE (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
46- """
47- Defines the class for the Differential Evolution procedure.
48- """
49- procedure : Procedures = Field (Procedures .DE , frozen = True )
50- populationSize : int = Field (20 , ge = 1 )
41+ class DE (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
42+ """Defines the class for the Differential Evolution procedure."""
43+ procedure : Procedures = Field (Procedures .DE , frozen = True )
44+ populationSize : int = Field (20 , ge = 1 )
5145 fWeight : float = 0.5
52- crossoverProbability : float = Field (0.8 , gt = 0 , lt = 1 )
46+ crossoverProbability : float = Field (0.8 , gt = 0.0 , lt = 1.0 )
5347 strategy : StrategyOptions = StrategyOptions .RandomWithPerVectorDither
54- targetValue : float = Field (1.0 , ge = 1 )
55- numGenerations : int = Field (500 , ge = 1 )
56-
57-
58- class NS (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
59- """
60- Defines the class for the Nested Sampler procedure.
61- """
62- procedure : Procedures = Field (Procedures .NS , frozen = True )
63- Nlive : int = Field (150 , ge = 1 )
64- Nmcmc : float = Field (0.0 , ge = 0 )
65- propScale : float = Field (0.1 , gt = 0 , lt = 1 )
66- nsTolerance : float = Field (0.1 , ge = 0 )
67-
68-
69- class Dream (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
70- """
71- Defines the class for the Dream procedure
72- """
73- procedure : Procedures = Field (Procedures .Dream , frozen = True )
74- nSamples : int = Field (50000 , ge = 0 )
75- nChains : int = Field (10 , gt = 0 )
76- jumpProb : float = Field (0.5 , gt = 0 , lt = 1 )
77- pUnitGamma :float = Field (0.2 , gt = 0 , lt = 1 )
48+ targetValue : float = Field (1.0 , ge = 1.0 )
49+ numGenerations : int = Field (500 , ge = 1 )
50+
51+
52+ class NS (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
53+ """Defines the class for the Nested Sampler procedure."""
54+ procedure : Procedures = Field (Procedures .NS , frozen = True )
55+ Nlive : int = Field (150 , ge = 1 )
56+ Nmcmc : float = Field (0.0 , ge = 0.0 )
57+ propScale : float = Field (0.1 , gt = 0.0 , lt = 1.0 )
58+ nsTolerance : float = Field (0.1 , ge = 0.0 )
59+
60+
61+ class Dream (BaseProcedure , validate_assignment = True , extra = 'forbid' ):
62+ """Defines the class for the Dream procedure."""
63+ procedure : Procedures = Field (Procedures .Dream , frozen = True )
64+ nSamples : int = Field (50000 , ge = 0 )
65+ nChains : int = Field (10 , gt = 0 )
66+ jumpProb : float = Field (0.5 , gt = 0.0 , lt = 1.0 )
67+ pUnitGamma : float = Field (0.2 , gt = 0.0 , lt = 1.0 )
7868 boundHandling : BoundHandlingOptions = BoundHandlingOptions .Fold
7969
8070
81- class ControlsClass :
71+ class Controls :
8272
8373 def __init__ (self ,
8474 procedure : Procedures = Procedures .Calculate ,
@@ -104,7 +94,7 @@ def controls(self, value: Union[Calculate, Simplex, DE, NS, Dream]) -> None:
10494 self ._controls = value
10595
10696 def __repr__ (self ) -> str :
107- properties = [[ "Property" , "Value" ]] + \
108- [[ k , v ] for k , v in self . _controls . __dict__ . items ()]
109- table = tabulate . tabulate ( properties , headers = "firstrow" )
110- return table
97+ table = prettytable . PrettyTable ()
98+ table . field_names = [ 'Property' , 'Value' ]
99+ table . add_rows ([[ k , v ] for k , v in self . _controls . __dict__ . items ()] )
100+ return table . get_string ()
0 commit comments