Skip to content

Create Scenario class#12

Merged
rouille merged 245 commits intodevelopfrom
scenario
Jul 22, 2019
Merged

Create Scenario class#12
rouille merged 245 commits intodevelopfrom
scenario

Conversation

@rouille
Copy link
Copy Markdown
Collaborator

@rouille rouille commented Jul 12, 2019

This the new framework to handle scenarios. Those can now be created, ran, analyzed and deleted from the local machine with Python only. This package also includes the Grid object that is used by other packages (PreREISE and PostREISE) to get information on the network used in this project (GPS coordinates of generators, charcteristics of transmission lines, ... See README for a description of the attributes).

@rouille rouille requested review from dmuldrew and kasparm July 12, 2019 22:31
@rouille rouille self-assigned this Jul 12, 2019
Comment thread README.md
Comment thread README.md
scenario.print_scenario_info() # print scenario information

# prepare simulation inputs
scenario.state.prepare_simulation_input()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm thinking that it might be more natural to have methods "print_scenario_status()", "prepare_simulation_input()" and "launch_simulation()" be methods of the scenario object and not state, so then we'll have:
scenario.print_status()
scenario.launch_simulation()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

print_scenario_status() is currently a method of the Execute object since it tracks the execution process (created --> prepared --> running --> finished --> extracted). That said this functionality can easily be made state independent and be moved to the Scenario object. Perhaps, the method should be renamed print_execution_status() and stays where it is now.

The other two methods, prepare_simulation() and launch_simulation() are also part of the Execute object and by design they cannot be moved. We can talk about the design and see if we can improve it.

@@ -0,0 +1,260 @@
import os
import pickle
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We need to evaluate pros and cons of using hdf5. If we decide to go this way we will have to convert the already produced output files and do some slight changes in the code. Nothing to completed. @dmuldrew can create an issue on ZenHub. This could a new PR.

:param str resource: type of generator.
:raises ValueError: if resource cannot be changed.
"""
possible = ['coal', 'ng', 'nuclear', 'hydro', 'solar', 'wind']
Copy link
Copy Markdown
Collaborator

@dmuldrew dmuldrew Jul 17, 2019

Choose a reason for hiding this comment

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

defining an enumerated types here will eliminate the need to have this possible matrix - it will just be built directly into the type

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That would be nice. I need to investigate enumerated types in Python. I am not sure this can be done for this CR. Can probably be its own PR.

['zone_name', 'type']).get_group(
(zone_name, resource)).index.values.tolist()
except KeyError:
pass
Copy link
Copy Markdown
Collaborator

@dmuldrew dmuldrew Jul 17, 2019

Choose a reason for hiding this comment

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

print out error here? what happens if the exception in the try block isn't a KeyError

scaling factor for the increase/decrease in capacity of the
generator.
"""
self._check_resource(resource)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check resource raises an exception, not sure where it will be caught...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The exception is caught as we saw yesterday. The full traceback is printed. We might want in the future to print the error and return. Believe that it does not hurt to have the full traceback since we are still developing the platform. We definitely want in the future to have a more user friendly handling of the error.

Comment thread setup.py Outdated
@kasparm
Copy link
Copy Markdown
Contributor

kasparm commented Jul 18, 2019

Please finish your reviews until tomorrow noon!

@rouille rouille merged commit 0a32c41 into develop Jul 22, 2019
:return: (*dict*) -- keys are the interval number and the values are
the decrease in percent (%) applied to the original demand profile.
"""
field = self._scenario_info['infeasibilities']
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

perhaps replace "field" name with "infeas" or some variant

elif status.shape[0] == 1:
self.status = status.status.values[0]

def print_scenario_info(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

seems like the implementation of this function can potentially moved out of state to here

self.state.print_scenario_info()

def change(self, state):
"""Changes state.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

likewise perhaps move implentation of this function here

self.__class__ = state
self._enter()
else:
print('State switching: %s -/-> %s' % (self, state.name))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we can be more explicit that a particular state switch is no allowed

name = "state"
allowed = []

def switch(self, state):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what is state here? an instance of class State? the name of a state?

@ahurli ahurli mentioned this pull request Mar 11, 2021
@rouille rouille changed the title Scenario Create Scenario class Mar 16, 2021
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.

5 participants