fix: prevent undefined port variable errors in measurement scripts (fixes #345)#401
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #345 by adding fallback definitions for port variables in measurement benchmark scripts (A.py, B.py, C.py) that were previously expected to be injected by copy_with_port_portname.py during study generation. The solution prevents NameError when scripts are executed directly while preserving backward compatibility with the injection mechanism.
Changes:
- Added globals() checks with safe fallback defaults for undefined port variables in all three measurement scripts
- Updated readme.md to document the port variable injection dependency and recommended workflow
- Maintained backward compatibility - injected values take precedence over fallbacks when present
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| measurements/A.py | Added fallback definitions for PORT_NAME_F1_F2 and PORT_F1_F2 with defaults "F1_F2" and "5555" |
| measurements/B.py | Added fallback definitions for all four port variables (F1_F2 and F2_F3 pairs) with appropriate defaults |
| measurements/C.py | Added fallback definitions for PORT_NAME_F2_F3 and PORT_F2_F3 with defaults "F2_F3" and "5556" |
| measurements/readme.md | Added section documenting port variable injection dependency and proper execution workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Can you check why irrelevant lines are also changed? Is it the EoL character / linebreak? For example, README.md just has some text added to the end. However, the PR shows it as the entire file being replaced. Can you please recreate the PR with minimal line changes? Keeping changes minimal will help with maintaining the code better (for example, on proper use of git blame). |
… variable definitions (fixes ControlCore-Project#345)
3b1d635 to
ec5690a
Compare
Hi @pradeeban Sir thank you for the feedback
|
Reworded the explanation for network communication measurements to enhance clarity and conciseness.
Hello pradeeban Sir,
Fixes #345.
Some measurement benchmark scripts (
A.py,B.py,C.py) were referencing port variables such asPORT_NAME_F1_F2,PORT_F1_F2,PORT_NAME_F2_F3, andPORT_F2_F3. These variables are normally inserted bycopy_with_port_portname.pywhen a study is generated. However, if the scripts are run directly, those variables are not defined and the scripts crash withNameError.This PR adds simple fallback definitions so the scripts can still run in standalone mode.
Changes made:
measurements/A.py- added fallback forPORT_NAME_F1_F2andPORT_F1_F2measurements/B.py- added fallback for all four port variablesmeasurements/C.py- added fallback forPORT_NAME_F2_F3andPORT_F2_F3measurements/readme.md– added a note explaining that these variables are normally injected during study generationEach script now checks if the variables already exist in
globals(). If not, it assigns safe defaults such as"F1_F2","5555","F2_F3", and"5556". A warning message is also printed so users know the script is running in standalone mode.The fallback block is placed after the imports. When
copy_with_port_portname.pygenerates a study, it inserts the real variable definitions before this block, so the injected values take priority and the fallback is skipped.Result:
NameErrorwhen run directlyScope:
measurements/A.py,B.py,C.py)measurements/readme.mdconcore-litecopy_with_port_portname.py)Testing done locally:
NameErrorand prints a warning