Skip to content
Draft
Changes from 2 commits
Commits
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
41 changes: 39 additions & 2 deletions src/nsls2ptycho/core/ptycho_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import traceback
import time


import requests
import json

from .databroker_api import load_metadata, save_data
from .utils import use_mpi_machinefile, set_flush_early
from .ptycho.utils import save_config
Expand Down Expand Up @@ -98,7 +102,37 @@ def clear_slurm_header(self):
os.remove(slurm_header)
except:
pass


def submit_job(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this evolves, it's worth keeping an eye on whether this actually needs any instance state (i.e. self.<X>). If not, it could just be a simple function, rather than a method, and that would make it simpler to test.

url = "https://orion-api-staging.nsls2.bnl.gov/api/v1/compute/orion/jobs"
bearer_token = os.getenv("SLURM_JWT")

payload = {
"script": "#!/bin/bash -l\n"
"#SBATCH --job-name=trial\n"
"#SBATCH --time=0-00:10:00\n"
"#SBATCH --nodes=1\n"
"#SBATCH --ntasks-per-node=2\n"
"#SBATCH --error=%x.err\n"
"#SBATCH --output=%x.out\n\n"
"module purge\n"
"module load beamline-aliases\n\n"
"source load-hxn\n\n"
"srun python solve.py",
"environment": ["PATH=/usr/bin:/bin:/usr/sbin:/sbin", "SLURM_EXPORT_ENV=ALL"],
"working_dir_path": "/nsls2/users/skarakuzu1/orion_ptycho"
}

print(payload)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {bearer_token}"
}

response = requests.post(url, headers=headers, json=payload)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a stateful client instance (and httpx) as mentioned in Slack.

print("response is ", response)


def recon_remote(self, param:Param, update_fcn=None):

self.fname_full = os.path.join(self.remote_path,'ptycho_'+str(param.scan_num)+'_'+param.sign)
Expand All @@ -119,6 +153,9 @@ def recon_remote(self, param:Param, update_fcn=None):

self.return_value = 0 # Assume the recon will succeed unless later detects failure and modify it.

print("Submitting job from the gui")
self.submit_job()

# try:
time.sleep(1)
out = self.msg.readlines()
Expand Down Expand Up @@ -157,7 +194,7 @@ def recon_remote(self, param:Param, update_fcn=None):
# pass

def run(self):
print('Ptycho thread started')
print('Ptycho thread started helloooo***')
try:
self.recon_remote(self.param, self.update_signal.emit)
except IndexError:
Expand Down