-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the logic in QsubBatchSettings
Much of the need to check the type and value of the the nodes property in QsubBatchSettings is because there are two technically valid, but not quite equivalent ways of setting the number of nodes. Now, we check at various points that the both 'select' and 'nodes' is not set. Additionally, both routes can be used to set the internal _nodes property if it needs to be accessed within Python
- Loading branch information
Showing
4 changed files
with
153 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# BSD 2-Clause License | ||
# | ||
# Copyright (c) 2021-2023, Hewlett Packard Enterprise | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import pytest | ||
|
||
from smartsim.error import SSConfigError | ||
from smartsim.settings import QsubBatchSettings | ||
|
||
# The tests in this file belong to the group_b group | ||
pytestmark = pytest.mark.group_b | ||
|
||
|
||
def test_node_formatting(): | ||
def validate_settings(settings, spec, num_nodes, num_cpus): | ||
assert settings._create_resource_list() == [ | ||
f"-l {spec}={num_nodes}:ncpus={num_cpus}" | ||
] | ||
assert settings._ncpus == num_cpus | ||
assert settings._nodes == num_nodes | ||
|
||
num_nodes = 10 | ||
num_cpus = 36 | ||
|
||
# Test by specifying the number of nodes via setting a resource | ||
for spec in ["nodes", "select"]: | ||
# Test by setting nodes | ||
settings = QsubBatchSettings() | ||
settings.set_resource(spec, num_nodes) | ||
settings.set_ncpus(36) | ||
validate_settings(settings, spec, num_nodes, num_cpus) | ||
|
||
# Test when setting nodes through the constructor | ||
settings = QsubBatchSettings(ncpus=num_cpus, nodes=num_nodes) | ||
validate_settings(settings, "nodes", num_nodes, num_cpus) | ||
|
||
# Test when setting nodes through the constructor via resource | ||
settings = QsubBatchSettings(ncpus=num_cpus, resources={"nodes": num_nodes}) | ||
validate_settings(settings, "nodes", num_nodes, num_cpus) | ||
|
||
# Test when setting select through the constructor via resource | ||
settings = QsubBatchSettings(ncpus=num_cpus, resources={"select": num_nodes}) | ||
validate_settings(settings, "select", num_nodes, num_cpus) | ||
|
||
|
||
def test_select_nodes_error(): | ||
|
||
# # Test failure on initialization | ||
with pytest.raises(SSConfigError): | ||
QsubBatchSettings(nodes=10, resources={"select": 10}) | ||
|
||
# Test setting via nodes and then select | ||
settings = QsubBatchSettings() | ||
settings.set_nodes(10) | ||
with pytest.raises(SSConfigError): | ||
settings.set_resource("select", 10) | ||
|
||
# Manually put "select" in the resource dictionary and | ||
# make sure the resource formatter catches the error | ||
settings = QsubBatchSettings() | ||
settings.resources = {"nodes": 10, "select": 20} | ||
with pytest.raises(SSConfigError): | ||
settings._create_resource_list() | ||
|
||
# # Test setting via select and then nodes | ||
settings = QsubBatchSettings() | ||
settings.set_resource("select", 10) | ||
with pytest.raises(SSConfigError): | ||
settings.set_nodes(10) |