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

Fix stochastic schedule generation runtime #1933

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Conversation

shorowit
Copy link
Contributor

@shorowit shorowit commented Feb 17, 2025

Pull Request Description

Fixes a regression introduced here that resulted in very slow generation of stochastic schedules.

Checklist

Not all may apply:

  • Schematron validator (EPvalidator.xml) has been updated
  • Sample files have been added/updated (openstudio tasks.rb update_hpxmls)
  • Tests have been added/updated (e.g., HPXMLtoOpenStudio/tests/test*.rb and/or workflow/tests/test*.rb)
  • Documentation has been updated
  • Changelog has been updated
  • openstudio tasks.rb update_measures has been run
  • No unexpected changes to simulation results of sample files

@shorowit shorowit self-assigned this Feb 17, 2025
@shorowit shorowit mentioned this pull request Feb 17, 2025
7 tasks
@shorowit shorowit marked this pull request as ready for review February 17, 2025 22:01
@schedules[SchedulesFile::Columns[:HotWaterFixtures].name] = fixtures.map { |flow| flow / fixtures.max }
@schedules[SchedulesFile::Columns[:HotWaterFixtures].name] = normalize(fixtures)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the primary bugfix. fixtures.max was being calculated within the iteration resulting in a huge performance hit.

Comment on lines -779 to +808
discharging_schedule += [1] * first_half_driving # Start driving
discharging_schedule += [0] * idle_time # Idle in the middle
discharging_schedule += [1] * second_half_driving # End driving
charging_schedule += [0] * activity_minutes
discharging_schedule.concat([1] * first_half_driving) # Start driving
discharging_schedule.concat([0] * idle_time) # Idle in the middle
discharging_schedule.concat([1] * second_half_driving) # End driving
charging_schedule.concat([0] * activity_minutes)

driving_minutes_used += actual_driving_time
else
charging_schedule += [1] * activity_minutes
discharging_schedule += [0] * activity_minutes
charging_schedule.concat([1] * activity_minutes)
discharging_schedule.concat([0] * activity_minutes)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically for EVs, this code was also resulting in some slowdown since += creates new arrays and all of this is happening within a loop.

Comment on lines 559 to 561
hours_per_year = (vehicle.hours_per_week / 7) * UnitConversions.convert(1, 'yr', 'day')
hours_per_week = get_ev_hours_per_week(vehicle)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found a bug while working on all of this. hours_per_week is not a required input, so we need to default it when not provided.

I should see if we can apply defaults to the entire HPXML Building (or a copy of the object, if we need to prevent writing the defaults out to disk) to generically prevent issues like this in the future...

…vidual defaulting methods. Should help prevent future bugs like vehicle.hours_per_week.
@shorowit
Copy link
Contributor Author

CI results:

  • Before EV schedules: 96.6s
  • After EV schedules: 230.2s
  • This PR: 101.9s

I'm calling it good enough.

@shorowit shorowit merged commit 1527bcd into master Feb 18, 2025
7 checks passed
@shorowit shorowit deleted the schedules_performance branch February 18, 2025 15:20
@joseph-robertson joseph-robertson mentioned this pull request Feb 18, 2025
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant