Skip to content

Commit

Permalink
Merge branch 'fix_native_compatibility_ci' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
LourensVeen committed Dec 17, 2023
2 parents b354a24 + 1f63710 commit 4a40b3d
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_macos11_clang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
build:
runs-on: macos-11
timeout-minutes: 30
timeout-minutes: 60

steps:
- uses: actions/checkout@v4
Expand All @@ -22,7 +22,7 @@ jobs:
run: |
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
- name: Run all tests on macOS Big Sur 11 with Clang
run: cd ${GITHUB_WORKSPACE} && make test test_examples
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_macos11_gcc_gfortran.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ on:
jobs:
build:
runs-on: macos-11
timeout-minutes: 30
timeout-minutes: 60

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
brew install gcc
brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gcc
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_macos12_clang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: |
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
- name: Run all tests on macOS Monterey 12 with Clang
run: cd ${GITHUB_WORKSPACE} && make test test_examples
4 changes: 2 additions & 2 deletions .github/workflows/ci_macos12_gcc_gfortran.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:

- name: Install dependencies
run: |
brew install gcc
brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gcc
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_macos13_clang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:

- name: Install dependencies
run: |
brew install openmpi
brew install pkg-config
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install pkg-config
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_macos13_gcc_gfortran.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:

- name: Install dependencies
run: |
brew install gcc
brew install openmpi
brew install pkg-config
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install gcc
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install openmpi
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install pkg-config
python3 -m pip install --upgrade pip
pip3 install tox tox-gh-actions
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
matplotlib>=3,<4
numpy<1.22; python_version=='3.7'
numpy>=1.22,<=1.25; python_version>='3.8'
numpy>=1.22; python_version>='3.8'
sobol_seq==0.2.0
yatiml>=0.10.0,<0.11
ymmsl>=0.13,<0.14
Expand Down
143 changes: 101 additions & 42 deletions libmuscle/python/libmuscle/test/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from libmuscle.communicator import Message
from libmuscle.instance import Instance, InstanceFlags as IFlags
from libmuscle.mpp_message import ClosePort
from libmuscle.port import Port
from libmuscle.settings_manager import SettingsManager


Expand Down Expand Up @@ -37,27 +38,69 @@ def sys_argv_instance() -> Generator[None, None, None]:


@pytest.fixture
def instance(sys_argv_instance, tmp_path):
def overlay_settings():
settings = Settings()
settings['test1'] = 12
return settings


@pytest.fixture
def instance(sys_argv_instance, tmp_path, overlay_settings):
ports = {
Operator.F_INIT: ['in', 'not_connected'],
Operator.S: ['in_s', 'in_settings', 'not_connected_s'],
Operator.O_F: ['out', 'out_v']}

def port_exists(name):
return [name for op, names in ports.items() if name in names] != []

def is_connected(name):
return 'not_connected' not in name

def is_vector(name):
return name.endswith('_v')

def get_port(name):
return Port(
name,
[op for op, names in ports.items() if name in names][0],
is_vector(name), is_connected(name), 2,
[13, 42, 10] if is_vector(name) else [13, 42])

with patch('libmuscle.instance.MMPClient') as mmp_client, \
patch('libmuscle.instance.Communicator') as comm_type:
communicator = MagicMock()
settings = Settings()
settings['test1'] = 12
msg = Message(0.0, 1.0, 'message', settings)
communicator.receive_message.return_value = msg, 10.0
communicator.port_exists = MagicMock(side_effect=port_exists)
communicator.is_connected = MagicMock(side_effect=is_connected)
communicator.is_vector = MagicMock(side_effect=is_vector)
communicator.get_port = MagicMock(side_effect=get_port)

msg = Message(0.0, 1.0, 'message')
msg_with_settings = Message(0.0, 1.0, 'message', overlay_settings)

def receive_message(name, slot, default):
if 'not_connected' in name:
return default, 10.0
if 'settings' in name:
return msg_with_settings, 10.0
return msg, 10.0

communicator.receive_message = MagicMock(side_effect=receive_message)

comm_type.return_value = communicator

mmp_client_object = MagicMock()
mmp_client_object.request_peers.return_value = (None, None, None)

checkpoint_info = (0.0, Checkpoints(), None, tmp_path)
mmp_client_object.get_checkpoint_info.return_value = checkpoint_info

mmp_client.return_value = mmp_client_object

instance = Instance({
Operator.F_INIT: ['in', 'not_connected'],
Operator.O_F: ['out']})
instance = Instance(ports)
instance._f_init_cache = dict()
instance._f_init_cache[('in', None)] = msg

yield instance


Expand Down Expand Up @@ -97,8 +140,6 @@ def test_create_instance(
assert len(instance._settings_manager.overlay) == 0
mmp_client.assert_called_once_with(
Reference('test_instance[13][42]'), 'localhost:9000')
assert mmp_client_object._register.called_with()
assert mmp_client_object._connect.called_with()
comm_type.assert_called_with(Reference('test_instance'), [13, 42],
ports, instance._profiler)
assert instance._communicator == comm_type.return_value
Expand Down Expand Up @@ -154,98 +195,116 @@ def test_get_setting(instance):

def test_list_ports(instance):
ports = instance.list_ports()
assert instance._communicator.list_ports.called_with()
instance._communicator.list_ports.assert_called_with()
assert ports == instance._communicator.list_ports.return_value


def test_is_vector_port(instance):
instance._communicator.get_port.return_value.is_vector = MagicMock(
return_value=True)
is_vector = instance.is_vector_port('out_port')
assert is_vector is True
assert instance._communicator.get_port.called_with('out_port')
assert instance.is_vector_port('out_v')
instance._communicator.get_port.assert_called_with('out_v')


def test_send(instance, message):
instance._trigger_manager._cpts_considered_until = 17.0
instance.send('out', message, 1)
assert instance._communicator.send_message.called_with(
'out', message, 1, 17.0)
instance._communicator.send_message.assert_called_with('out', message, 1, 17.0)


def test_send_invalid_port(instance, message):
instance._communicator.port_exists.return_value = False
with pytest.raises(RuntimeError):
instance.send('does_not_exist', message, 1)


def test_receive(instance):
instance._communicator.get_port.return_value = MagicMock(
operator=Operator.F_INIT)
msg = instance.receive('in_s')
assert msg.timestamp == 0.0
assert msg.next_timestamp == 1.0
assert msg.data == 'message'
instance._communicator.receive_message.assert_called_with('in_s', None, None)


def test_receive_cached(instance):
msg = instance.receive('in')
assert msg.timestamp == 0.0
assert msg.next_timestamp == 1.0
assert instance._communicator.receive_message.called_with(
'in', None)
assert msg.data == 'message'
instance._communicator.receive_message.assert_not_called()

with pytest.raises(RuntimeError):
instance.receive('in')


def test_receive_default(instance):
instance._communicator.port_exists.return_value = True
port = instance._communicator.get_port.return_value
port.operator = Operator.F_INIT
port.is_connected.return_value = False
instance.receive('not_connected', 1, 'testing')
assert instance._communicator.receive_message.called_with(
'not_connected', 1, 'testing')
default_msg = Message(1.0, 2.0, 'testing')
msg = instance.receive('not_connected_s', 1, default_msg)
instance._communicator.receive_message.assert_called_with(
'not_connected_s', 1, default_msg)
assert msg == default_msg


def test_receive_default_cached(instance):
msg = instance.receive('not_connected', 1, Message(1.0, 2.0, 'testing'))
assert msg.timestamp == 1.0
assert msg.next_timestamp == 2.0
assert msg.data == 'testing'
instance._communicator.receive_message.assert_not_called()
with pytest.raises(RuntimeError):
instance.receive('not_connected', 1)


def test_receive_invalid_port(instance):
instance._communicator.port_exists.return_value = False
with pytest.raises(RuntimeError):
instance.receive('does_not_exist', 1)


def test_receive_with_settings(instance):
msg = instance.receive_with_settings('in', 1)
assert (instance._communicator.receive_message
.called_with('in', 1))
def test_receive_with_settings(instance, overlay_settings):
instance._settings_manager.overlay = overlay_settings
msg = instance.receive_with_settings('in_settings')
instance._communicator.receive_message.assert_called_with(
'in_settings', None, None)
assert msg.timestamp == 0.0
assert msg.next_timestamp == 1.0
assert msg.data == 'message'
assert msg.settings['test1'] == 12


def test_receive_with_settings_default(instance):
instance.receive_with_settings('not_connected', 1, 'testing')
assert instance._communicator.receive_message.called_with(
'not_connected', 1, 'testing')
settings = Settings()
settings['test1'] = 42
default_msg = Message(1.0, 2.0, 'testing', settings)
msg = instance.receive_with_settings('not_connected_s', default=default_msg)
instance._communicator.receive_message.assert_called_with(
'not_connected_s', None, msg)
assert msg.settings['test1'] == 42


def test_receive_parallel_universe(instance) -> None:
instance._settings_manager.overlay['test2'] = 'test'
with pytest.raises(RuntimeError):
instance.receive('in')
instance.receive('in_settings')


def test_reuse_instance_receive_overlay(instance):
instance._settings_manager.overlay = Settings()

test_base_settings = Settings()
test_base_settings['test1'] = 24
test_base_settings['test2'] = [1.3, 2.0]

test_overlay = Settings()
test_overlay['test2'] = 'abc'
recv = instance._communicator.receive_message

msg = Message(0.0, None, test_overlay, test_base_settings)

recv = instance._communicator.receive_message
recv.reset_mock(side_effect=True)
recv.return_value = msg, 0.0

instance.reuse_instance()
assert instance._communicator.receive_message.called_with(
'muscle_settings_in')
instance._communicator.receive_message.assert_called()
assert instance._communicator.receive_message.call_args[0][0] == (
'muscle_settings_in')

assert len(instance._settings_manager.overlay) == 2
assert instance._settings_manager.overlay['test1'] == 24
assert instance._settings_manager.overlay['test2'] == 'abc'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
'msgpack>=1,<2',
'netifaces==0.11.0',
"numpy<1.22; python_version=='3.7'",
"numpy>=1.22,<=1.25; python_version>='3.8'",
"numpy>=1.22; python_version>='3.8'",
'qcg-pilotjob==0.13.1',
'typing_extensions>=4.4.0,<5',
'ymmsl>=0.13.0,<0.14' # Also in CI, update there as well
Expand Down

0 comments on commit 4a40b3d

Please sign in to comment.