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

Strictly positive DANDI jobs #506

Merged
merged 9 commits into from
Nov 11, 2023
Merged
24 changes: 22 additions & 2 deletions pyflask/apis/neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,17 @@ class UploadProject(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
return upload_project_to_dandi(**neuroconv_api.payload)
import psutil

upload_options = neuroconv_api.payload
if "number_of_jobs" not in upload_options:
upload_options.update(number_of_jobs=psutil.cpu_count(logical=False))
if "number_of_threads" not in upload_options:
upload_options.update(
number_of_threads=psutil.cpu_count(logical=True) / psutil.cpu_count(logical=False)
)

return upload_project_to_dandi(**upload_options)

except Exception as e:
if notBadRequestException(e):
Expand All @@ -139,7 +149,17 @@ class UploadFolder(Resource):
@neuroconv_api.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"})
def post(self):
try:
return upload_folder_to_dandi(**neuroconv_api.payload)
import psutil

upload_options = neuroconv_api.payload
if "number_of_jobs" not in upload_options:
upload_options.update(number_of_jobs=psutil.cpu_count(logical=False))
if "number_of_threads" not in upload_options:
upload_options.update(
number_of_threads=psutil.cpu_count(logical=True) / psutil.cpu_count(logical=False)
)

return upload_folder_to_dandi(**upload_options)

except Exception as e:
if notBadRequestException(e):
Expand Down
10 changes: 0 additions & 10 deletions schemas/dandi-upload.schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import upload from './json/dandi/upload.json' assert { type: "json" }


upload.properties.number_of_jobs.transform = upload.properties.number_of_threads.transform = (value, prevValue) => {
if (value === 0){
if (prevValue === -1) return 1
else return -1
}

return value
}

export default upload
6 changes: 2 additions & 4 deletions schemas/json/dandi/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
"type": "integer",
"title": "Job Count",
"description": "The number of files to upload in parallel. A value of <code>-1</code> uses all available processes.<br><small><b>Note:</b> If you encounter an error for any selector value, particularly a Segmentation Fault error, try a value of <code>1</code> to run the jobs without parallelization.</small>",
"default": -1,
"min": -1
"min": 1
},
"number_of_threads": {
"type": "integer",
"title": "Threads per Job",
"description": "The number of threads to handle each file. A value of <code>-1</code> uses all available threads per process.",
"default": -1,
"min": -1
"min": 1
},
"cleanup": {
"type": "boolean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export class GuidedUploadPage extends Page {
await fetch(new URL("cpus", baseUrl))
.then((res) => res.json())
.then(({ physical, logical }) => {
dandiUploadSchema.properties.number_of_jobs.max = physical;
dandiUploadSchema.properties.number_of_threads.max = logical / physical;
const { number_of_jobs, number_of_threads } = dandiUploadSchema.properties;
number_of_jobs.max = number_of_jobs.default = physical;
number_of_threads.max = number_of_threads.default = logical / physical;
})
.catch(() => {});

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/src/stories/pages/uploads/UploadsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ export class UploadsPage extends Page {
await fetch(new URL("cpus", baseUrl))
.then((res) => res.json())
.then(({ physical, logical }) => {
dandiSchema.properties.number_of_jobs.max = physical;
dandiSchema.properties.number_of_threads.max = logical / physical;
const { number_of_jobs, number_of_threads } = dandiSchema.properties;
number_of_jobs.max = number_of_jobs.default = physical;
number_of_threads.max = number_of_threads.default = logical / physical;
})
.catch(() => {});

Expand Down
Loading