Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ changelog:
- title: Major Changes 🛠
labels:
- major

- title: New Features 🎉
labels:
- enhancement
- style

- title: Bugfixes 🐛
labels:
- bug

- title: Documentation 📖
labels:
- documentation

- title: Maintenance 🔧
labels:
        - "*"
- "*"
15 changes: 10 additions & 5 deletions Murray/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ def select_treatments(similarity_matrix, treatment_size, excluded_locations):
max_combinations = comb(n, r)

n_combinations = max_combinations
if n_combinations > 5000:
n_combinations = 5000
# if n_combinations > 5000:
# n_combinations = 5000
if n_combinations > 2000:
n_combinations = 2000

logger.debug(f"Generating {n_combinations} combinations")

Expand Down Expand Up @@ -515,7 +517,8 @@ def select_treatments_exclusive(

# Smart candidate limit based on problem size
available_ratio = n / len(similarity_matrix.columns)
base_candidates = min(5000, max_combinations)
# base_candidates = min(5000, max_combinations)
base_candidates = min(2000, max_combinations)

if available_ratio < 0.3: # Many locations excluded, need more candidates
max_candidates = min(base_candidates * 2, max_combinations)
Expand Down Expand Up @@ -815,8 +818,10 @@ def BetterGroups(
"""
unique_locations = data["location"].unique()
no_locations = len(unique_locations)
max_group_size = round(no_locations * 0.45)
min_elements_in_treatment = round(no_locations * 0.15)
max_group_size = round(no_locations * 0.35)
min_elements_in_treatment = round(no_locations * 0.20)
# max_group_size = round(no_locations * 0.45)
# min_elements_in_treatment = round(no_locations * 0.15)
min_holdout = 100 - (maximum_treatment_percentage * 100)
total_Y = data["Y"].sum()

Expand Down
48 changes: 28 additions & 20 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ async def analyze_design(
httpx.post(webhook_dict["url"], json={
"status": "pending",
"task_id": task.id,
"message": "Task queued for processing",
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"results": {
"message": "Task queued for processing"
}
})
except Exception as ex:
logger.error(f"[{task.id}] Error sending pending webhook: {str(ex)}")
Expand Down Expand Up @@ -298,8 +300,10 @@ async def analyze_evaluation(
httpx.post(webhook_dict["url"], json={
"status": "pending",
"task_id": task.id,
"message": "Task queued for processing",
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"results": {
"message": "Task queued for processing"
}
})
except Exception as ex:
logger.error(f"[{task.id}] Error sending pending webhook: {str(ex)}")
Expand All @@ -317,8 +321,20 @@ async def get_task_status(task_id: str):
Get the status and results of a task
"""
task_result = AsyncResult(task_id, app=celery_app)

if task_result.ready():

# Check for revoked state first (revoked tasks might not be "ready")
if task_result.state == "REVOKED":
return TaskResponse(
task_id=task_id,
status="REVOKED",
results={
"message": "Task was cancelled/revoked",
"details": "The task was cancelled by user request or system intervention",
"cancelled_at": datetime.now().isoformat(),
"final_status": "cancelled"
}
)
elif task_result.ready():
if task_result.successful():
results = convert_ndarrays(task_result.result)
# results = truncate_large_lists(results)
Expand All @@ -333,17 +349,6 @@ async def get_task_status(task_id: str):
status="FAILURE",
results={"error": str(task_result.result)}
)
elif task_result.revoked():
return TaskResponse(
task_id=task_id,
status="REVOKED",
results={
"message": "Task was cancelled/revoked",
"details": "The task was cancelled by user request or system intervention",
"cancelled_at": datetime.now().isoformat(),
"final_status": "cancelled"
}
)
elif task_result.state == "RETRY":
return TaskResponse(
task_id=task_id,
Expand Down Expand Up @@ -520,9 +525,12 @@ async def cancel_task(task_id: str):
response = httpx.post(webhook_url, json={
"status": "cancelled",
"task_id": task_id,
"message": "Task was cancelled by user request",
"progress": current_progress,
"progress_percentage": int(current_progress * 100),
"results": {
"message": "Task was cancelled/revoked",
"details": "The task was cancelled by user request or system intervention",
"cancelled_at": datetime.now().isoformat(),
"final_status": "cancelled"
},
"timestamp": datetime.now().isoformat()
})
logger.info(f"[{task_id}] Cancellation webhook sent to {webhook_url}")
Expand Down
51 changes: 36 additions & 15 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ def analyze_design_task(
httpx.post(webhook["url"], json={
"status": "started",
"task_id": task_id,
"message": f"Design analysis task started ({analysis_mode} mode)",
"analysis_mode": analysis_mode,
"multicell_config": multicell_config,
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"results": {
"message": f"Design analysis task started ({analysis_mode} mode)",
"analysis_mode": analysis_mode,
"multicell_config": multicell_config,
"task_type": "design"
}
})
except Exception as e:
logger.error(f"[{task_id}] Error sending start webhook: {str(e)}")
Expand Down Expand Up @@ -304,7 +307,10 @@ def advance_to_sensitivity():
"status": "completed",
"task_id": task_id,
"timestamp": datetime.now().isoformat(),
"result": final_results
"results": {
"message": "Task completed successfully",
"analysis_data": final_results
}
})
except Exception as e:
logger.error(f"[{task_id}] Error sending traditional success webhook: {str(e)}")
Expand All @@ -321,7 +327,10 @@ def advance_to_sensitivity():
"status": "failed",
"task_id": task_id,
"timestamp": datetime.now().isoformat(),
"error": str(e)
"results": {
"message": "Task failed with error",
"error": str(e)
}
})
except Exception as webhook_error:
logger.error(f"[{task_id}] Error sending traditional failure webhook: {str(webhook_error)}")
Expand Down Expand Up @@ -366,8 +375,11 @@ def analyze_evaluation_task(
httpx.post(webhook["url"], json={
"status": "started",
"task_id": task_id,
"message": "Evaluation analysis task started",
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"results": {
"message": "Evaluation analysis task started",
"task_type": "evaluation"
}
})
except Exception as e:
logger.error(f"[{task_id}] Error sending start webhook: {str(e)}")
Expand Down Expand Up @@ -454,8 +466,11 @@ def analyze_evaluation_task(
httpx.post(webhook["url"], json={
"status": "completed",
"task_id": task_id,
"result": serializable_results,
"timestamp": datetime.now().isoformat()
"timestamp": datetime.now().isoformat(),
"results": {
"message": "Task completed successfully",
"analysis_data": serializable_results
}
})
except Exception as e:
logger.error(f"[{task_id}] Error sending traditional success webhook: {str(e)}")
Expand All @@ -472,7 +487,10 @@ def analyze_evaluation_task(
"status": "failed",
"task_id": task_id,
"timestamp": datetime.now().isoformat(),
"error": str(e)
"results": {
"message": "Task failed with error",
"error": str(e)
}
})
except Exception as webhook_error:
logger.error(f"[{task_id}] Error sending traditional failure webhook: {str(webhook_error)}")
Expand Down Expand Up @@ -1166,10 +1184,13 @@ def task_revoked_handler(sender=None, task_id=None, reason=None, **kwargs):
response = httpx.post(webhook_url, json={
"status": "cancelled",
"task_id": task_id,
"message": f"Task was revoked. Reason: {reason or 'Unknown'}",
"progress": current_progress,
"progress_percentage": int(current_progress * 100),
"reason": reason,
"results": {
"message": "Task was cancelled/revoked",
"details": f"The task was revoked. Reason: {reason or 'Unknown'}",
"cancelled_at": datetime.now().isoformat(),
"final_status": "cancelled",
"revocation_reason": reason
},
"timestamp": datetime.now().isoformat()
})
logger.info(f"[{task_id}] Revocation webhook sent to {webhook_url}")
Expand Down
Loading