scml.oneshot.context ==================== .. py:module:: scml.oneshot.context Classes ------- .. autoapisummary:: scml.oneshot.context.ContextParams scml.oneshot.context.Context scml.oneshot.context.GeneralContext scml.oneshot.context.LimitedPartnerNumbersContext scml.oneshot.context.FixedPartnerNumbersContext scml.oneshot.context.MonopolicContext scml.oneshot.context.SingleAgentPerLevelSupplierContext scml.oneshot.context.EutopiaContext scml.oneshot.context.EutopiaSupplierContext scml.oneshot.context.EutopiaConsumerContext scml.oneshot.context.FixedPartnerNumbersOneShotContext scml.oneshot.context.ANACContext scml.oneshot.context.LimitedPartnerNumbersOneShotContext scml.oneshot.context.ANACOneShotContext scml.oneshot.context.SupplierContext scml.oneshot.context.StrongSupplierContext scml.oneshot.context.BalancedSupplierContext scml.oneshot.context.WeakSupplierContext scml.oneshot.context.ConsumerContext scml.oneshot.context.StrongConsumerContext scml.oneshot.context.BalancedConsumerContext scml.oneshot.context.WeakConsumerContext scml.oneshot.context.RepeatingContext Module Contents --------------- .. py:class:: ContextParams Basic Parameters you can assume about a context. Returned by `extract_context_params` .. py:attribute:: perishable :type: bool .. py:attribute:: nlines :type: int .. py:attribute:: nsuppliers :type: int .. py:attribute:: nconsumers :type: int .. py:class:: Context Bases: :py:obj:`abc.ABC` A context used for generating worlds satisfying predefined conditions and testing for them .. py:method:: __call__(*args, **kwargs) .. py:method:: generate(types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None, params: tuple[dict[str, Any], Ellipsis] | None = None, name: str | None = None) -> tuple[scml.oneshot.world.SCMLBaseWorld, tuple[scml.oneshot.agent.OneShotAgent]] :abstractmethod: Generates a world with one or more agents to be controlled externally and returns both :param agent_types: The types of a list of agents to be guaranteed to exist in the world :param agent_params: The parameters to pass to the constructors of these agents. None means no parameters for any agents :param name: The name of the worlds to generate. Uses a random name if not given :returns: The constructed world and a tuple of the agents created corresponding (in order) to the given agent types/params .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld) -> bool :abstractmethod: Checks that the given world could have been generated from this context .. py:method:: is_valid_awi(awi: scml.oneshot.awi.OneShotAWI) -> bool :abstractmethod: Checks that the given AWI is connected to a world that could have been generated from this context .. py:method:: contains_context(context: Context) -> bool :abstractmethod: Checks that the any world generated from the given `context` could have been generated from this context .. py:method:: __contains__(other: Union[SCMLBaseWorld, OneShotAWI, Context]) -> bool .. py:class:: GeneralContext Bases: :py:obj:`BaseContext` A context that generates oneshot worlds with agents of a given `types` with predetermined structure and settings .. py:attribute:: perishable :type: bool :value: True .. py:attribute:: price_multiplier :type: numpy.ndarray | tuple[float, float] | float :value: (1.5, 2.0) .. py:attribute:: force_signing :value: True .. py:attribute:: n_steps :type: tuple[int, int] | int :value: (20, 200) .. py:attribute:: n_processes :type: tuple[int, int] | int :value: 2 .. py:attribute:: n_lines :type: tuple[int, int] | int :value: 10 .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:attribute:: production_costs :type: numpy.ndarray | tuple[int, int] | int :value: (1, 4) .. py:attribute:: cash_availability :type: tuple[float, float] | float :value: (1.5, 2.5) .. py:attribute:: shortfall_penalty :type: tuple[float, float] | float :value: (0.2, 1.0) .. py:attribute:: shortfall_penalty_dev :type: tuple[float, float] | float :value: (0.0, 0.1) .. py:attribute:: disposal_cost :type: tuple[float, float] | float :value: (0.0, 0.2) .. py:attribute:: disposal_cost_dev :type: tuple[float, float] | float :value: (0.0, 0.02) .. py:attribute:: storage_cost :type: tuple[float, float] | float :value: (0.0, 0.02) .. py:attribute:: storage_cost_dev :type: tuple[float, float] | float :value: 0 .. py:attribute:: cost_increases_with_level :value: True .. py:attribute:: penalties_scale :type: str | list[str] :value: 'trading' .. py:attribute:: process_inputs :type: tuple[int, int] | int :value: 1 .. py:attribute:: process_outputs :type: numpy.ndarray | tuple[int, int] | int :value: 1 .. py:attribute:: exogenous_generation_method :value: 'profitable' .. py:attribute:: profit_means :type: numpy.ndarray | tuple[float, float] | float :value: (0.1, 0.2) .. py:attribute:: profit_stddevs :type: numpy.ndarray | tuple[float, float] | float :value: 0.05 .. py:attribute:: max_productivity :type: numpy.ndarray | tuple[float, float] | float :value: (0.8, 1.0) .. py:attribute:: initial_balance :type: numpy.ndarray | tuple[int, int] | int | None :value: None .. py:attribute:: exogenous_supply_predictability :type: tuple[float, float] | float :value: (0.6, 0.9) .. py:attribute:: exogenous_sales_predictability :type: tuple[float, float] | float :value: (0.6, 0.9) .. py:attribute:: exogenous_control :type: tuple[float, float] | float :value: -1 .. py:attribute:: exogenous_price_dev :type: tuple[float, float] | float :value: (0.1, 0.2) .. py:attribute:: equal_exogenous_supply :value: False .. py:attribute:: equal_exogenous_sales :value: False .. py:attribute:: cap_exogenous_quantities :type: bool :value: True .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_predefined_config(agent_types: list[type[scml.oneshot.agent.OneShotAgent]], agent_processes: list[int], agent_params: list[dict[str, Any]], n_agents_per_process: list[int]) -> dict[str, Any] Generates a config for a world .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:method:: _assign_types(n_processes, types, params, levels, n_agents_per_process) .. py:method:: _distribute_agents(n_types) .. py:method:: make_config() -> dict[str, Any] Generates a config for a world .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, raise_on_failure: bool = False, warn_on_failure: bool = False, types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_general_context(context: GeneralContext) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:class:: LimitedPartnerNumbersContext Bases: :py:obj:`GeneralContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: tuple[int, int] :value: (4, 8) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_competitors :type: tuple[int, int] .. py:attribute:: buying_strength :type: Strength | None :value: None .. py:attribute:: selling_strength :type: Strength | None :value: None .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_config() -> dict[str, Any] Generates a config .. py:method:: find_test_agents(world: scml.oneshot.world.SCMLBaseWorld, types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> list[str] .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None, raise_on_failure: bool = False, warn_on_failure: bool = False) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_limited_partner_context(context: LimitedPartnerNumbersContext, raise_on_failure: bool = False, warn_on_failure: bool = False) -> bool .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context .. py:class:: FixedPartnerNumbersContext Bases: :py:obj:`LimitedPartnerNumbersContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: int :value: 4 .. py:attribute:: n_suppliers :type: int :value: 0 .. py:attribute:: n_competitors :type: int :value: 3 .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:class:: MonopolicContext Bases: :py:obj:`LimitedPartnerNumbersContext` An agent that has no competitors in the same level as themselves .. py:attribute:: n_competitors :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:method:: __attrs_post_init__() .. py:class:: SingleAgentPerLevelSupplierContext Bases: :py:obj:`MonopolicContext` A world in which every level has exactly one factory and the agent is a supplier .. py:attribute:: level :type: int :value: 0 .. py:attribute:: n_consumers :type: tuple[int, int] :value: (1, 1) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_agents_per_process :type: numpy.ndarray | list[int] | tuple[int, int] | int .. py:class:: EutopiaContext Bases: :py:obj:`MonopolicContext` An unrealistic context in which the agent is the only one in its level and all other agents are nice. .. py:attribute:: non_competitors :type: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] .. py:class:: EutopiaSupplierContext Bases: :py:obj:`EutopiaContext` An unrealistic context in which the agent is the only supplier and all consumers are nice. .. py:attribute:: level :type: int .. py:attribute:: n_consumers :type: tuple[int, int] :value: (4, 8) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (0, 0) .. py:class:: EutopiaConsumerContext Bases: :py:obj:`EutopiaContext` An unrealistic context in which the agent is the only consumer and all suppliers are nice. .. py:attribute:: level :type: int .. py:attribute:: n_consumers :type: tuple[int, int] :value: (0, 0) .. py:attribute:: n_suppliers :type: tuple[int, int] :value: (4, 8) .. py:class:: FixedPartnerNumbersOneShotContext Bases: :py:obj:`FixedPartnerNumbersContext` Generates a world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:class:: ANACContext Bases: :py:obj:`GeneralContext` Generates a oneshot world with no constraints except compatibility with a specific ANAC competition year. .. py:attribute:: year :type: int :value: 2024 .. py:method:: __attrs_post_init__() .. py:class:: LimitedPartnerNumbersOneShotContext Bases: :py:obj:`LimitedPartnerNumbersContext` Generates a oneshot world limiting the range of the agent level, production capacity and the number of suppliers, consumers, and optionally same-level competitors. .. py:attribute:: year :type: int :value: 2024 .. py:method:: __attrs_post_init__() .. py:class:: ANACOneShotContext Bases: :py:obj:`ANACContext` Generates a oneshot world with no constraints except compatibility with a specific ANAC competition year. .. py:method:: __attrs_post_init__() .. py:class:: SupplierContext(*args, **kwargs) Bases: :py:obj:`LimitedPartnerNumbersOneShotContext` A world context that can generate any world compatible with the observation manager .. py:class:: StrongSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with almost many consumers relative to competitors .. py:class:: BalancedSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with almost same number of consumers as competitors .. py:class:: WeakSupplierContext(*args, **kwargs) Bases: :py:obj:`SupplierContext` A supplier with few consumers relative to competitors .. py:class:: ConsumerContext(*args, **kwargs) Bases: :py:obj:`LimitedPartnerNumbersOneShotContext` A world context that can generate any world compatible with the observation manager .. py:class:: StrongConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with almost many suppliers relative to competitors .. py:class:: BalancedConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with almost same number of suppliers as competitors .. py:class:: WeakConsumerContext(*args, **kwargs) Bases: :py:obj:`ConsumerContext` A consumer with few suppliers relative to competitors .. py:class:: RepeatingContext Bases: :py:obj:`BaseContext` Encapsulates one or more configs and switches between them when asked to generate or make something. .. py:attribute:: configs :type: tuple[dict[str, Any], Ellipsis] .. py:attribute:: randomize :type: bool :value: True .. py:attribute:: rename :type: bool :value: True .. py:attribute:: _next :type: int .. py:method:: __attrs_post_init__() .. py:method:: extract_context_params(min_values: bool, level: int | None = None) -> ContextParams .. py:method:: make_config(types: tuple[type[scml.oneshot.agent.OneShotAgent], Ellipsis] = DEFAULT_PLACEHOLDER_AGENT_TYPES, params: tuple[dict[str, Any], Ellipsis] | None = None) -> dict[str, Any] Generates a config for a world .. py:method:: from_context(context: BaseContext, n: int = 1, types: tuple[type[scml.oneshot.agent.OneShotAgent]] = DEFAULT_PLACEHOLDER_AGENT_TYPES, rename: bool = False, randomize: bool = False) :classmethod: .. py:method:: contains_repeating_context(context: RepeatingContext, raise_on_failure: bool = False, warn_on_failure: bool = False) .. py:method:: is_valid_world(world: scml.oneshot.world.SCMLBaseWorld, raise_on_failure=RAISE_ON_FAILURE, warn_on_failure=WARN_ON_FAILURE, types: tuple[str | type[scml.oneshot.agent.OneShotAgent], Ellipsis] | None = None) -> bool Checks that the given world could have been generated from this context .. py:method:: contains_context(context: Context, raise_on_failure: bool = False, warn_on_failure: bool = False, n_tests: int = NTESTS) -> bool Checks that the any world generated from the given `context` could have been generated from this context