Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…vement/Simod into conditions
  • Loading branch information
SimpleSquirrelz committed Aug 28, 2024
2 parents 51a509b + 8c8cd73 commit 81725f0
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "simod"
version = "4.1.2"
version = "5.0.0"
authors = [
"Ihar Suvorau <[email protected]>",
"David Chapela <[email protected]>",
Expand Down
27 changes: 21 additions & 6 deletions src/simod/settings/simod_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SimodSettings(BaseModel):
control_flow: ControlFlowSettings = ControlFlowSettings()
resource_model: ResourceModelSettings = ResourceModelSettings()
extraneous_activity_delays: Union[ExtraneousDelaysSettings, None] = None
version: int = 4
version: int = 5

@staticmethod
def default() -> "SimodSettings":
Expand Down Expand Up @@ -56,11 +56,13 @@ def one_shot() -> "SimodSettings":

@staticmethod
def from_yaml(config: dict, config_dir: Optional[Path] = None) -> "SimodSettings":
assert config["version"] in [2, 4], "Configuration version must be 2 or 4"
assert config["version"] in [2, 4, 5], "Configuration version must be 2, 4, or 5"

# Transform from previous version to the latest if needed
if config["version"] == 2:
config = _parse_legacy_config(config)
config = _parse_legacy_config_2(config)
elif config["version"] == 4:
config = _parse_legacy_config_4(config)

# Get each of the settings components if present, default otherwise
if "common" in config:
Expand Down Expand Up @@ -136,11 +138,11 @@ def to_yaml(self, output_dir: Path) -> Path:
return output_path


def _parse_legacy_config(config: dict) -> dict:
def _parse_legacy_config_2(config: dict) -> dict:
parsed_config = copy.deepcopy(config)
if config["version"] == 2:
# Transform dictionary from version 2 to 4
parsed_config["version"] = 4
# Transform dictionary from version 2 to 5
parsed_config["version"] = 5
# Common elements
if "log_path" in parsed_config["common"]:
parsed_config["common"]["train_log_path"] = parsed_config["common"]["log_path"]
Expand Down Expand Up @@ -174,3 +176,16 @@ def _parse_legacy_config(config: dict) -> dict:
del parsed_config["resource_model"]["case_arrival"]
# Return parsed configuration
return parsed_config


def _parse_legacy_config_4(config: dict) -> dict:
parsed_config = copy.deepcopy(config)
if config["version"] == 4:
# Transform dictionary from version 4 to 5
parsed_config["version"] = 5
# Common elements
if "discover_case_attributes" in parsed_config["common"]:
parsed_config["common"]["discover_data_attributes"] = parsed_config["common"]["discover_case_attributes"]
del parsed_config["common"]["discover_case_attributes"]
# Return parsed configuration
return parsed_config
2 changes: 1 addition & 1 deletion tests/assets/configuration_simod_basic.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
test_log_path: LoanApp_simplified.csv.gz
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/configuration_simod_with_extraneous.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
discover_data_attributes: true
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/configuration_simod_with_model.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
process_model_path: LoanApp_simplified.bpmn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
test_log_path: LoanApp_simplified.csv.gz
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
process_model_path: LoanApp_simplified.bpmn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4
version: 5
common:
train_log_path: LoanApp_simplified.csv.gz
test_log_path: LoanApp_simplified.csv.gz
Expand Down
62 changes: 57 additions & 5 deletions tests/test_settings/test_simod_settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
from pathlib import Path

import pytest
import yaml

from simod.settings.simod_settings import SimodSettings

settings = """
settings_5 = """
version: 5
common:
train_log_path: assets/LoanApp_simplified.csv.gz
perform_final_evaluation: true
num_final_evaluations: 1
evaluation_metrics:
- dl
- absolute_event_distribution
discover_data_attributes: true
preprocessing:
multitasking: false
control_flow:
num_iterations: 2
mining_algorithm: sm1
epsilon:
- 0.0
- 1.0
eta:
- 0.0
- 1.0
gateway_probabilities:
- equiprobable
- discovery
replace_or_joins:
- true
- false
prioritize_parallelism:
- true
- false
resource_model:
num_iterations: 2
discover_prioritization_rules: true
resource_profiles:
discovery_type: differentiated_by_pool
granularity: 60
confidence:
- 0.5
- 0.85
support:
- 0.01
- 0.3
participation: 0.4
"""

settings_4 = """
version: 4
common:
train_log_path: assets/LoanApp_simplified.csv.gz
Expand All @@ -14,6 +58,7 @@
evaluation_metrics:
- dl
- absolute_event_distribution
discover_case_attributes: true
preprocessing:
multitasking: false
control_flow:
Expand Down Expand Up @@ -50,9 +95,8 @@
"""


@pytest.mark.parametrize("test_case", [settings], ids=["default"])
def test_configuration(test_case):
config = yaml.safe_load(test_case)
def test_configuration():
config = yaml.safe_load(settings_5)
result = SimodSettings.from_yaml(config)

assert result is not None
Expand All @@ -62,6 +106,14 @@ def test_configuration(test_case):
assert_resource_model(config, result)


def test_configuration_legacy():
ground_truth = SimodSettings.from_yaml(yaml.safe_load(settings_5))
legacy = SimodSettings.from_yaml(yaml.safe_load(settings_4))

assert legacy is not None
assert ground_truth.to_dict() == legacy.to_dict()


def assert_common(config: dict, result: SimodSettings):
config_common = config["common"]
result_common = result.common
Expand Down

0 comments on commit 81725f0

Please sign in to comment.