Coverage for tests / test_sites.py: 19%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-26 09:05 +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 

31from parsl.executors import HighThroughputExecutor, WorkQueueExecutor 

32from parsl.launchers import SingleNodeLauncher, SrunLauncher 

33 

34from lsst.ctrl.bps import BpsConfig 

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

36 Ccin2p3, 

37 Local, 

38 LocalSrunWorkQueue, 

39 Slurm, 

40 Torque, 

41 TripleSlurm, 

42) 

43 

44 

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

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

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

48 to be set. 

49 """ 

50 return BpsConfig( 

51 { 

52 "submitPath": ".", 

53 "operator": "operator", 

54 "computeSite": "slurm", 

55 "uniqProcName": "test_run", 

56 "site": { 

57 "slurm": { 

58 "class": site_class, 

59 "cores": 1, 

60 "nodes": nodes, 

61 "walltime": "00:01:00", 

62 } 

63 }, 

64 } 

65 ) 

66 

67 

68def testSiteResourceLists(): 

69 """Test compute site resource lists.""" 

70 config = get_bps_config() 

71 expected_resources = { 

72 HighThroughputExecutor: {"priority"}, 

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

74 } 

75 

76 site_classes = [Local, Slurm, Torque] 

77 if platform.machine() in ("aarch64", "x86_64"): 

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

79 site_classes.append(Ccin2p3) 

80 

81 try: 

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

83 # subclasses to the site_classes list. 

84 import ndcctools # noqa F401 

85 

86 site_classes.append(LocalSrunWorkQueue) 

87 except ImportError: 

88 pass 

89 

90 for site_class in site_classes: 

91 compute_site = site_class(config) 

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

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

94 

95 

96def testSlurmProviderLauncher(): 

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

98 SlurmProvider given the number of nodes. 

99 """ 

100 site_classes = [ 

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

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

103 ] 

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

105 for site_class_name, site_class in site_classes: 

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

107 site_config = site_class(config) 

108 executor = site_config.get_executors()[0] 

109 if nodes > 1: 

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

111 else: 

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