-
Notifications
You must be signed in to change notification settings - Fork 63
feat(webapi): batch task submission via dedicated endpoint #2694
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 7 comments
# TODO: Replace with batch delete endpoint when available | ||
# DELETE /tidy3d/projects/{folder_id}/batch/{batch_id} | ||
for task_id in self.task_ids.values(): | ||
http.delete(f"tidy3d/tasks/{task_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Individual task deletion in loop could leave batch in inconsistent state if some deletions fail - consider error handling and rollback strategy
# TODO: Replace with batch submit endpoint when available | ||
# POST /tidy3d/projects/{folder_id}/batch/{batch_id}/submit | ||
for task_id in self.task_ids.values(): | ||
http.post(f"tidy3d/tasks/{task_id}/submit") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Individual task submission in loop could leave batch partially submitted if some fail - consider atomic batch submission or proper error handling
PERMUTATION = "Permutation" | ||
PARALLEL = "Parallel" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Inconsistent naming convention: 'Permutation' and 'Parallel' use title case while others use uppercase. Consider using 'PERMUTATION' and 'PARALLEL' for consistency.
MONTE_CARLO = "MONTE_CARLO" | ||
RF_SWEEP = "RF_SWEEP" | ||
|
||
DEFAULT = "RF_SWEEP" # noqa: PIE796 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The PIE796 noqa comment suppresses a 'prefer using a unique enum value' warning, but having DEFAULT = RF_SWEEP creates an alias that could cause confusion. Consider using a separate method like get_default()
instead.
) | ||
|
||
def batch_request_matcher(request): | ||
import json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Redundant import of json module - already imported at line 4
import json | |
def batch_request_matcher(request): | |
json_data = json.loads(request.body) | |
assert "tasks" in json_data | |
assert "batchType" in json_data | |
assert "groupName" in json_data | |
for task in json_data["tasks"]: | |
assert "groupName" in task | |
assert task["groupName"] == json_data["groupName"] | |
return True, None |
assert job.task_id == f"task_id_{i}" | ||
assert job._cached_properties.get("task_id") == f"task_id_{i}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Accessing _cached_properties
directly may be fragile - consider using a public method if this internal access pattern is common
for task_name, simulation in simulations.items(): | ||
if isinstance(simulation, (ModeSolver, ModeSimulation)): | ||
simulation = get_reduced_simulation(simulation, reduce_simulation) | ||
simulations[task_name] = simulation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Modifying simulations
dict during iteration could cause unexpected behavior. Consider creating a new dict or processing modifications separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 1 comment
|
||
def _create_jobs_from_batch(self) -> dict[TaskName, Job]: | ||
"""Create jobs from batch submission response.""" | ||
batch_id, task_ids = self._submit_batch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The batch_id returned from _submit_batch is not stored or used anywhere, potentially missing functionality for batch tracking
Greptile Summary
This PR introduces a new batch task submission feature that allows submitting multiple simulations via a dedicated server endpoint instead of individual API calls. The implementation adds a new
BatchTask
class and refactors the existing task management system into a cleaner class hierarchy.Key Changes:
upload_batch()
function andBatchTask
class that can create multiple simulation tasks in a single API call via the new/batch-tasks
endpointBaseTask
abstract base class and renamesSimulationTask
toTask
(with backward compatibility alias), establishing a cleaner inheritance structureBatchType
enum with different batch processing types (BATCH, INVDES, PERMUTATION, PARALLEL, MONTE_CARLO, RF_SWEEP) for server-side optimizationBatch
class withuse_batch_endpoint
flag andbatch_type
field, allowing users to opt into the new batch submission methodThe feature maintains full backward compatibility by defaulting
use_batch_endpoint=False
, ensuring existing code continues to work unchanged. The implementation follows established patterns in the codebase with proper validation, error handling, and HTTP communication through existing utilities.Important Files Changed
Click to expand file changes
tidy3d/web/core/task_core.py
tidy3d/web/core/types.py
tidy3d/web/api/container.py
tidy3d/web/api/webapi.py
tests/test_web/test_webapi.py
Confidence score: 4/5
• This PR is generally safe to merge with robust backward compatibility and comprehensive test coverage
• Score reflects some unimplemented server-side functionality and extensive TODO comments indicating ongoing development
• Files need attention:
tidy3d/web/core/task_core.py
for placeholder methods andtidy3d/web/api/container.py
for mixed batch/individual handling patternsSequence Diagram