Coverage for tests/test_sites.py: 95%

48 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-17 09:09 +0000

1# This file is part of ctrl_bps_parsl. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org) and the LSST DESC (https://www.lsstdesc.org/). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27 

28 

29import platform 

30 

31import parsl.config 

32from parsl.dataflow.memoization import BasicMemoizer 

33from parsl.executors import HighThroughputExecutor, WorkQueueExecutor 

34from parsl.launchers import SingleNodeLauncher, SrunLauncher 

35 

36from lsst.ctrl.bps import BpsConfig 

37from lsst.ctrl.bps.parsl.sites import ( 

38 Ccin2p3, 

39 Local, 

40 LocalSrunWorkQueue, 

41 Slurm, 

42 Torque, 

43 TripleSlurm, 

44) 

45 

46 

47def get_bps_config(nodes=1, site_class="lsst.ctrl.bps.parsl.sites.Slurm"): 

48 """Provide a minimal config that allows compute site classes to be 

49 created, allowing for the site class type and the number of nodes 

50 to be set. 

51 

52 Parameters 

53 ---------- 

54 nodes : `int`, optional 

55 Number of nodes to request for the site. 

56 site_class : `str`, optional 

57 Fully qualified name of the compute site class. 

58 

59 Returns 

60 ------- 

61 config : `lsst.ctrl.bps.BpsConfig` 

62 The BPS configuration. 

63 """ 

64 return BpsConfig( 

65 { 

66 "submitPath": ".", 

67 "operator": "operator", 

68 "computeSite": "slurm", 

69 "uniqProcName": "test_run", 

70 "site": { 

71 "slurm": { 

72 "class": site_class, 

73 "cores": 1, 

74 "nodes": nodes, 

75 "walltime": "00:01:00", 

76 } 

77 }, 

78 } 

79 ) 

80 

81 

82def testSiteResourceLists(): 

83 """Test compute site resource lists.""" 

84 config = get_bps_config() 

85 expected_resources = { 

86 HighThroughputExecutor: {"priority"}, 

87 WorkQueueExecutor: {"memory", "cores", "disk", "running_time_min", "priority"}, 

88 } 

89 

90 site_classes = [Local, Slurm, Torque] 

91 if platform.machine() in ("aarch64", "x86_64"): 91 ↛ 95line 91 didn't jump to line 95 because the condition on line 91 was always true

92 # If running on a supported architecture, then add Ccin2p3 site class. 

93 site_classes.append(Ccin2p3) 

94 

95 try: 

96 # If the ndcctools module is available, then add WorkQueue 

97 # subclasses to the site_classes list. 

98 import ndcctools # noqa F401 

99 

100 site_classes.append(LocalSrunWorkQueue) 

101 except ImportError: 

102 pass 

103 

104 for site_class in site_classes: 

105 compute_site = site_class(config) 

106 executor_type = type(compute_site.get_executors()[0]) 

107 assert expected_resources[executor_type] == set(compute_site.resource_list) 

108 

109 

110def testGetParslConfig(): 

111 """ 

112 Test that get_parsl_config returns a properly configured parsl Config. 

113 """ 

114 config = get_bps_config() 

115 site_classes = [Slurm] 

116 if platform.machine() in ("aarch64", "x86_64"): 116 ↛ 119line 116 didn't jump to line 119 because the condition on line 116 was always true

117 # If running on a supported architecture, then add Ccin2p3 site class. 

118 site_classes.append(Ccin2p3) 

119 for site_config_class in site_classes: 

120 site_config = site_config_class(config) 

121 parsl_config = site_config.get_parsl_config() 

122 

123 assert isinstance(parsl_config, parsl.config.Config) 

124 assert isinstance(parsl_config.memoizer, BasicMemoizer) 

125 assert parsl_config.monitoring is None 

126 assert parsl_config.retries == 1 

127 assert parsl_config.run_dir == "runinfo" or parsl_config.run_dir == "parsl_runinfo" 

128 assert parsl_config.memoizer.checkpoint_mode == "task_exit" 

129 

130 

131def testSlurmProviderLauncher(): 

132 """Test that the correct parsl launcher is selected for the 

133 SlurmProvider given the number of nodes. 

134 """ 

135 site_classes = [ 

136 ("lsst.ctrl.bps.parsl.Slurm", Slurm), 

137 ("lsst.ctrl.bps.parsl.TripleSlurm", TripleSlurm), 

138 ] 

139 for nodes in (1, 2, 3): 

140 for site_class_name, site_class in site_classes: 

141 config = get_bps_config(nodes=nodes, site_class=site_class_name) 

142 site_config = site_class(config) 

143 executor = site_config.get_executors()[0] 

144 if nodes > 1: 

145 assert isinstance(executor.provider.launcher, SrunLauncher) 

146 else: 

147 assert isinstance(executor.provider.launcher, SingleNodeLauncher)