Skip to content

Commit 37408cc

Browse files
committed
Replace Process with OldProcess
1 parent a59cec9 commit 37408cc

15 files changed

Lines changed: 82 additions & 78 deletions

File tree

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,25 @@ julia> Pkg.add("SimJulia")
2727
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://BenLauwens.github.io/SimJulia.jl/stable)
2828
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://BenLauwens.github.io/SimJulia.jl/latest)
2929

30+
## License
31+
32+
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
33+
34+
## Authors
35+
36+
* Ben Lauwens, Royal Military Academy, Brussels, Belgium.
37+
38+
## Contributing
39+
40+
* To discuss problems or feature requests, file an issue. For bugs, please include as much information as possible, including operating system, julia version, and version of the dependencies: `DataStructures` and `ResumableFunctions`.
41+
* To contribute, make a pull request. Contributions should include tests for any new features/bug fixes.
3042

3143
## Release Notes
3244

33-
* 2017: v0.5 does no longer integrate a continuous time solver. A continuous time solver based on the standalone [QSS](https://sourceforge.net/projects/qssengine/) solver using SimJulia as its discrete event engine can be found in the repository [QuantizedStateSystems](https://github.com/BenLauwens/QuantizedStateSystems.jl.git):
34-
* Documentation is automated with [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
45+
* 2017: v0.5
46+
* The old way of making processes is deprecated in favor of the semi-coroutine approach as implemented in [ResumableFunctions](https://github.com/BenLauwens/ResumableFunctions.jl.git). The `@process` macro replaces the `@coroutine` macro. The old `@process` macro is temporarily renamed `@oldprocess` and will be removed when the infrastructure supporting the `produce` and the `consume` functions are no longer available in Julia. (DONE)
47+
* This version no longer integrates a continuous time solver. A continuous simulation framework based on [DISCO](http://www.akira.ruc.dk/~keld/research/DISCO/) and inspired by the standalone [QSS](https://sourceforge.net/projects/qssengine/) solver using SimJulia as its discrete-event engine can be found in the repository [QuantizedStateSystems](https://github.com/BenLauwens/QuantizedStateSystems.jl.git) (WIP):
48+
* Documentation is automated with [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) (WIP).
3549
* 2017: v0.4.1, the `resumable` and `yield` macro are put in a seperate package [ResumableFunctions](https://github.com/BenLauwens/ResumableFunctions.jl.git):
3650
* Users have to take into account the following syntax change: `@yield return arg` is replaced by `@yield arg`.
3751
* 2017: v0.4 only supports Julia v0.6 and above. It is a complete rewrite: more julian and less pythonic. The discrete event features are on par with v0.3 (SimPy v3) and following features are added:
@@ -95,15 +109,4 @@ julia> Pkg.add("SimJulia")
95109

96110
## Todo
97111

98-
* Transparent output processing.
99-
* Automatically running a large number of simulations (over a parameter space) on a cluster to do simulation based optimisation.
100-
101-
102-
## Authors
103-
104-
* Ben Lauwens, Royal Military Academy, Brussels, Belgium.
105-
106-
107-
## License
108-
109-
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
112+
* Transparent statistics gathering for resources.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float
44
while true
55
dt = rand(Exponential(1/lambd))
66
yield(Timeout(sim, dt))
7-
@process customer(sim, server, mu)
7+
@oldprocess customer(sim, server, mu)
88
end
99
end
1010

@@ -26,7 +26,7 @@ end
2626
function test_mm1(n::Float64)
2727
sim = Simulation()
2828
server = Resource(sim)
29-
@process exp_source(sim, 1.0, server, 1.1)
29+
@oldprocess exp_source(sim, 1.0, server, 1.1)
3030
run(sim, n)
3131
end
3232

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111

1212
function run_test()
1313
sim = Simulation()
14-
@process fibonnaci(sim)
14+
@oldprocess fibonnaci(sim)
1515
run(sim, 10)
1616
end
1717

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ makedocs(
77
format = :html,
88
sitename = "SimJulia.jl",
99
pages = [
10-
"Home" => "index.md",
10+
"Overview" => "index.md",
11+
"Manual" => "manual.md",
1112
]
1213
)
1314

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Overview
22

3-
SimJulia is a discrete event process oriented simulation framework written in [Julia](http://julialang.org/) inspired by the Python library [SimPy](https://simpy.readthedocs.io/).
3+
SimJulia is a discrete-event process-oriented simulation framework written in [Julia](http://julialang.org/) inspired by the Python library [SimPy](https://simpy.readthedocs.io/). Its preferred process dispatcher is based on semi-coroutines scheduling as implemented in [ResumableFunctions](git@github.com:BenLauwens/ResumableFunctions.jl.git). A `Process` in SimJulia is defined by a `@resumable function` yielding `Events`. SimJulia also provides three types of shared resources to model limited capacity congestion points: `Resources`, `Containers` and `Stores`. The API is modeled after the SimPy API but using some specific Julia semantics.

docs/src/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Manual
2+

src/SimJulia.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module SimJulia
2121
export Simulation
2222
export run, now, active_process
2323
export nowDatetime
24-
export Process, @process
24+
export OldProcess, @oldprocess
2525
export yield, interrupt
2626
export Coroutine, @coroutine
2727
export Container, Resource, Store
@@ -32,8 +32,7 @@ module SimJulia
3232
include("operators.jl")
3333
include("simulations.jl")
3434
include("utils/time.jl")
35-
include("tasks/base.jl")
36-
include("processes.jl")
35+
include("old/processes.jl")
3736
include("coroutines.jl")
3837
include("resources/base.jl")
3938
include("resources/containers.jl")
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
mutable struct Process <: DiscreteProcess
1+
function produce(v)
2+
ct = current_task()
3+
consumer = ct.consumers
4+
ct.consumers = nothing
5+
Base.schedule_and_wait(consumer, v)
6+
return consumer.result
7+
end
8+
9+
function consume(producer::Task, values...)
10+
istaskdone(producer) && return producer.value
11+
ct = current_task()
12+
ct.result = length(values)==1 ? values[1] : values
13+
producer.consumers = ct
14+
Base.schedule_and_wait(producer)
15+
end
16+
17+
mutable struct OldProcess <: DiscreteProcess
218
bev :: BaseEvent
319
task :: Task
420
target :: AbstractEvent
521
resume :: Function
6-
function Process(func::Function, env::Environment, args::Any...)
22+
function OldProcess(func::Function, env::Environment, args::Any...)
723
proc = new()
824
proc.bev = BaseEvent(env)
925
proc.task = @task func(env, args...)
@@ -13,11 +29,11 @@ mutable struct Process <: DiscreteProcess
1329
end
1430
end
1531

16-
macro process(expr)
32+
macro oldprocess(expr)
1733
expr.head != :call && error("Expression is not a function call!")
1834
func = esc(expr.args[1])
1935
args = [esc(expr.args[n]) for n in 2:length(expr.args)]
20-
:(Process($(func), $(args...)))
36+
:(OldProcess($(func), $(args...)))
2137
end
2238

2339
function yield(target::AbstractEvent)
@@ -30,7 +46,7 @@ function yield(target::AbstractEvent)
3046
return ret
3147
end
3248

33-
function execute(ev::AbstractEvent, proc::Process)
49+
function execute(ev::AbstractEvent, proc::OldProcess)
3450
try
3551
env = environment(ev)
3652
set_active_process(env, proc)
@@ -42,7 +58,7 @@ function execute(ev::AbstractEvent, proc::Process)
4258
end
4359
end
4460

45-
function interrupt(proc::Process, cause::Any=nothing)
61+
function interrupt(proc::OldProcess, cause::Any=nothing)
4662
if !istaskdone(proc.task)
4763
remove_callback(proc.resume, proc.target)
4864
proc.target = Timeout(environment(proc); priority=typemax(Int8), value=InterruptException(proc, cause))

src/tasks/base.jl

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/containers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function source(sim::Simulation, server::Resource)
6262
while true
6363
i += 1
6464
yield(Timeout(sim, rand()))
65-
@process customer(sim, server, i)
65+
@oldprocess customer(sim, server, i)
6666
end
6767
end
6868

@@ -80,5 +80,5 @@ end
8080

8181
sim = Simulation()
8282
server = Resource(sim)
83-
@process source(sim, server)
83+
@oldprocess source(sim, server)
8484
run(sim, 10.0)

0 commit comments

Comments
 (0)