Coverage for tests / tests_references / test_circulation_alone.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 16:40 +0100

1# SPDX-FileCopyrightText: Copyright INRIA 

2# 

3# SPDX-License-Identifier: LGPL-3.0-only 

4# 

5# Copyright INRIA 

6# 

7# This file is part of PhysioBlocks, a library mostly developed by the 

8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA. 

9# 

10# Authors: 

11# - Colin Drieu 

12# - Dominique Chapelle 

13# - François Kimmig 

14# - Philippe Moireau 

15# 

16# PhysioBlocks is free software: you can redistribute it and/or modify it under the 

17# terms of the GNU Lesser General Public License as published by the Free Software 

18# Foundation, version 3 of the License. 

19# 

20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY 

21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 

22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

23# 

24# You should have received a copy of the GNU Lesser General Public License along with 

25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>. 

26 

27from copy import copy 

28 

29import pandas as pd 

30 

31from physioblocks.configuration.aliases import unwrap_aliases 

32from physioblocks.configuration.functions import load 

33from physioblocks.io.configuration import read_json 

34from physioblocks.simulation.runtime import ForwardSimulation 

35from physioblocks.simulation.time_manager import TIME_QUANTITY_ID 

36from physioblocks.utils.gradient_test_utils import gradient_test_from_file 

37 

38from .io import read_reference, results_close_to_data 

39 

40reference_path = ( 

41 "tests/tests_references/circulation_alone/ref_circulation_alone_sim.csv" 

42) 

43circulation_alone_path = "references/circulation_alone_sim.jsonc" 

44circulation_alone_gradient_test_path = ( 

45 "tests/tests_references/circulation_alone/circulation_alone_sim_gradient_test.json" 

46) 

47 

48 

49def test_circulation_alone_ref(): 

50 sim_config = read_json(circulation_alone_path) 

51 sim_config = unwrap_aliases(sim_config) 

52 sim: ForwardSimulation = load(sim_config) 

53 sim.time_manager.duration = 0.5 # Shorten simulation time to avoid test too long 

54 results = sim.run() 

55 

56 ref_df = read_reference(reference_path) 

57 ref_df = ref_df.set_index(TIME_QUANTITY_ID) 

58 

59 matching_ids = {data_id: data_id for data_id in results[0] if data_id != "time"} 

60 tol_factors = copy(sim.magnitudes) 

61 tol_factors["aorta_proximal.blood_flow"] = 1.0e-6 

62 

63 results_df = pd.DataFrame(results) 

64 results_df = results_df.set_index(TIME_QUANTITY_ID) 

65 

66 assert results_close_to_data( 

67 results_df, 

68 ref_df, 

69 matching_ids, 

70 1e-9, 

71 tol_factors, 

72 (sim.time_manager.start, sim.time_manager.start + sim.time_manager.duration), 

73 ) 

74 

75 

76def test_circulation_alone_gradient(): 

77 assert gradient_test_from_file(circulation_alone_gradient_test_path)