Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-abstract Savable by making it a protocol #298

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c86e502
Use uv.lock
unkcpz Jan 17, 2025
5980bd6
Defer import of aio_pika
unkcpz Dec 11, 2024
827d5c8
Explicit future implementation: distinguish concurrent.future.Future …
unkcpz Dec 11, 2024
cf58970
Move communication into rmq module
unkcpz Dec 11, 2024
307514c
Move TaskRejectError as the common exception for task launch
unkcpz Dec 14, 2024
3ef6bd8
Remove useless communicator param passed to ProcessLaunch __call__
unkcpz Dec 14, 2024
3536f29
Forming Communicator protocol
unkcpz Dec 14, 2024
ee0da23
Remove kiwipy/rmq dependencies of process module
unkcpz Dec 14, 2024
7f5e7ce
Interface change from communicator -> coordinator
unkcpz Dec 17, 2024
229747c
Remove unnecessary task_send ab from RemoteProcessControl interface
unkcpz Dec 17, 2024
758fa3b
Interface for ProcessController
unkcpz Dec 17, 2024
e9b1da6
RmqCoordinator example to show how using interface can avoid making c…
unkcpz Dec 17, 2024
b564a0f
broadcast subscriber has versatile filters
unkcpz Dec 18, 2024
df92da4
Generic typing for Coordinator
unkcpz Dec 19, 2024
3872dc3
changes required for aiida-core support
unkcpz Dec 19, 2024
c5ce865
Adopt new message protocol
unkcpz Dec 20, 2024
68f7409
Simpler create_task_threadsafe implementation
unkcpz Dec 30, 2024
60bfdab
Remove RmqCoordinator to tests/util only
unkcpz Jan 10, 2025
21c8157
Export plumpy.futures.Future
unkcpz Jan 11, 2025
6ce23b2
Explict module import list in __init__.py (#8)
unkcpz Jan 18, 2025
dd17ccc
Remove the middle layer of statemachine.State + Savable abstraction
unkcpz Dec 2, 2024
a684daf
Move is_terminal as class attribute required
unkcpz Dec 2, 2024
f023e9c
forming the enter/exit for State protocol
unkcpz Dec 2, 2024
50d7f65
Forming Interruptable and Proceedable protocol
unkcpz Dec 2, 2024
a111cd8
Refactoring create_state as static function initialize state from label
unkcpz Dec 2, 2024
11f7518
To lenthy for rethinking
unkcpz Dec 4, 2024
da45d60
Move static method load outside
unkcpz Dec 4, 2024
3993e4c
save_instance_state simplify to only has save interface
unkcpz Dec 9, 2024
dab66cc
load_instance_state deabstract simplify
unkcpz Dec 9, 2024
4bf5e99
ProcessListener recreate_from
unkcpz Dec 9, 2024
cc80a0b
Absorb all load_instance_state into recreate_from
unkcpz Dec 9, 2024
efb322b
Remove useless persist method of Savable class
unkcpz Dec 9, 2024
94590a6
Explicity recreate_from implementation
unkcpz Dec 9, 2024
90848fa
forming Savable protocol
unkcpz Dec 9, 2024
d5680d7
Make auto_load symmetry with auto_save and state/state_label distinguish
unkcpz Dec 10, 2024
4195247
misc rebase
unkcpz Jan 18, 2025
4f6a2bb
debug logger when state change
unkcpz Jan 18, 2025
15ce0fe
logger for load process from context
unkcpz Jan 18, 2025
845a7d6
Using typing-extensions for 3.9 support of @override
unkcpz Jan 22, 2025
b485d7d
Move BroadcastFilter from kiwipy into plumpy and used directly (#34)
unkcpz Feb 5, 2025
0a3b65e
Merge branch 'fork' into deab-savable-inh
unkcpz Feb 5, 2025
d931848
Bump to use pytest-asyncio ~=0.25 which deprecate get_event_loop (#35)
unkcpz Feb 5, 2025
1fa8a09
Create/Launch/Continue body into builder (#37)
unkcpz Feb 5, 2025
94e7fe2
Merge branch 'fork' into deab-savable-inh
unkcpz Feb 5, 2025
40e2d91
Move create_task function to rmq (#40)
unkcpz Feb 5, 2025
897a5c4
Merge branch 'fork' into deab-savable-inh
unkcpz Feb 11, 2025
76c887f
mis
unkcpz Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ WorkChains support the use of logical constructs such as `If_` and `While_` to c

A `Controller` can control processes throughout their lifetime, by sending and receiving messages. It can launch, pause, continue, kill and check status of the process.

The {py:class}`~plumpy.process_comms.RemoteProcessThreadController` can communicate with the process over the thread communicator provided by {{kiwipy}} which can subscribe and send messages over the {{rabbitmq}} message broker.
The {py:class}`~plumpy.rmq.process_control.RemoteProcessThreadController` can communicate with the process over the thread communicator provided by {{kiwipy}} which can subscribe and send messages over the {{rabbitmq}} message broker.

The thread communicator runs on a independent thread (event loop) and so will not be blocked by sometimes long waiting times in the process event loop.
Using RabbitMQ means that even if the computer is terminated unexpectedly, messages are persisted and can be run once the computer restarts.
4 changes: 2 additions & 2 deletions docs/source/nitpick-exceptions
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ py:class kiwipy.communications.Communicator

# unavailable forward references
py:class plumpy.process_states.Command
py:class plumpy.process_states.State
py:class plumpy.state_machine.State
py:class plumpy.base.state_machine.State
py:class State
py:class Process
py:class plumpy.futures.CancellableAction
py:class plumpy.communications.LoopCommunicator
py:class plumpy.rmq.communications.LoopCommunicator
py:class plumpy.persistence.PersistedPickle
py:class plumpy.utils.AttributesFrozendict
py:class plumpy.workchains._FunctionCall
Expand Down
6 changes: 3 additions & 3 deletions docs/source/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"The {py:class}`~plumpy.workchains.WorkChain`\n",
": A subclass of `Process` that allows for running a process as a set of discrete steps (also known as instructions), with the ability to save the state of the process after each instruction has completed.\n",
"\n",
"The process `Controller` (principally the {py:class}`~plumpy.process_comms.RemoteProcessThreadController`)\n",
"The process `Controller` (principally the {py:class}`~plumpy.rmq.process_control.RemoteProcessThreadController`)\n",
": To control the process or workchain throughout its lifetime."
]
},
Expand Down Expand Up @@ -281,7 +281,7 @@
" def continue_fn(self):\n",
" print('continuing')\n",
" # message is stored in the process status\n",
" return plumpy.Kill(plumpy.MessageBuilder.kill('I was killed'))\n",
" return plumpy.Kill(plumpy.MsgKill.new('I was killed'))\n",
"\n",
"\n",
"process = ContinueProcess()\n",
Expand Down Expand Up @@ -1118,7 +1118,7 @@
"\n",
"process = SimpleProcess(communicator=communicator)\n",
"\n",
"pprint(communicator.rpc_send(str(process.pid), plumpy.MessageBuilder.status()).result())"
"pprint(communicator.rpc_send(str(process.pid), plumpy.MsgStatus.new()).result())"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
'kiwipy[rmq]~=0.8.5',
'nest_asyncio~=1.5,>=1.5.1',
'pyyaml~=6.0',
'typing-extensions~=4.12'
]

[project.urls]
Expand All @@ -57,8 +58,8 @@ pre-commit = [
]
tests = [
'ipykernel==6.12.1',
'pytest~=7.0',
'pytest-asyncio~=0.12,<0.17',
'pytest~=8.0',
'pytest-asyncio~=0.25',
'pytest-cov~=4.1',
'pytest-notebook>=0.8.0',
'shortuuid==1.0.8',
Expand Down Expand Up @@ -162,6 +163,7 @@ testpaths = [
'test',
]
filterwarnings = []
asyncio_default_fixture_loop_scope = "function"

[tool.yapf]
align_closing_bracket_with_visual_indent = true
Expand Down
162 changes: 133 additions & 29 deletions src/plumpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,143 @@
# -*- coding: utf-8 -*-
# mypy: disable-error-code=name-defined
__version__ = '0.24.0'

import logging

from .communications import *
from .events import *
from .exceptions import *
from .futures import *
from .loaders import *
from .mixins import *
from .persistence import *
from .ports import *
from .process_comms import *
from .process_listener import *
from .process_states import *
from .processes import *
from .utils import *
from .workchains import *
from .base.state_machine import TransitionFailed

# interfaces
from .controller import ProcessController
from .coordinator import Coordinator
from .events import (
PlumpyEventLoopPolicy,
get_event_loop,
new_event_loop,
reset_event_loop_policy,
run_until_complete,
set_event_loop,
set_event_loop_policy,
)
from .exceptions import (
ClosedError,
CoordinatorConnectionError,
CoordinatorTimeoutError,
InvalidStateError,
KilledError,
PersistenceError,
UnsuccessfulResult,
)
from .futures import CancellableAction, Future, capture_exceptions
from .loaders import DefaultObjectLoader, ObjectLoader, get_object_loader, set_object_loader
from .message import MsgContinue, MsgCreate, MsgKill, MsgLaunch, MsgPause, MsgPlay, MsgStatus, ProcessLauncher
from .persistence import (
Bundle,
InMemoryPersister,
LoadSaveContext,
PersistedCheckpoint,
Persister,
PicklePersister,
Savable,
SavableFuture,
auto_persist,
)
from .ports import UNSPECIFIED, InputPort, OutputPort, Port, PortNamespace, PortValidationError
from .process_listener import ProcessListener
from .process_spec import ProcessSpec
from .process_states import (
Continue,
Created,
Excepted,
Finished,
Interruption,
Kill,
Killed,
KillInterruption,
PauseInterruption,
ProcessState,
Running,
Stop,
Wait,
Waiting,
)
from .processes import BundleKeys, Process
from .utils import AttributesDict
from .workchains import ToContext, WorkChain, WorkChainSpec, if_, return_, while_

__all__ = (
events.__all__
+ exceptions.__all__
+ processes.__all__
+ utils.__all__
+ futures.__all__
+ mixins.__all__
+ persistence.__all__
+ communications.__all__
+ process_comms.__all__
+ process_listener.__all__
+ workchains.__all__
+ loaders.__all__
+ ports.__all__
+ process_states.__all__
'UNSPECIFIED',
'AttributesDict',
'Bundle',
'BundleKeys',
'CancellableAction',
'ClosedError',
'Continue',
'Coordinator',
'CoordinatorConnectionError',
'CoordinatorTimeoutError',
'Created',
'DefaultObjectLoader',
'Excepted',
'Finished',
'Future',
'InMemoryPersister',
'InputPort',
'Interruption',
'InvalidStateError',
'Kill',
'KillInterruption',
'Killed',
'KilledError',
'LoadSaveContext',
'MsgContinue',
'MsgCreate',
'MsgKill',
'MsgLaunch',
'MsgPause',
'MsgPlay',
'MsgStatus',
'ObjectLoader',
'OutputPort',
'PauseInterruption',
'PersistedCheckpoint',
'PersistenceError',
'Persister',
'PicklePersister',
'PlumpyEventLoopPolicy',
'Port',
'PortNamespace',
'PortValidationError',
'Process',
'ProcessController',
'ProcessLauncher',
'ProcessListener',
'ProcessSpec',
'ProcessState',
'Running',
'Savable',
'SavableFuture',
'Stop',
'ToContext',
'TransitionFailed',
'UnsuccessfulResult',
'Wait',
'Waiting',
'WorkChain',
'WorkChainSpec',
'auto_persist',
'capture_exceptions',
'create_continue_body',
'create_launch_body',
'get_event_loop',
'get_object_loader',
'if_',
'new_event_loop',
'reset_event_loop_policy',
'return_',
'run_until_complete',
'set_event_loop',
'set_event_loop_policy',
'set_object_loader',
'while_',
)


Expand Down
Loading