Skip to content

xpansion_configuration

Classes:

XpansionConfiguration

XpansionConfiguration(
    xpansion_service: BaseXpansionService,
    settings: XpansionSettings,
    sensitivity: XpansionSensitivity,
    candidates: Optional[dict[str, XpansionCandidate]] = None,
    constraints: Optional[dict[str, XpansionConstraint]] = None,
)

Xpansion configuration.

Methods:

Attributes:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def __init__(
    self,
    xpansion_service: BaseXpansionService,
    settings: XpansionSettings,
    sensitivity: XpansionSensitivity,
    candidates: Optional[dict[str, XpansionCandidate]] = None,
    constraints: Optional[dict[str, XpansionConstraint]] = None,
):
    self._settings = settings
    self._candidates = candidates or {}
    self._constraints = constraints or {}
    self._sensitivity = sensitivity
    self._xpansion_service = xpansion_service

sensitivity property

sensitivity: XpansionSensitivity

Xpansion sensitivity parameters.

settings property

settings: XpansionSettings

Xpansion settings.

create_candidate

Create a candidate in the current configuration.

Parameters:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def create_candidate(self, candidate: XpansionCandidate) -> XpansionCandidate:
    """Create a candidate in the current configuration.

    Args:
        candidate: The Xpansion candidate.
    """
    cdt = self._xpansion_service.create_candidate(candidate)
    self._candidates[cdt.name] = cdt
    return cdt

create_constraint

Create a constraint in the current configuration.

Parameters:

  • constraint

    (XpansionConstraint) –

    Xpansion constraint between invested capacities.

  • file_name

    (str) –

    The .ini constraint file. See https://antares-xpansion.readthedocs.io/en/stable/user-guide/get-started/settings-definition/#additional-constraints for an example of the constraint file format

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def create_constraint(self, constraint: XpansionConstraint, file_name: str) -> XpansionConstraint:
    """Create a constraint in the current configuration.

    Args:
        constraint: Xpansion constraint between invested capacities.
        file_name: The `.ini` constraint file. See https://antares-xpansion.readthedocs.io/en/stable/user-guide/get-started/settings-definition/#additional-constraints for an example of the constraint file format

    Returns:
        The constraint.
    """
    constraint = self._xpansion_service.create_constraint(constraint, file_name)
    self._constraints[constraint.name] = constraint
    return constraint

delete_candidates

delete_candidates(names: list[str]) -> None

Delete candidates if not referenced inside the sensitivity config.

Parameters:

  • names

    (list[str]) –

    List of the candidates' name.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def delete_candidates(self, names: list[str]) -> None:
    """Delete candidates if not referenced inside the sensitivity config.

    Args:
        names: List of the candidates' name.
    """
    problematic_candidates = set()
    for name in names:
        if name in set(self._sensitivity.projection):
            problematic_candidates.add(name)
    if problematic_candidates:
        raise XpansionCandidateDeletionError(
            self._xpansion_service.study_id, problematic_candidates, "They are referenced in the sensitivity config"
        )
    # Performs the deletion
    self._xpansion_service.delete_candidates(set(names))
    for name in names:
        del self._candidates[name]

delete_capacity

delete_capacity(file_name: str) -> None

Delete a capacity file if not referenced in a candidate.

Parameters:

  • file_name

    (str) –

    capacity filename

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def delete_capacity(self, file_name: str) -> None:
    """Delete a capacity file if not referenced in a candidate.

    Args:
        file_name: capacity filename
    """
    for candidate in self._candidates.values():
        for profile in [
            "direct_link_profile",
            "indirect_link_profile",
            "already_installed_direct_link_profile",
            "already_installed_indirect_link_profile",
        ]:
            if file_name == getattr(candidate, profile):
                raise XpansionResourceDeletionError(
                    "capacity", file_name, f"It is referenced in the candidate {candidate.name}"
                )

    return self._xpansion_service.delete_matrix(file_name, XpansionMatrix.CAPACITIES)

delete_constraints

delete_constraints(names: list[str], file_name: str) -> None

Delete constraints in the current configuration.

Parameters:

  • names

    (list[str]) –

    A list of constraint names.

  • file_name

    (str) –

    The associated constraint file.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def delete_constraints(self, names: list[str], file_name: str) -> None:
    """Delete constraints in the current configuration.

    Args:
        names: A list of constraint names.
        file_name: The associated constraint file.
    """
    self._xpansion_service.delete_constraints(names, file_name)
    for name in names:
        del self._constraints[name]

delete_constraints_file

delete_constraints_file(file_name: str) -> None

Delete constraint file.

Parameters:

  • file_name

    (str) –

    Name of the constraint file.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def delete_constraints_file(self, file_name: str) -> None:
    """Delete constraint file.

    Args:
        file_name: Name of the constraint file.
    """
    # Checks the constraint file is not referenced in the settings
    if self._settings.additional_constraints == file_name:
        raise XpansionResourceDeletionError("constraints", file_name, "It is referenced in the settings")
    self._xpansion_service.delete_constraints_file(file_name)

delete_weight

delete_weight(file_name: str) -> None

Delete a weight file if not referenced in the settings.

Parameters:

  • file_name

    (str) –

    weight filename

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def delete_weight(self, file_name: str) -> None:
    """Delete a weight file if not referenced in the settings.

    Args:
        file_name: weight filename
    """
    if self._settings.yearly_weights == file_name:
        raise XpansionResourceDeletionError("weight", file_name, "It is referenced in the settings")

    return self._xpansion_service.delete_matrix(file_name, XpansionMatrix.WEIGHTS)

get_candidates

get_candidates() -> MappingProxyType[str, XpansionCandidate]

Get investments candidates.

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def get_candidates(self) -> MappingProxyType[str, XpansionCandidate]:
    """Get investments candidates.

    Returns:
        Read-only dictionnary of the investments candidates.
    """
    return MappingProxyType(self._candidates)

get_capacity

get_capacity(file_name: str) -> DataFrame

Get capacities.

Returns:

  • DataFrame

    Xpansion capacity matrix.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def get_capacity(self, file_name: str) -> pd.DataFrame:
    """Get capacities.

    Returns:
        Xpansion capacity matrix.
    """
    return self._xpansion_service.get_matrix(file_name, XpansionMatrix.CAPACITIES)

get_constraints

get_constraints() -> MappingProxyType[str, XpansionConstraint]

Get constraints.

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def get_constraints(self) -> MappingProxyType[str, XpansionConstraint]:
    """Get constraints.

    Returns:
        Read-only dictionnary of Xpansion constraints.
    """
    return MappingProxyType(self._constraints)

get_weight

get_weight(file_name: str) -> DataFrame

Get weigths.

Returns:

  • DataFrame

    Xpansion weight matrix.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def get_weight(self, file_name: str) -> pd.DataFrame:
    """Get weigths.

    Returns:
        Xpansion weight matrix.
    """
    return self._xpansion_service.get_matrix(file_name, XpansionMatrix.WEIGHTS)

remove_constraints_and_or_weights_from_settings

remove_constraints_and_or_weights_from_settings(constraint: bool, weight: bool) -> None

Remove constraints or weights from settings.

Parameters:

  • constraint

    (bool) –

    Whether to remove the constraints.

  • weight

    (bool) –

    Whether to remove the constraints.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def remove_constraints_and_or_weights_from_settings(self, constraint: bool, weight: bool) -> None:
    """Remove constraints or weights from settings.

    Args:
        constraint: Whether to remove the constraints.
        weight: Whether to remove the constraints.
    """
    if not constraint and not weight:
        return
    new_settings = self._xpansion_service.remove_constraints_and_or_weights_from_settings(
        constraint, weight, self._settings
    )
    self._settings = new_settings
remove_links_profile_from_candidate(
    name: str, profiles: list[XpansionLinkProfile]
) -> None

Remove link profile from candidate.

Parameters:

  • (str) –

    Name of the candidate.

  • (list[XpansionLinkProfile]) –

    List of link profiles (DIRECT_LINK, INDIRECT_LINK, ALREADY_INSTALLED_DIRECT_LINK or ALREADY_INSTALLED_INDIRECT_LINK)

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def remove_links_profile_from_candidate(self, name: str, profiles: list[XpansionLinkProfile]) -> None:
    """Remove link profile from candidate.

    Args:
        name: Name of the candidate.
        profiles: List of link profiles (`DIRECT_LINK`, `INDIRECT_LINK`, `ALREADY_INSTALLED_DIRECT_LINK`
            or `ALREADY_INSTALLED_INDIRECT_LINK`)
    """
    current_candidate = self._candidates[name]
    new_candidate = self._xpansion_service.remove_links_profile_from_candidate(current_candidate, profiles)
    self._candidates[name] = new_candidate

set_capacity

set_capacity(file_name: str, series: DataFrame) -> None

Set capacity.

Parameters:

  • file_name

    (str) –

    Filename of the file to create.

  • series

    (DataFrame) –

    Capacities to put in the file.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def set_capacity(self, file_name: str, series: pd.DataFrame) -> None:
    """Set capacity.

    Args:
        file_name: Filename of the file to create.
        series: Capacities to put in the file.
    """
    return self._xpansion_service.set_matrix(file_name, series, XpansionMatrix.CAPACITIES)

set_weight

set_weight(file_name: str, series: DataFrame) -> None

Set weigths.

Parameters:

  • file_name

    (str) –

    Filename of the file to create.

  • series

    (DataFrame) –

    Weights to put in the file.

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def set_weight(self, file_name: str, series: pd.DataFrame) -> None:
    """Set weigths.

    Args:
        file_name: Filename of the file to create.
        series: Weights to put in the file.
    """
    return self._xpansion_service.set_matrix(file_name, series, XpansionMatrix.WEIGHTS)

update_candidate

Update a candidate in the current configuration.

Parameters:

  • candidate_name

    (str) –

    The Xpansion candidate name to update.

  • candidate

    (XpansionCandidateUpdate) –

    The updates parameters and field.

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def update_candidate(self, candidate_name: str, candidate: XpansionCandidateUpdate) -> XpansionCandidate:
    """Update a candidate in the current configuration.

    Args:
        candidate_name: The Xpansion candidate name to update.
        candidate: The updates parameters and field.

    Returns:
        The updates Xpansion candidate.
    """
    if candidate.name and candidate.name != candidate_name:
        # Means we're renaming a candidate
        # We have to check it wasn't referenced inside the sensitivity config
        if candidate_name in self._sensitivity.projection:
            raise XpansionCandidateEditionError(
                self._xpansion_service.study_id, candidate_name, "It is referenced in the sensitivity config"
            )

    cdt = self._xpansion_service.update_candidate(candidate_name, candidate)
    if cdt.name not in self._candidates:
        # Means we're renaming a candidate (+ updating it)
        del self._candidates[candidate_name]

    self._candidates[cdt.name] = cdt
    return cdt

update_constraint

Update a constraint in the current configuration.

Parameters:

  • name

    (str) –

    The name of the constraint.

  • constraint

    (XpansionConstraintUpdate) –

    The (partially) updated constraint.

  • file_name

    (str) –

    The constraint file.

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def update_constraint(self, name: str, constraint: XpansionConstraintUpdate, file_name: str) -> XpansionConstraint:
    """Update a constraint in the current configuration.

    Args:
        name: The name of the constraint.
        constraint: The (partially) updated constraint.
        file_name: The constraint file.

    Returns:
        The new constraint.
    """
    new_constraint = self._xpansion_service.update_constraint(name, constraint, file_name)
    if new_constraint.name != name:
        # We're renaming a constraint
        del self._constraints[name]
    self._constraints[new_constraint.name] = new_constraint
    return new_constraint

update_sensitivity

Update sensitivity.

Parameters:

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def update_sensitivity(self, sensitivity: XpansionSensitivityUpdate) -> XpansionSensitivity:
    """Update sensitivity.

    Args:
        sensitivity: Sensitivity (partial) update.

    Returns:
        The updated sensitivity parameters.
    """
    # Ensures projections correspond to existing candidates
    if sensitivity.projection:
        problematic_candidates = set()
        for name in sensitivity.projection:
            if name not in self._candidates:
                problematic_candidates.add(name)
        if problematic_candidates:
            raise XpansionSensitivityEditionError(
                self._xpansion_service.study_id, f"The candidates {problematic_candidates} do not exist"
            )
    # Performs the update
    new_sensitivity = self._xpansion_service.update_sensitivity(sensitivity, self._settings, self._sensitivity)
    self._sensitivity = new_sensitivity
    return new_sensitivity

update_settings

Update Xpansion settings in this configuration.

Parameters:

Returns:

Source code in src/antares/craft/model/xpansion/xpansion_configuration.py
def update_settings(self, settings: XpansionSettingsUpdate) -> XpansionSettings:
    """Update Xpansion settings in this configuration.

    Args:
        settings: The settings to update.

    Returns:
        The updated settings.
    """
    new_settings = self._xpansion_service.update_settings(settings, self._settings)
    self._settings = new_settings
    return new_settings

XpansionMatrix

Xpansion matrix types.

Attributes:

  • CAPACITIES

    Link profile matrix type.

  • WEIGHTS

    Yearly weight matrix type.