Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Scenarios to improve legibility and workflow management. #315

Merged
merged 20 commits into from
Apr 26, 2023

Conversation

e-lo
Copy link
Collaborator

@e-lo e-lo commented Mar 7, 2023

Resolves issues with Scenario class as discussed in #277 including:

  • removes state variables
  • improves legibility for what is happening

Updated Definitions

  • Scenario.project_cards: Mapping[ProjectCard.name,ProjectCard] Storage of all project cards by name; helps prevent naming conflicts.
  • Scenario._planned_projects: Collection[ProjectCard.name] Initial ordering of project cards which are awaiting to be queued for adding. Similar to a git working directory, project cards aren't recognized in this collection once they are moved to staging
  • Scenario._queued_projects: Collection[ProjectCard.name] Projects which are "shovel ready": have had pre-requistes checked and done any required re-ordering. Similar to a git staging, project cards aren't recognized in this collection once they are moved to applied
  • Scenario.queued_projects: @Property wrapper on _queued_projects which lazily queues (checks requirements/conflicts and orders) anything already in Scenario._queued_projects and anything in Scenario.planned_projects (and removes queued projects from planned_projects)
  • Scenario.applied_projects: Collection[ProjectCard.name] Projects which have been applied to the network.
  • No more "state" variables: requisites_checked and conflicts_checked: as this is the definitional difference between planned and queued
  • Scenario.projects: Sum of applied, queued.

e-lo added 2 commits March 7, 2023 15:46
Changes how scenarios works per description in #277 and updates relevant documentation about API changes.

Also:
- various efficiencies and consistency fixes
@e-lo e-lo added enhancement New feature or request refactor labels Mar 7, 2023
@e-lo e-lo added this to the v1.0 milestone Mar 7, 2023
@e-lo e-lo requested review from lmz and i-am-sijia March 7, 2023 23:55
@e-lo e-lo self-assigned this Mar 7, 2023
So you aren't iterating over a changing list
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 10, 2023

@i-am-sijia or @lmz would love your attention on this next as it will enables some good stuff going on in network-wrangler/projectcard

@e-lo e-lo changed the base branch from master to develop March 13, 2023 14:32
@e-lo
Copy link
Collaborator Author

e-lo commented Mar 16, 2023

@lmz see updated documentation to review!

Copy link
Member

@i-am-sijia i-am-sijia left a comment

Choose a reason for hiding this comment

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

  1. Ran the scenario creation notebook and tests\test_scenario.py, both are currently failing due to bugs in scenario.py
  2. Link and Node foreign keys has upper case variables, but the project card reading step is converting everything in project cards into lower case. This is causing most of the tests to fail.

network_wrangler/projectcard.py Outdated Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
notebook/Scenario Building Example.ipynb Outdated Show resolved Hide resolved
network_wrangler/scenario.py Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
network_wrangler/scenario.py Show resolved Hide resolved
network_wrangler/scenario.py Outdated Show resolved Hide resolved
e-lo and others added 11 commits March 21, 2023 14:53
Also:
- Better document Scenario.__init__ arguments
- Require minimum variables in base_scenario: applied_projects and conflicts
- is_disjoint is actually isdisjoint (doh!) and performed on a set object
- mapping objects converted to lists (doh!)
- `planned_proejects` should actually be `_planned _projects`
- _queued_projects should be truthiness-checked, not ever none
also:
- fixed a lot of API usage
- added specific Exception types for better error catching in testing
- black
@lmz
Copy link
Collaborator

lmz commented Mar 30, 2023

I was trying to take a look at this by running notebook\Scenario Building Example.ipynb and I'm getting errors when reading the project cards which I'm finding difficult to interpret:

2023-03-30 13:26:54, INFO: Creating Scenario
2023-03-30 13:26:54, WARNING: Base_scenario doesn't contain ['road_net', 'transit_net', 'applied_projects', 'conflicts']
2023-03-30 13:26:54, DEBUG: Finding project cards using glob search: *attribute*.yml in [e:\GitHub\network_wrangler_wsp-sag\examples\stpaul\project_cards](file:///E:/GitHub/network_wrangler_wsp-sag/examples/stpaul/project_cards)
2023-03-30 13:26:54, DEBUG: Reading YAML-Style Project Card [e:\GitHub\network_wrangler_wsp-sag\examples\stpaul\project_cards\1_simple_roadway_attribute_change.yml](file:///E:/GitHub/network_wrangler_wsp-sag/examples/stpaul/project_cards/1_simple_roadway_attribute_change.yml)
2023-03-30 13:26:54, ERROR: Failed Project Card validation: Validation Error
   Project Card File Loc:[e:\GitHub\network_wrangler_wsp-sag\examples\stpaul\project_cards\1_simple_roadway_attribute_change.yml](file:///E:/GitHub/network_wrangler_wsp-sag/examples/stpaul/project_cards/1_simple_roadway_attribute_change.yml)
   Project Card Schema Loc:[E:\GitHub\network_wrangler_wsp-sag\network_wrangler\schemas\project_card.json](file:///E:/GitHub/network_wrangler_wsp-sag/network_wrangler/schemas/project_card.json)
      [{'osm_link_id': ['223371529']}] is valid under each of {'required': ['osm_link_id']}, {'required': ['model_link_id']}, {'required': ['name']}

2023-03-30 13:26:54, DEBUG: Reading YAML-Style Project Card [e:\GitHub\network_wrangler_wsp-sag\examples\stpaul\project_cards\3_multiple_roadway_attribute_change.yml](file:///E:/GitHub/network_wrangler_wsp-sag/examples/stpaul/project_cards/3_multiple_roadway_attribute_change.yml)
2023-03-30 13:26:54, ERROR: Failed Project Card validation: Validation Error
   Project Card File Loc:[e:\GitHub\network_wrangler_wsp-sag\examples\stpaul\project_cards\3_multiple_roadway_attribute_change.yml](file:///E:/GitHub/network_wrangler_wsp-sag/examples/stpaul/project_cards/3_multiple_roadway_attribute_change.yml)
   Project Card Schema Loc:[E:\GitHub\network_wrangler_wsp-sag\network_wrangler\schemas\project_card.json](file:///E:/GitHub/network_wrangler_wsp-sag/network_wrangler/schemas/project_card.json)
      [{'name': ['6th', 'Sixth', 'sixth']}] is valid under each of {'required': ['osm_link_id']}, {'required': ['model_link_id']}, {'required': ['name']}

The error says "... is valid under ..."
Is valid seems like it's good? But it's not? 🤔

@e-lo
Copy link
Collaborator Author

e-lo commented Apr 10, 2023

The error says "... is valid under ..."
Is valid seems like it's good? But it's not? 🤔

Yeah - this sux and has to do with the project card not the scenario handling...which is fully addressed in a subsequent PR that moves the project card validation to the project card "project" ...but I'll add a quick bridge fix (was trying to not spend too much time on it b/c it will be fixed in #325

@e-lo e-lo merged commit 708772f into develop Apr 26, 2023
@e-lo e-lo deleted the change_project_apply_handling branch April 26, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] Rename/define Scenario variables so they make sense when building tiered scenarios
3 participants