I am confused about Julia behavior when I used pmap return object as an iterator. I will first show a chunk of code isomorphic to the malfunctioning code but which works and then show the malfunctioning code.
Consider this code embeded within a function which takes as an argument a vector of Integers:
MEPS_all_years = DataFrame();
for year in years
year_data = CSV.read(string("/users/miguelborrero/desktop/EffectACA/MEPS/augmented_MEPS", year, ".csv"), DataFrame)
MEPS_all_years = vcat(MEPS_all_years, year_data, cols=:union)
end
Now consider an “a priori” very similar (in terms of the use of the for loop) chunk of code which is also embedded in a function:
@everywhere function utility_gen(util::Int64, yearly_utility::DataFrame, hourly_utility::DataFrame, hourly_fuel_utility::DataFrame, parameters::Dict, weeklist::Vector{Vector{Int64}})
fit_results = DataFrame(utility_id = Int64[], est_YEAR = Int64[], sample_hour_of_year = Int64[], modefuel_short = String[], gload = Float64[],
elec_price = Float64[], util_revenues = Float64[], TVC = Float64[], NAMEPLATE = Float64[])
…
…
…
return fit_results
end
util_parallel(yearly_utility::DataFrame) = pmap(u -> utility_gen(u, yearly_utility, hourly_utility, hourly_fuel_utility, parameters, weeklist), [u for u in unique(yearly_utility.utility_id)])
fit_results_hourly = DataFrame()
for i in util_parallel(yearly_utility)
fit_results_hourly = vcat(fit_results_hourly, i)
end
Supposedly, util_parallel(yearly_utility) is an array of DataFrames and hence it can work as an iterable object and it does but when I run this last part it raises the undefvar error, claiming that fit_results_hourly is not defined. This does not happen in the first case and so it seems like using a return object from pmap(.) as the iterable object is messing with the scope.
Can someone give some insight as to way I am getting this error?
Thanks a lot!