Skip to content

Fix critical bugs and enhance model coverage in generate_model_size_report.py script#89

Merged
bernalde merged 7 commits intoopenhands-fix-issue-50from
copilot/fix-32b66453-35a3-4ff1-836b-d3c4a3c5fcb5
Aug 6, 2025
Merged

Fix critical bugs and enhance model coverage in generate_model_size_report.py script#89
bernalde merged 7 commits intoopenhands-fix-issue-50from
copilot/fix-32b66453-35a3-4ff1-836b-d3c4a3c5fcb5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 27, 2025

This PR addresses all the issues identified in Copilot's code review of PR #86, fixing several critical bugs in the generate_model_size_report.py script and expanding its coverage to include all models in GDPlib.

Critical Bug Fixes

1. NameError when no models are processed

The script would crash with NameError: name 'combined_df' is not defined when all models failed to process due to missing dependencies or other errors. This was caused by improper indentation where the combined report generation code was outside the else block.

Before:

if not all_reports:
    print("No reports were generated. Skipping combined report generation.")
else:
    combined_df = pd.concat([df for df in all_reports.values()], axis=1)
    # ...

# This code was outside the else block!
combined_report += combined_df.to_markdown()  # NameError when all_reports is empty

After:

if not all_reports:
    print("No reports were generated. Skipping combined report generation.")
else:
    combined_df = pd.concat([df for df in all_reports.values()], axis=1)
    # All combined report generation is now properly inside the else block
    combined_report += combined_df.to_markdown()

2. Duplicate and conflicting error handling

The script had duplicate checks for missing README sections with conflicting behavior - first raising an exception, then handling it gracefully.

3. DataFrame column mutation issue

The same DataFrame object was having its columns modified multiple times, which could lead to unexpected behavior and made the code harder to understand.

Enhanced Model Coverage

All models enabled

Expanded the script to process all 19 models in GDPlib instead of just 2 conservative models, providing comprehensive coverage of the entire library.

Model directory links

Enhanced the generated table to include clickable links to each model directory, improving navigation and documentation quality. Each model name is now formatted as [model_name](./gdplib/model_name/).

Testing Results

The enhanced script now:

  • ✅ Handles cases where all models fail to process without crashing
  • ✅ Successfully processes 17 out of 19 models in the test environment
  • ✅ Generates individual model_size_report.md files for each successful model
  • ✅ Creates a comprehensive combined model size comparison table in README.md with clickable links
  • ✅ Gracefully handles missing dependencies, solver issues, and other model-specific errors
  • ✅ Passes Black code formatting checks

Generated Output

The script now successfully generates a comprehensive model size comparison table showing metrics for all successfully processed models with clickable navigation:

Component biofuel disease_model gdp_col ...
variables 36840 1250 442 ...
binary_variables 516 52 30 ...
... ... ... ... ...

All changes maintain backward compatibility while significantly expanding the script's functionality and robustness.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 27, 2025 20:59
Co-authored-by: bernalde <8647329+bernalde@users.noreply.github.com>
…ck addressed

Co-authored-by: bernalde <8647329+bernalde@users.noreply.github.com>
@bernalde bernalde requested a review from Copilot July 27, 2025 21:01

This comment was marked as outdated.

Copilot AI changed the title [WIP] Take over PR #86 and work on it. Fix critical bugs in generate_model_size_report.py script Jul 27, 2025
Copilot AI requested a review from bernalde July 27, 2025 21:02
@bernalde
Copy link
Copy Markdown
Member

Tests are failing. Aim to merge this with main branch. Consider further cvopilot feedback and original goals in #86

Co-authored-by: bernalde <8647329+bernalde@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jul 27, 2025

Tests are failing. Aim to merge this with main branch. Consider further cvopilot feedback and original goals in #86

Fixed the failing tests by applying Black code formatting and made the script compatible with main branch. The script now:

✅ Passes all linting checks
✅ Starts with a conservative model list (jobshop, water_network) similar to main branch
✅ Maintains all functionality while being merge-ready
✅ Automatically detects and creates "Model Size Example" section in README

All original bug fixes from the Copilot feedback are preserved. Ready for merge with main branch.

Commit: 7319f58

@bernalde
Copy link
Copy Markdown
Member

Have the table be generated for all the models.

This comment was marked as outdated.

Copy link
Copy Markdown
Member

@bernalde bernalde left a comment

Choose a reason for hiding this comment

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

Modify the README file to add links to each model as before.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jul 27, 2025

@bernalde Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 46b5e4c9-40bb-41db-94aa-1f3195098f34

Sorry for the inconvenience!

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bernalde
Copy link
Copy Markdown
Member

bernalde commented Aug 4, 2025

@copilot try again

@bernalde
Copy link
Copy Markdown
Member

bernalde commented Aug 5, 2025

…on table

Co-authored-by: bernalde <8647329+bernalde@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 5, 2025

https://gh.io/copilot-coding-agent-docs try again @copilot

I've successfully implemented both requested changes:

  1. Enabled all models: The script now processes all 19 models in the instance list, successfully generating reports for 17 models (2 failed due to missing IPOPT solver)

  2. Added model directory links: Each model name in the table is now a clickable link to its directory, e.g., [biofuel](./gdplib/biofuel/)

The generated table now includes comprehensive size metrics for all successfully processed models with direct links to their respective directories, just like the original "Available Models" section format.

Commit: 39a1da6

Copilot AI changed the title Fix critical bugs in generate_model_size_report.py script Fix critical bugs and enhance model coverage in generate_model_size_report.py script Aug 5, 2025
Copilot AI requested a review from bernalde August 5, 2025 23:49
@bernalde bernalde requested a review from Copilot August 6, 2025 00:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses critical bugs in the generate_model_size_report.py script and significantly expands its functionality to process all GDPlib models. The key fixes include resolving a NameError when no models are processed, eliminating duplicate error handling, and preventing DataFrame mutation issues. The enhancement expands model coverage from 2 to 19 models and adds clickable navigation links to model directories in the generated comparison table.

  • Fix critical NameError bug when all models fail to process by properly organizing code within conditional blocks
  • Expand model coverage to include all 19 models in GDPlib instead of just 2
  • Add clickable directory links to model names in the generated comparison table for improved navigation

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.

File Description
generate_model_size_report.py Fixes critical bugs, expands model coverage, and adds linked headers to comparison table
gdplib/*/model_size_report.md Generated individual model size reports for 16 different models
README.md Updated with comprehensive model size comparison table containing clickable links

"stranded_gas",
"syngas",
"water_network"
"water_network",
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

[nitpick] The trailing comma after 'water_network' is inconsistent with the original code style. Since this is the last item in the list, the comma should be removed to maintain consistency with the previous pattern.

Suggested change
"water_network",
"water_network"

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bernalde bernalde merged commit 6457e4a into openhands-fix-issue-50 Aug 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants