Actions
StartAction¶
description: Section to trigger an action instance. Comes with an abstract method start_action that should be implemented in the extended classes to provides the logic to trigger
an action.
Using start_action in normalize methods:
Implementing start_action method alone will not trigger the action. How and when
it should be triggered needs to be defined in the normalize method of the child
section.
Here's an example that uses trigger_start_action quantity to trigger the action
when the quantity is set to True:
from nomad_analysis.actions.schema import StartAction
class MyExtendedStartAction(StartAction):
def start_action(self, archive, logger) -> str:
# Implement the logic to prepare the input for an action and start it.
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'):
super().normalize(archive, logger)
if self.trigger_start_action:
try:
self.action_instance_id = self.start_action(archive, logger)
except Exception:
logger.warning('Failed to start the action.', exc_info=True)
finally:
self.trigger_start_action = False
inherits from: nomad.datamodel.data.ArchiveSection
properties:
| name | type | |
|---|---|---|
| action_instance_id | str |
Instance ID of the action started. |
| trigger_start_action | bool |
Starts the action defined under start_action method.default=False |
StopAction¶
description: Section to stop a running action instance. Comes with a method stop_action that takes in action instance ID and schedules a cancellation of the action.
Using stop_action in normalize methods:
How and when the stop_action method is triggered needs to be defined in the
normalize method of child sections.
Here's an example that uses trigger_stop_action quantity to trigger the action:
from nomad_analysis.actions.schema import StopAction
class MyExtendedStopAction(..., StopAction):
# Assuming quantity `action_instance_id` is already a property of the section.
# Can be defined in the section or inherited from the parent section.
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'):
super().normalize(archive, logger)
# Other normalization code...
if self.trigger_stop_action:
self.stop_action(self.action_instance_id, archive, logger)
inherits from: nomad.datamodel.data.ArchiveSection
properties:
| name | type | |
|---|---|---|
| trigger_stop_action | bool |
Schedule cancellation of an actiondefault=False |
ActionStatus¶
description: Section to save and fetch the status of an action instance. Comes with a method get_action_status that takes in action instance ID and gets the status.
The action_status field can have the following values:
| Status | Description |
|---|---|
RUNNING |
Action is currently executing |
COMPLETED |
Action finished successfully |
FAILED |
Action encountered an error |
CANCELLED |
Action was stopped by user |
TERMINATED |
Action was terminated by system or admin |
Using get_action_status in normalize methods:
How and when the get_action_status method is triggered needs to be defined in the
normalize method of child sections.
Here's an example that uses trigger_get_action_status quantity to trigger the
action status retrieval:
Example usage:
from nomad_analysis.actions.schema import ActionStatus
class MySection(..., ActionStatus):
# Assuming quantity `action_instance_id` is already a property of the section.
# Can be defined in the section or inherited from the parent section.
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'):
super().normalize(archive, logger)
# Other normalization code...
if self.trigger_get_action_status:
self.get_action_status(self.action_instance_id, archive, logger)
inherits from: nomad.datamodel.data.ArchiveSection
properties:
| name | type | |
|---|---|---|
| action_status | ['CANCELLED', 'COMPLETED', 'FAILED', 'RUNNING', 'TERMINATED'] |
Status of an action instance. Can be one of the following: The action_status field can have the following values: |
| trigger_get_action_status | bool |
Retrieves the status of an action.default=False |
Action¶
description: Section for running NOMAD Actions.
inherits from: ActionStatus, StopAction, StartAction
normalization:
Handles the behavior of the trigger buttons:
-
If
trigger_start_actionis set to True, it calls thestart_actionmethod to execute the action and setstrigger_get_action_statusto True to retrieve the action status. -
If
trigger_stop_actionis set to True, it calls thestop_actionmethod to stop the action and setstrigger_get_action_statusto True to update the action status. -
If
trigger_get_action_statusis set to True, it calls theget_action_statusmethod to update theaction_status.
The start_action method should be implemented by subclasses.
It should prepare the input for the specific action and trigger it using the
nomad.actions.manager.start_action method. The start_action method should
return the same instance ID of the triggered as returned by the
nomad.actions.manager.start_action method.