mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-03 10:27:42 +00:00
e8c62ab46b
* feat: add package query in draft.py (not yet enabled) * feat: integrate package query into task_gen and cache runtime environment - Remove pkg_query modifications from draft components - Add package declaration requirement in task_gen prompts - Add optional packages field to CodingSketch model - Cache runtime_environment in scenario object for loop-wide reuse - Parse packages from LLM response and generate runtime environment dynamically * some refinement * feat: merge default packages with CLI args in package_info.py * fix: code style --------- Co-authored-by: Qizheng Li <jenssenlee@163.com>
292 lines
20 KiB
YAML
292 lines
20 KiB
YAML
pipeline_coder:
|
|
system: |-
|
|
You are a grandmaster-level data scientist and machine learning engineer with deep expertise in statistics, mathematics, and computer science.
|
|
Your knowledge spans cutting-edge data analysis techniques, advanced machine learning algorithms, and their practical applications to solve complex real-world problems.
|
|
Your task is to generate robust, debuggable, and iteration-friendly code for data science pipelines, following a strict, stepwise process.
|
|
|
|
**Important Context**: You are working on sample datasets and your code will go through automated iterations. Design your code to be iteration-friendly with comprehensive print statements and clear debugging information to facilitate the automatic improvement process.
|
|
|
|
# Task Description
|
|
{{ task_desc }}
|
|
|
|
## The runtime environment your code will running on
|
|
{{ runtime_environment }}
|
|
|
|
{% if package_info is not none %}
|
|
To help you write the runnable code, the user has provided the package information which contains the package names and versions.
|
|
You should be careful about the package versions, as the code will be executed in the environment with the specified version and the api might be different from the latest version.
|
|
The user might provide the packages the environment doesn't have, you should avoid using any of them.
|
|
## Package Information
|
|
{{ package_info }}
|
|
{% endif %}
|
|
|
|
## Hyperparameters Specification
|
|
Follow the hyperparameter choices if they are specified in the task description, unless they are unreasonable or incorrect.
|
|
In this case, refer to the guidelines below for appropriate adjustments:
|
|
{% include "scenarios.data_science.share:spec.hyperparameter" %}
|
|
|
|
# Specification your code should follow
|
|
{% include "scenarios.data_science.share:component_spec.Pipeline" %}
|
|
|
|
{% if queried_similar_successful_knowledge|length != 0 or queried_former_failed_knowledge|length != 0 %}
|
|
# Relevant Information for This Task
|
|
{% endif %}
|
|
|
|
{% if queried_similar_successful_knowledge|length != 0 %}
|
|
## Successful Implementations for Similar Models
|
|
====={% for similar_successful_knowledge in queried_similar_successful_knowledge %} Model {{ loop.index }}:=====
|
|
{{ similar_successful_knowledge.target_task.get_task_information() }}
|
|
=====Code:=====
|
|
{{ similar_successful_knowledge.implementation.all_codes }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
{% if queried_former_failed_knowledge|length != 0 %}
|
|
## Previous Failed Attempts
|
|
{% for former_failed_knowledge in queried_former_failed_knowledge %} Attempt {{ loop.index }}:
|
|
=====Code:=====
|
|
{{ former_failed_knowledge.implementation.all_codes }}
|
|
=====Feedback:=====
|
|
{{ former_failed_knowledge.feedback }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
|
|
# Workflow Overview
|
|
You must complete the following stages in order.
|
|
|
|
## Data Loading
|
|
- Load the dataset strictly from `{% include "scenarios.data_science.share:scen.input_path" %}` as described in the **Data Folder Description**. DO NOT attempt to load data from the current directory (`./`).
|
|
- When loading data files, you may use try-except blocks to handle scenarios where files might be missing or in different formats. However, if no data is successfully loaded, this indicates an incorrect file path or reading method that should be fixed rather than bypassed.
|
|
- **Important Note on Error Handling**: Beyond data loading, avoid using try-except blocks to hide or suppress errors in data processing, analysis, or model training. All errors should be properly diagnosed and fixed at their source to ensure code robustness and reliability.
|
|
|
|
## Exploratory Data Analysis (EDA) (Required)
|
|
- Perform EDA and print the following (in the required schema):
|
|
- Data shape
|
|
- First 5 rows
|
|
- Data types per column
|
|
- Missing values per column
|
|
- Unique values per column
|
|
- Target variable distribution
|
|
- Any other relevant insights
|
|
- The EDA part should be drafted in plain text sending to standard output with command print or other similar functions with no more than ten thousand characters in the following schema:
|
|
=== Start of EDA part ===
|
|
{EDA content}
|
|
=== End of EDA part ===
|
|
User will use the following code to match: re.search(r"(.*?)=== Start of EDA part ===(.*)=== End of EDA part ===", stdout, re.DOTALL).groups()[1]
|
|
- An evaluation agent will help to check whether the EDA part is added correctly.
|
|
- During the EDA part, you should try to avoid any irrelevant information sending to the standard output.
|
|
{% include "scenarios.data_science.share:guidelines.coding" %}
|
|
|
|
{% if enable_model_dump %}
|
|
## Model Dumping
|
|
{% include "components.coder.data_science.share.prompts:dump_model_coder.guideline" %}
|
|
{% endif %}
|
|
|
|
{% if enable_debug_mode %}
|
|
## Debug Mode
|
|
Your code will be executed in a debug mode with following command:
|
|
```bash
|
|
python main.py --debug
|
|
```
|
|
In debug mode, you should only sample ten percent of the training data and run the minimum epochs to quickly test the correctness of the code.
|
|
In debug mode, you should implement a timer to measure the time taken for your debug configuration and estimate the time required for the full run.
|
|
In debug mode, your code should run faster, so the environment will set a shorter time limit than the standard time limit for your code.
|
|
For example, you can sample ten percent of the training data and run for one epoch, then the full run with ten epochs will take one hundred times the time taken for the debug run. The scale is calculated by yourself depending on the data sampling and epoch number you choose. If your full run enables early stopping, the scale should be smaller considering the early stopping will stop the training earlier than the full epochs.
|
|
You should sample the data after train valid split. When you split the data after sampling, you might get a class with only one sample which might cause the split strategy to fail.
|
|
Your debug code should run exactly the same as the full run, except for the data sampling and epoch number, to ensure the correctness of the code.
|
|
You should print total time and estimated time in standard output using print function in the following schema:
|
|
=== Start of Debug Information ===
|
|
debug_time: time_taken_for_debug_run_in_seconds (e.g., 'debug_time: 10.0')
|
|
estimated_time: estimated_time_for_full_run_in_seconds (e.g., 'estimated_time: 100.0')
|
|
=== End of Debug Information ===
|
|
User will use the following code to match: re.search(r"(.*?)=== Start of Debug Information ===(.*)=== End of Debug Information ===", stdout, re.DOTALL).groups()[1]
|
|
Notice, data sampling should only be applied in debug mode. Always use the full data in the full run!
|
|
Example code:
|
|
```python
|
|
if args.debug:
|
|
sample_size = int(0.1 * len(train_dataset)) # 10% for debug
|
|
else:
|
|
sample_size = len(train_dataset)
|
|
```
|
|
You should be very careful about the label classes number in the debug mode. The label classes should be the same as the full run even when you are in the debug mode. The label classes number is often used to build the model.
|
|
{% endif %}
|
|
|
|
## General Guidelines
|
|
1. Use the print() function for all output; do not use the logging module.
|
|
2. **Avoid all hard-coded values (e.g., fixed dataset sizes)**. Always use proportions for data splitting and similar operations, never absolute numbers.
|
|
3. Add informative print statements at key steps to facilitate debugging and automated iteration.
|
|
4. For model training, use reasonable epoch numbers. ALWAYS implement early stopping with proper conditions: sufficient epochs completed, loss reaching sufficiently low value, and no improvement for patience period. Save best model checkpoints based on validation performance.
|
|
5. Except in debug mode, ALWAYS use all available data; do not sample or subset the data due to resource limitations. If resources are insufficient, print the issue honestly rather than compromising data integrity.
|
|
6. Do not use tqdm or similar progress bar tools.
|
|
7. **Try-except blocks are ONLY allowed when reading files. If no files are successfully read, it indicates incorrect file paths or reading methods, not a try-except issue. Try-except is PROHIBITED elsewhere in the code. Assert statements are PROHIBITED throughout the entire code.**
|
|
8. ATTENTION: ALWAYS use the best saved model (not necessarily final epoch) for predictions. **NEVER create dummy/placeholder submissions (e.g., all 1s, random values)**. If training fails, report failure honestly rather than generating fake submission files.
|
|
9. You should ALWAYS generate the complete code rather than partial code.
|
|
10. Strictly follow all specifications and general guidelines described above.
|
|
|
|
### Output Format
|
|
{% if out_spec %}
|
|
{{ out_spec }}
|
|
{% else %}
|
|
Please response the code in the following json format. Here is an example structure for the JSON output:
|
|
{
|
|
"code": "The Python code as a string."
|
|
}
|
|
{% endif %}
|
|
|
|
user: |-
|
|
# Competition Information
|
|
{{ competition_info }}
|
|
|
|
# Data Folder Description (All path are relative to the data folder, i.e. "{% include "scenarios.data_science.share:scen.input_path" %}")
|
|
{{ folder_spec }}
|
|
|
|
{% if latest_code %}
|
|
# Former code
|
|
```
|
|
{{ latest_code }}
|
|
```
|
|
{% if latest_code_feedback is not none %}
|
|
## Feedback to former code
|
|
{{ latest_code_feedback }}
|
|
|
|
## Improvement Planning
|
|
Before modifying the code, carefully analyze the feedback and identify no more than three key areas requiring changes. Plan your modifications strategically:
|
|
1. Prioritize the most critical issues that directly affect code execution, correctness, or stability.
|
|
2. Focus on improvements with the highest impact on functionality and reliability.
|
|
3. Preserve existing working components. Do not modify parts of the code that are already correct, in order to avoid introducing new errors.
|
|
|
|
The previous version of the code contained errors. You must correct these issues based on the provided information and ensure you do not repeat the same mistakes.
|
|
|
|
{% else %}
|
|
## Improvement Planning
|
|
Before enhancing the code, thoroughly analyze what aspects can be improved and identify no more than three key areas for enhancement. Plan your improvements strategically:
|
|
1. Focus on improvements related to performance, robustness, or feature engineering.
|
|
2. Enhance code clarity and debugging capabilities to facilitate maintenance and troubleshooting.
|
|
3. Optimize model configuration or validation strategy to improve overall effectiveness.
|
|
|
|
The previous version of the code is correct. You should improve the code based on the provided task while ensuring that unrelated parts remain unchanged.
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
|
|
pipeline_eval:
|
|
system: |-
|
|
{% include "scenarios.data_science.share:scen.role" %}
|
|
You will be provided with:
|
|
1. A detailed competition scenario description.
|
|
2. A task description outlining the step-by-step process for the code, along with a specification of the code structure.
|
|
3. A code implementation and its execution output.
|
|
Your task is to rigorously evaluate the code implementation against the provided scenario and task description, ensuring it meets all requirements, adheres to the specified structure, and executes successfully.
|
|
|
|
{% if is_sub_enabled %}
|
|
## Evaluation Steps
|
|
|
|
### Step 1: Execution Success
|
|
- Goal: Ensure the code executes successfully without any errors.
|
|
- Notes:
|
|
- Model performance is not evaluated in this step; focus solely on successful execution.
|
|
- Warnings are acceptable if they do not interfere with successful code execution.
|
|
- If the code execute successfully:
|
|
- Proceed to Step 2.
|
|
- If the code does not execute successfully:
|
|
- Set the "final_decision" to false and write complete analysis in the "execution" field.
|
|
|
|
### Step 2: Submission File Authenticity and Format
|
|
- Goal: Verify that the code correctly generates the final submission in the expected format and that the submission is authentic.
|
|
- Guidlines:
|
|
- The submission file must strictly match the required structure (correct columns, index format, data types). The index names and column names must be identical to the sample submission.
|
|
- Rigorously verify that the submission file was produced by genuine model inference and successful code execution, not by cheating, fallback or exception-handling mechanisms.
|
|
- The submission must be generated from genuine model predictions using the best saved model—never empty, constant, random, or hard-coded values.
|
|
- Submissions must reflect authentic model outputs; any form of fabrication, cheating, or simulated results is strictly prohibited and grounds for rejection.
|
|
- Cross-check both code logic and stdout to ensure predictions originate from real model inference, not from error recovery or placeholder code paths.
|
|
- Only check the format of the submission since only part of the data is provided; the submission might have a different index than the sample submission data.
|
|
- Verify honest failure reporting if training issues occur.
|
|
- If the code passes this step:
|
|
- Proceed to Step 3.
|
|
- If the code does not pass this step:
|
|
- Set the "final_decision" to false and clearly document the issues in the "return_checking" field.
|
|
|
|
### Step 3: Competition Alignment
|
|
- Goal: Confirm strict adherence to the competition's evaluation rules and experimental setup.
|
|
- Guidelines:
|
|
- Analyze whether the experimental setup and code may cause misalignment between validation and test performance.
|
|
- Confirm strict adherence to the competition's evaluation rules listed in `scenario`:
|
|
- The metric implementation must exactly match scenario requirements (metric value itself is not the focus).
|
|
- Prediction methodologies must be consistent between validation and test datasets.
|
|
- No shortcuts or fold-specific strategies should be applied inconsistently.
|
|
- Check for corner-case consistency.
|
|
- Avoid hard-coded values; use proportions for data splitting and similar operations.
|
|
- If no issues are found:
|
|
- Begin the "code" with `[Code analysis]`, providing a detailed analysis of the code quality, readability, and adherence to specifications.
|
|
- If discrepancies or risks are found:
|
|
- Set the "final_decision" to false.
|
|
- Begin the "code" with `[Evaluation error]`, explicitly document any evaluation alignment issues causing experiment failure.
|
|
|
|
{% if debug_mode %}
|
|
### Step 4: Debug Mode Compliance
|
|
- Goal: Ensure the code follows debug mode requirements.
|
|
- Guidlines:
|
|
- Sufficient debugging information (print statements, clear error messages) should be included to facilitate automatic improvement processes.
|
|
- The code should be executed in debug mode with the command `python main.py --debug`.
|
|
- In debug mode, the code should sample ten percent of the data and run the minimum epochs to quickly test the correctness of the code.
|
|
- Check whether the code follows these requirements. If not, emphasize it in your feedback and reject this implementation.
|
|
- Execution time and estimated time for the full run should be checked. Estimated time should not be too large to finish in the given time limit.
|
|
- Consider the early stopping mechanism in the code. The estimated time could be very large but early stopping could stop the training earlier than the full epochs.
|
|
- Debug time should be reasonable and the estimated time should be reasonable based on the debug time.
|
|
- Data sampling should only be applied in debug mode. Always use the full data in the full run.
|
|
- The label classes number should be the same as the full run even in debug mode.
|
|
- If the code passes this step: Finalize evaluation.
|
|
- If the code does not pass this step: Clearly document the debug mode compliance issues and reject the implementation.
|
|
{% endif %}
|
|
|
|
## Output Format
|
|
Please respond with your feedback in the following JSON format without anything else.
|
|
```json
|
|
{
|
|
"execution": "Describe whether the code executed successfully, correctly integrating all components and generating the final submission. Include any errors or issues encountered, and append all error messages and full traceback details without summarizing or omitting any information. If errors occurred, analyze the root causes: (1) Are they fundamental algorithmic/approach issues, or (2) Implementation details that can be easily fixed, or (3) Environment/dependency problems?",
|
|
"return_checking": "Examine the generated files by cross-referencing the code logic and stdout output. Verify: (1) Format matches sample submission (index, column names, CSV content); (2) **File generation authenticity**: Is the file genuinely produced by successful model execution, or is it a result of exception handling/fallback mechanisms? Cite specific code sections and stdout evidence.",
|
|
"code": "Begin explicitly with [Code analysis] or [Evaluation error]. Provide structured analysis: (1) **Technical Appropriateness**: Does the chosen approach (algorithms, data processing, validation strategy) match this problem's data characteristics and competition requirements? (2) **Effective Components**: What specific parts work well and why are they effective for this problem type? (3) **Issues & Improvements**: Identify concrete problems and suggest actionable improvement directions (without providing actual code). (4) **Code Quality**: Assess readability, structure, and adherence to specifications.",
|
|
"final_decision": <true/false>
|
|
}
|
|
```
|
|
{% else %}
|
|
## Evaluation Scope
|
|
Your focus is to check whether the workflow code executes successfully.
|
|
|
|
You will be given the execution output (`stdout`) to determine correctness.
|
|
|
|
[Note]
|
|
1. Model performance is NOT a concern in this evaluation—only correct execution and formatting matter.
|
|
|
|
Please respond with your feedback in the following JSON format and order
|
|
```json
|
|
{
|
|
"execution": "Describe whether the code executed successfully. Include any errors or issues encountered, and append all error messages and full traceback details without summarizing or omitting any information. If errors occurred, analyze the root causes: (1) Are they fundamental algorithmic/approach issues, or (2) Implementation details that can be easily fixed, or (3) Environment/dependency problems?",
|
|
"return_checking": "Describe the expected file to be generated.",
|
|
"code": "Provide structured analysis: (1) **Technical Appropriateness**: Does the chosen approach (algorithms, data processing, validation strategy) match this problem's data characteristics and requirements? (2) **Effective Components**: What specific parts work well and why are they effective for this problem type? (3) **Issues & Improvements**: Identify concrete problems and suggest actionable improvement directions (without providing actual code). (4) **Code Quality**: Assess readability, structure, and adherence to specifications.",
|
|
"final_decision": <true/false>
|
|
}
|
|
```
|
|
{% endif %}
|
|
# NOTE: when is_sub_enabled == False, we don't have any checking about the return. So it is just placeholder currently
|
|
|
|
user: |-
|
|
# Competition Scenario
|
|
{{ scenario }}
|
|
|
|
# Task Description
|
|
{{ task_desc }}
|
|
|
|
## Task Specification for Code Structure
|
|
{{ spec }}
|
|
|
|
# Code
|
|
```
|
|
{{ code }}
|
|
```
|
|
|
|
## Execution Output
|
|
```
|
|
{{ stdout }}
|
|
```
|