Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 21, 2024
1 parent 15a9d10 commit 7a648fd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
6 changes: 3 additions & 3 deletions control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "2f454b5b",
"id": "0",
"metadata": {},
"source": [
"# AiiDA control"
Expand All @@ -11,7 +11,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "03c3d207",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "56f4a261",
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand Down
69 changes: 45 additions & 24 deletions home/control.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import subprocess
from aiida import engine
import ipywidgets as ipw

import aiidalab_widgets_base as awb
from aiida import orm, manage
import ipywidgets as ipw
import plumpy
import traitlets as tr
from aiida import engine, manage
from IPython.display import clear_output
import subprocess


class DaemonControlWidget(ipw.VBox):
def __init__(self, *args, **kwargs):
Expand All @@ -22,12 +22,20 @@ def __init__(self, *args, **kwargs):
stop_button.on_click(self._stop_daemon)

# Restart daemon.
restart_button = ipw.Button(description="Restart daemon", button_style="warning")
restart_button = ipw.Button(
description="Restart daemon", button_style="warning"
)
restart_button.on_click(self._restart_daemon)

self.info=ipw.HTML()
self.info = ipw.HTML()
self._update_status()
super().__init__(children=[self.info, self._status, ipw.HBox([start_button, stop_button, restart_button])])
super().__init__(
children=[
self.info,
self._status,
ipw.HBox([start_button, stop_button, restart_button]),
]
)

def _restart_daemon(self, _=None):
self._clear_status()
Expand Down Expand Up @@ -56,37 +64,48 @@ def _stop_daemon(self, _=None):
def _update_status(self, _=None):
self._clear_status()
with self._status:
result = subprocess.run(["verdi", "daemon", "status"], capture_output=True, text=True)
result = subprocess.run(
["verdi", "daemon", "status"], capture_output=True, text=True, check=False
)
print(result.stdout, result.stderr)

def _clear_status(self):
with self._status:
clear_output()



class ProcessControlWidget(ipw.VBox):
def __init__(self):
process_list = awb.ProcessListWidget(path_to_root="../../")
past_days_widget = ipw.IntText(value=7, description='Past days:')
tr.link((past_days_widget, 'value'), (process_list, 'past_days'))
past_days_widget = ipw.IntText(value=7, description="Past days:")
tr.link((past_days_widget, "value"), (process_list, "past_days"))

all_days_checkbox = ipw.Checkbox(description="All days", value=True)
tr.dlink((all_days_checkbox, 'value'), (past_days_widget, 'disabled'))
tr.dlink((all_days_checkbox, 'value'), (process_list, 'past_days'), transform=lambda v: -1 if v else past_days_widget.value)
tr.dlink((all_days_checkbox, "value"), (past_days_widget, "disabled"))
tr.dlink(
(all_days_checkbox, "value"),
(process_list, "past_days"),
transform=lambda v: -1 if v else past_days_widget.value,
)

available_states = [state.value for state in plumpy.ProcessState]
process_state_widget = ipw.SelectMultiple(options=available_states,
value=["running", "waiting"],
description='Process State:',
style={'description_width': 'initial'},
disabled=False)
tr.dlink((process_state_widget, 'value'), (process_list, 'process_states'))
process_state_widget = ipw.SelectMultiple(
options=available_states,
value=["running", "waiting"],
description="Process State:",
style={"description_width": "initial"},
disabled=False,
)
tr.dlink((process_state_widget, "value"), (process_list, "process_states"))
process_list.update()


super().__init__(children=[ipw.HBox([past_days_widget, all_days_checkbox]), process_state_widget, process_list])

super().__init__(
children=[
ipw.HBox([past_days_widget, all_days_checkbox]),
process_state_widget,
process_list,
]
)


class GroupControlWidget(ipw.VBox):
Expand All @@ -98,7 +117,9 @@ def __init__(self):
class StatusControlWidget(ipw.HTML):
def __init__(self):
print("AiiDA status")
print(subprocess.run(["verdi", "status"], capture_output=True, text=True).stdout)
print(
subprocess.run(["verdi", "status"], capture_output=True, text=True, check=False).stdout
)
super().__init__()


Expand Down

0 comments on commit 7a648fd

Please sign in to comment.