Skip to content

Commit

Permalink
WIP Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhoanglnh committed Jan 22, 2025
1 parent a84bd92 commit 0e81ec3
Show file tree
Hide file tree
Showing 80 changed files with 145 additions and 109 deletions.
26 changes: 22 additions & 4 deletions solidago/src/solidago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@

from .__version__ import __version__

import solidago.primitives as primitives
from solidago._state import *
from solidago._generative_model import *
from solidago._pipeline import *
from solidago.primitives import *
from solidago.state import *
from solidago.modules import *
from solidago.generators import *

__all__ = [
"User", "Users", "VectorUser", "VectorUsers",
"Vouches",
"Entity", "Entities", "VectorEntity", "VectorEntities",
"MadePublic", "AllPublic",
"Assessment", "Assessments",
"Comparison", "Comparisons",
"VotingRights",
"Score", "MultiScore",
"ScoringModel", "BaseModel",
"UserModels",
"DirectScoring",
"ScaleDict", "ScaledModel",
"PostProcessedModel", "SquashedModel",
"State", "TournesolExport",
"primitives", "modules", "generators",
]
8 changes: 0 additions & 8 deletions solidago/src/solidago/_generative_model/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions solidago/src/solidago/_pipeline/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions solidago/src/solidago/_state/__init__.py

This file was deleted.

8 changes: 8 additions & 0 deletions solidago/src/solidago/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .base import Generator

import solidago.generators.user
import solidago.generators.vouch
import solidago.generators.entity
import solidago.generators.engagement
import solidago.generators.assessment
import solidago.generators.comparison
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class AssessmentGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numpy import sqrt
from numpy.random import normal

from solidago._state import *
from solidago.state import *
from .base import AssessmentGenerator


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import logging
import json

from solidago._state import *
from solidago._pipeline import Sequential
from solidago.state import *
from solidago.modules import Sequential

from ._user import UserGenerator
from ._vouch import VouchGenerator
from ._entity import EntityGenerator
from ._engagement import EngagementGenerator
from ._assessment import AssessmentGenerator
from ._comparison import ComparisonGenerator
from .user import UserGenerator
from .vouch import VouchGenerator
from .entity import EntityGenerator
from .engagement import EngagementGenerator
from .assessment import AssessmentGenerator
from .comparison import ComparisonGenerator

logger = logging.getLogger(__name__)


class GenerativeModel(Sequential):
class Generator(Sequential):
def __init__(self,
user_gen: UserGenerator = UserGenerator(),
entity_gen: EntityGenerator = EntityGenerator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class ComparisonGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import numpy as np

from solidago._state import *
from solidago.state import *
from .base import ComparisonGenerator


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numpy.random import random

from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class EngagementGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pandas as pd
import numpy as np

from solidago._state import *
from solidago.state import *
from .base import EngagementGenerator


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd

from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class EntityGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

from typing import Optional, Callable
from solidago._state import VectorEntity, VectorEntities
from solidago.state import VectorEntity, VectorEntities
from .base import EntityGenerator


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pandas as pd

from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class UserGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from solidago._state import *
from solidago.state import *
from .base import UserGenerator


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from solidago._state import *
from solidago._pipeline import StateFunction
from solidago.state import *
from solidago.modules import StateFunction


class VouchGenerator(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from numpy.random import random

from solidago._state import Users, Vouches
from solidago.state import Users, Vouches
from .base import VouchGenerator


Expand Down
11 changes: 11 additions & 0 deletions solidago/src/solidago/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .base import StateFunction
from .sequential import Sequential
from .identity import Identity

from .trust_propagation import *
from .preference_learning import *
from .voting_rights import *
from .scaling import *
from .aggregation import *
from .post_process import *

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd

from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class Average(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import numpy as np

from solidago.primitives.lipschitz import qr_quantile, qr_uncertainty
from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class EntitywiseQrQuantile(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union, Optional, Any
from pathlib import Path

from solidago._state import *
from solidago.state import *


class StateFunction:
Expand Down Expand Up @@ -88,12 +88,12 @@ def load(cls, filename: Optional[Union[str, Path, list, dict]]=None) -> "StateFu
args = json.load(f)
else:
args = filename
import solidago._pipeline as pipeline
import solidago.modules as modules
if isinstance(args, list):
return cls(*[ getattr(pipeline, m[0])(m[1]) for m in args ])
return cls(*[ getattr(modules, m[0])(m[1]) for m in args ])
else:
assert isinstance(args, dict)
return cls(**{ key: getattr(pipeline, m[0])(m[1]) for key, m in args.items() })
return cls(**{ key: getattr(modules, m[0])(m[1]) for key, m in args.items() })

def save(self, filename: Optional[Union[str, Path]]=None) -> tuple[str, Optional[Union[dict, list]]]:
j = type(self).__name__, self.args_save()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Union, Optional
from pathlib import Path

from solidago._state import *
from solidago.state import *
from .base import StateFunction


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import numpy as np
import pandas as pd

from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class Squash(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

logger = logging.getLogger("preference_learning")

from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class PreferenceLearning(StateFunction, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import solidago.primitives.dichotomy as dichotomy

from solidago._state import *
from solidago.state import *
from .base import PreferenceLearning


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Install 'solidago[torch]' to get the optional dependencies."
) from exc

from solidago._state import *
from solidago.state import *
from solidago.primitives import dichotomy
from .generalized_bradley_terry import GeneralizedBradleyTerry, UniformGBT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy.typing as npt
from numba import njit

from solidago._state import *
from solidago.state import *
from solidago.primitives.optimize import coordinate_descent, njit_brentq
from .generalized_bradley_terry import GeneralizedBradleyTerry, UniformGBT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np

from solidago.primitives import qr_quantile
from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class LipschitzQuantileShift(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pandas as pd

from solidago.primitives import qr_standard_deviation
from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class LipschitzStandardize(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from solidago.primitives.lipschitz import qr_median, qr_uncertainty, lipschitz_resilient_mean
from solidago.primitives.pairs import UnorderedPairs
from solidago.primitives.datastructure import NestedDictOfItems, NestedDictOfRowLists
from solidago._state import *
from solidago._pipeline.base import StateFunction
from solidago.state import *
from solidago.modules.base import StateFunction


class Mehestan(StateFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

logger = logging.getLogger(__name__)

from solidago._state import State
from solidago.state import *
from .base import StateFunction


Expand All @@ -20,8 +20,8 @@ def __init__(self, name: Optional[str]=None, **kwargs):
if isinstance(value, StateFunction):
setattr(self, key, value)
elif isinstance(value, (list, tuple)) and len(value) == 2:
import solidago._pipeline as pipeline
setattr(self, key, getattr(pipeline, value[0])(**value[1]))
import solidago.modules as modules
setattr(self, key, getattr(modules, value[0])(**value[1]))
else:
print(f"Sequential.__init__: Got unhandled input key={key}, type(value)={type(value).__name__}")

Expand Down Expand Up @@ -55,9 +55,9 @@ def load(cls, d: Union[dict, str]) -> "Sequential":
if isinstance(d, str):
with open(d) as f:
d = json.load(f)
import solidago._pipeline as pipeline
import solidago.modules as modules
return cls(**{
key: getattr(pipeline, value[0])(**value[1])
key: getattr(modules, value[0])(**value[1])
for key, value in d.items() if key not in Sequential.__init__.__annotations__
}, **{ key: value
for key, value in d.items() if key in Sequential.__init__.__annotations__
Expand Down
Loading

0 comments on commit 0e81ec3

Please sign in to comment.