Skip to content

Add CLI flag to prune network nodes without country_code key - #126

Merged
robgjansen merged 2 commits into
shadow:mainfrom
louisgregg:prune-nodes-without-country-code
Oct 22, 2026
Merged

robgjansen merged 2 commits into
shadow:mainfrom
louisgregg:prune-nodes-without-country-code

Conversation

@louisgregg

Copy link
Copy Markdown
Contributor

Description

A single node in networkinfo_staging.gml graph doesn't contain the country_code key in its dictionary - node 284. Contents of the node dict:

{'ip_address': '185.243.20.232', 'bandwidth_down': '35408 Kibit', 'bandwidth_up': '21936 Kibit'}  

In the rare case that this particular node is then used to construct the network graph for the shadow simulation, I encounter an error in a geographical analysis I'm running on subsequent simulation output. This PR creates a optional flag for the stage subcommand which removes a node from this graph if it doesn't contain a country_code key.

Flag Usage

tornettools stage --help
# ...
#   --remove_nodes_without_country_code
#                        Include only those nodes in the networkinfo_staging.gml network graph that specify a country_code (default: False)

Testing

I smoke tested this on my local simulation / analysis pipeline but I haven't created any unit tests or integration tests, etc.

…info_staging.gml. Does not check for other node keys (yet)
@louisgregg louisgregg changed the title A check to ensure the country_code key exists in all nodes in network… Add CLI flag to prune network nodes lacking country_code Oct 21, 2026
@louisgregg louisgregg changed the title Add CLI flag to prune network nodes lacking country_code Add CLI flag to prune network nodes without country_code key Oct 21, 2026

@robgjansen robgjansen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if the pruning should be done upstream, on the code that generates the input that is passed to the staging command?

If we merge this, I'd ask for some minor changes first.

Comment thread tornettools/stage.py Resolved
Comment thread tornettools/stage.py Resolved
Comment thread tornettools/stage.py Resolved
Comment thread tornettools/stage.py Resolved
@louisgregg

Copy link
Copy Markdown
Contributor Author

I wonder if the pruning should be done upstream, on the code that generates the input that is passed to the staging command?

By default, networkinfo_staging.gml is a nodes-only copy of tmodel-ccs2018.github.io/data/shadow/network/atlas_v201801.shadow_v2.gml.xz . Would you prefer to see this country_code check implemented in the tmodel-ccs2018.github.io repo itself? That's a data-only repo so I don't know where this logic should go there.

tornettools stage is the first step in costructing/running a tornettools simulation so to me, it seemed like an appropriate point to remove the nodes. Let me know if I've misunderstood your suggestion, thanks.

If we merge this, I'd ask for some minor changes first.

Done.

@robgjansen robgjansen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK, this looks good.

Note, I think the upstream scripts are in our atlas repo. And I think the script that outputs the final graph file is here.

I have not inspected the above script to see how it would need to change so that it does not output empty country codes, but I think in any case it makes sense to have a defensive check here so I'm approving this PR.

Thank you for your contribution!

(I will inspect the CI issue before merging.)

@robgjansen
robgjansen merged commit e0b0b12 into shadow:main Oct 22, 2026
4 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.

2 participants