Skip to content

Commit

Permalink
fixes to cornflowclient + tests for WindProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Aug 16, 2024
1 parent 9621e26 commit 31c5c06
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cornflow-dags/DAG/sudoku/schemas/solution_checks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
},
"required": []
}
2 changes: 1 addition & 1 deletion cornflow-dags/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ortools
pyomo
tsplib95<=0.7.1
hackathonbaobab2020[solvers]
git+ssh://git@github.com/pchtsp/windenergybattery.git@article_case_validation#egg=windenergybattery
git+ssh://git@github.com/baobabsoluciones/windenergybattery.git@main#egg=windenergybattery
networkx

# quarto and reports:
Expand Down
32 changes: 32 additions & 0 deletions cornflow-dags/tests/test_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,38 @@ def test_report(self):
)


class WindProblem(BaseDAGTests.SolvingTests):
def setUp(self):
super().setUp()
from DAG.wind_problem import WindEnergyBattery

self.app = WindEnergyBattery()

@patch("cornflow_client.airflow.dag_utilities.connect_to_cornflow")
def test_complete_report(self, connectCornflow, config=None):
config = config or self.config
config = dict(**config, report=dict(name="report"))
tests = self.app.test_cases
for test_case in tests:
instance_data = test_case.get("instance")
solution_data = test_case.get("solution", None)
if solution_data is None:
solution_data = dict(solution_node_values=[])

mock = Mock()
mock.get_data.return_value = dict(
data=instance_data, solution_data=solution_data
)
mock.get_results.return_value = dict(config=config, state=1)
mock.create_report.return_value = dict(id=1)
connectCornflow.return_value = mock
dag_run = Mock()
dag_run.conf = dict(exec_id="exec_id")
cf_report(app=self.app, secrets="", dag_run=dag_run)
mock.create_report.assert_called_once()
mock.put_one_report.assert_called_once()


class Tsp(BaseDAGTests.SolvingTests):
def setUp(self):
super().setUp()
Expand Down
4 changes: 2 additions & 2 deletions libs/client/cornflow_client/airflow/dag_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ def my_try_to_save(state):
# maybe all of this should be abstracted inside the app?
# maybe the app should return an Experiment?
experiment = app.get_solver(app.get_default_solver_name())
my_experiment = experiment(
app.instance(input_data), app.solution(solution_data)
my_experiment = experiment.from_dict(
dict(instance=input_data, solution=solution_data)
)

print(f"Preparing to write the report: {report_name}")
Expand Down

0 comments on commit 31c5c06

Please sign in to comment.