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

Comparing with TransportationTracker and without TransportationTracker for HPC execution speed. #26

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions celavi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# of generating a new one
use_computed_routes = True
# create cost graph fresh or use an imported version
#Initialize cost graph should be always set to true because the cost graph pickle will not exists for users.
#Setting this to false should only be done when exploring same regions multiple times on the same machine.
initialize_costgraph = True
# save the newly initialized costgraph as a pickle file
pickle_costgraph = True
Expand Down Expand Up @@ -89,8 +91,12 @@

turbine_data_filename = os.path.join(args.data, 'inputs', 'number_of_turbines.csv')


data_filtering_choice = False
#The code is setup such that data filtering is always true unless user sends 'US' as an argument to the code run statement.
#Sending any other arguments, namely state abbreviations will result in filtering to occur
#Send python __main__.py --list US for national scale run
#Send python __main__.py --list IO CO .... for state runs.
#maximum of 6 states can be entered on the HPC runs right now. Can be modified later.
data_filtering_choice = True
if args.list == ['US']:
print('National Scale Run')
data_filtering_choice = False
Expand All @@ -103,9 +109,6 @@
print(states_to_filter)
data_filter(locations_computed_filename, routes_computed_filename, turbine_data_filename, states_to_filter)




# Pickle file containing CostGraph object
costgraph_pickle_filename = os.path.join(args.data, 'inputs', 'netw.obj')
costgraph_csv_filename = os.path.join(args.data, 'inputs', 'netw.csv')
Expand Down Expand Up @@ -275,6 +278,8 @@
print('FINISHED RUN at %d s' % np.round(time.time() - time0),
flush=True)

pickle.dump(count_facility_inventories, open('graph_context_count_facility.obj', 'wb'))

# Plot the cumulative count levels of the inventories
diagnostic_viz = DiagnosticViz(context, subfolder_dict['outputs_folder'])
diagnostic_viz.generate_blade_count_plots()
18 changes: 6 additions & 12 deletions celavi/component.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import List, Dict, Deque, Tuple
from collections import deque

from transportation_tracker import TransportationTracker


class Component:
"""
Expand Down Expand Up @@ -92,16 +90,16 @@ def create_pathway_queue(self, from_facility_id: int):
path_choice = path_choices_dict[manufacturing_facility_id]
self.pathway = deque()

for facility, lifespan, distance in path_choice['path']:
for facility, lifespan in path_choice['path']:
# Override the initial timespan when component goes into use.
if facility.startswith("in use"):
self.pathway.append((facility, self.initial_lifespan_timesteps, distance))
self.pathway.append((facility, self.initial_lifespan_timesteps))
# Set landfill timespan long enough to be permanent
elif facility.startswith("landfill"):
self.pathway.append((facility, self.context.max_timesteps * 2, distance))
self.pathway.append((facility, self.context.max_timesteps * 2))
# Otherwise, use the timespan the model gives us.
else:
self.pathway.append((facility, lifespan, distance))
self.pathway.append((facility, lifespan))

def manufacturing(self, env):
"""
Expand Down Expand Up @@ -136,16 +134,12 @@ def eol_process(self, env):
if self.current_location.startswith('manufacturing'):
# Query cost graph again
self.create_pathway_queue(self.in_use_facility_id)
# Because the blade was just manufactured, skip the first
# manufacturing step so that the blade is not manufactured twice in
# a row.
# Since the blade was immediately prior in use, just go to next step.
self.pathway.popleft()

location, lifespan, distance = self.pathway.popleft()
location, lifespan = self.pathway.popleft()
count_inventory = self.context.count_facility_inventories[location]
transport = self.context.transportation_trackers[location]
count_inventory.increment_quantity(self.kind, 1, env.now)
transport.increment_inbound_tonne_km(self.mass_tonnes * distance, env.now)
self.current_location = location
yield env.timeout(lifespan)
count_inventory.increment_quantity(self.kind, -1, env.now)
Expand Down
8 changes: 4 additions & 4 deletions celavi/costgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,8 @@ def find_nearest(self,
a_dictionary = {1: "a", 2: "b", 3: "c"}
timeout = nx.get_node_attributes(self.supply_chain, 'timeout')
timeout_list = [value for key, value in timeout.items() if key in short_paths[nearest]]
dist_list = [self.supply_chain.edges[short_paths[nearest][d:d+2]]['dist'] for d in range(len(short_paths[nearest])-1)]
dist_list.insert(0, 0.0)
_out = self.list_of_tuples(short_paths[nearest], timeout_list, dist_list)

_out = self.list_of_tuples(short_paths[nearest], timeout_list)

return nearest, subdict[nearest], _out
else:
Expand Down Expand Up @@ -695,7 +694,8 @@ def find_upstream_neighbor(self,
if len(_upstream_nodes) == 0:
# If there are no upstream nodes of the correct type, print a
# message and return None
print(f'Facility {node_id} does not have any upstream neighbors of type {connect_to}',
print('Facility %d does not have any upstream neighbors of type %s'
% node_id, connect_to,
flush=True)
return None

Expand Down
20 changes: 0 additions & 20 deletions celavi/des.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pandas as pd

from celavi.inventory import FacilityInventory
from celavi.transportation_tracker import TransportationTracker
from celavi.component import Component
from celavi.costgraph import CostGraph

Expand Down Expand Up @@ -108,7 +107,6 @@ def __init__(
locations_step_costs = locations.merge(step_costs, on='facility_id')

self.count_facility_inventories = {}
self.transportation_trackers = {}
for _, row in locations_step_costs.iterrows():
facility_type = row['facility_type_x']
facility_id = row['facility_id']
Expand All @@ -123,7 +121,6 @@ def __init__(
quantity_unit="count",
can_be_negative=False
)
self.transportation_trackers[step_facility_id] = TransportationTracker(timesteps=max_timesteps)

self.cost_graph = cost_graph
self.cost_graph_update_interval_timesteps = cost_graph_update_interval_timesteps
Expand Down Expand Up @@ -202,14 +199,12 @@ def populate(self, df: pd.DataFrame, lifespan_fns: Dict[str, Callable[[], float]
"""

for _, row in df.iterrows():
avg_blade_mass_tonnes_for_year = self.avg_blade_mass_tonnes_dict[row["year"]]
component = Component(
kind=row["kind"],
year=row["year"],
in_use_facility_id=row["facility_id"],
context=self,
lifespan_timesteps=lifespan_fns[row["kind"]](),
mass_tonnes=avg_blade_mass_tonnes_for_year
)
self.env.process(component.manufacturing(self.env))
self.components.append(component)
Expand Down Expand Up @@ -308,21 +303,6 @@ def pylca_interface_process(self, env):
}
self.data_for_lci.append(row)
annual_data_for_lci.append(row)
for facility_name, tracker in self.transportation_trackers.items():
_, facility_id = facility_name.split("_")
annual_transportations = tracker.inbound_tonne_km[window_first_timestep:window_last_timestep + 1]
tonne_km = annual_transportations.sum()
if tonne_km > 0:
row = {
'flow quantity': tonne_km,
'stage': 'Transportation',
'year': year,
'material': 'transportation',
'flow unit': 't * km',
'facility_id': facility_id
}
self.data_for_lci.append(row)
annual_data_for_lci.append(row)
print(str(time.time() - time0)+' For loop of pylca took these many seconds')
if len(annual_data_for_lci) > 0:
print(f'{datetime.now()} DES interface: Found flow quantities greater than 0, performing LCIA')
Expand Down
51 changes: 0 additions & 51 deletions celavi/scriptmain.sh

This file was deleted.

33 changes: 0 additions & 33 deletions celavi/transportation_tracker.py

This file was deleted.