Skip to content

Commit 5f361d1

Browse files
committed
remove unused distributed usage and import
1 parent ce81241 commit 5f361d1

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

src/simulation.jl

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Distributed
2-
31
function compute_single_step_cost(
42
model::Model,
53
y::Vector{<:Real},
@@ -48,7 +46,7 @@ function compute_single_step_gradient(
4846
end
4947

5048
"""
51-
compute_cost(model, X, Y, with_gradients=false, n_workers=1)
49+
compute_cost(model, X, Y, with_gradients=false)
5250
5351
Compute the cost function (C) based on the model predictions and the true values.
5452
@@ -67,7 +65,6 @@ function compute_cost(
6765
X::Matrix{<:Real},
6866
Y::Matrix{<:Real},
6967
with_gradients::Bool = false,
70-
n_workers::Int = 1,
7168
)
7269

7370
# data size assertions
@@ -96,32 +93,11 @@ function compute_cost(
9693
# get predictions
9794
Yhat = model.forecast(X')' # size=(T, output_size)
9895

99-
# main loop - sequential
100-
if n_workers == 1
101-
for t = 1:T
102-
result = _compute_step(Y[t, :], Yhat[t, :])
103-
C += result[1] ./ T
104-
dC .+= result[2] ./ T
105-
end
106-
107-
# main loop - parallel
108-
elseif n_workers > 1
109-
110-
# add workers and import package on first call
111-
if nprocs() < n_workers
112-
error(
113-
"Please add workers and import the AppDrivenLearning module @everywhere before calling `train!` function.",
114-
)
115-
end
116-
117-
# parallel computation
118-
result =
119-
pmap(_compute_step, [Y[t, :] for t = 1:T], [Yhat[t, :] for t = 1:T])
120-
C = sum([r[1] for r in result])
121-
dC = sum([r[2] for r in result])
122-
123-
else
124-
error("Invalid number of workers")
96+
# main loop to compute cost
97+
for t = 1:T
98+
result = _compute_step(Y[t, :], Yhat[t, :])
99+
C += result[1] ./ T
100+
dC .+= result[2] ./ T
125101
end
126102

127103
if with_gradients

0 commit comments

Comments
 (0)