Engee documentation
Notebook

From Workspace and To Workspace

In this demonstration we will describe the specifics of using From Workspace and To Workspace blocks. Our goal is to show how we can feed data into or read data from the model. For this purpose, we have implemented a simple model shown in the figure below.

image_2.png

Next, we will plug in the library needed to form the WorkspaceArray data structure.

First, we will create a DataFrame structure with time and data columns.

After that we create a WorkspaceArray object, the first parameter of which is the internal name of the database, and the second parameter is the data from the DataFrame structure.

In [ ]:
using DataFrames
In [ ]:
# Задаем данные:
t = [1.0, 2.0, 4.0];
d = rand(Float64, size(t));
In [ ]:
df = DataFrame(time=t, value=d)
Out[0]:

3 rows × 2 columns

timevalue
Float64Float64
11.00.554436
22.00.564866
34.00.116877
In [ ]:
wa = WorkspaceArray(string(rand()), df)
Out[0]:
WorkspaceArray("0.7893540708500778")

Let's move on to running our model.

In [ ]:
function run_model( name_model, path_to_folder )
    
    Path = path_to_folder * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end

    return model_output
end
Out[0]:
run_model (generic function with 1 method)
In [ ]:
run_model("from_to_workspace", @__DIR__)
Building...
Progress 0%
Progress 0%
Progress 5%
Progress 10%
Progress 15%
Progress 20%
Progress 25%
Progress 30%
Progress 35%
Progress 40%
Progress 45%
Progress 50%
Progress 55%
Progress 60%
Progress 65%
Progress 70%
Progress 75%
Progress 80%
Progress 85%
Progress 90%
Progress 95%
Progress 100%

At the output we will also get the WorkspaceArray structure. Let's view its fields and compare them with the input data.

In [ ]:
dump(out)
WorkspaceArray{Any}
  name: String "out"
  vecsize: Int64 11
  method: Symbol file
  chunks: OrderedCollections.OrderedDict{Int64, Array}
    slots: Array{Int32}((16,)) Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    keys: Array{Int64}((0,)) Int64[]
    vals: Array{Array}((0,))
    ndel: Int64 0
    maxprobe: Int64 0
    dirty: Bool false
  type: Symbol pair
  range: StepRange{Int64, Int64}
    start: Int64 1
    step: Int64 1
    stop: Int64 11
  parent: Nothing nothing
  time: WorkspaceArray{Any}
    name: String "out"
    vecsize: Int64 11
    method: Symbol file
    chunks: OrderedCollections.OrderedDict{Int64, Array}
      slots: Array{Int32}((16,)) Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      keys: Array{Int64}((0,)) Int64[]
      vals: Array{Array}((0,))
      ndel: Int64 0
      maxprobe: Int64 0
      dirty: Bool false
    type: Symbol time
    range: StepRange{Int64, Int64}
      start: Int64 1
      step: Int64 1
      stop: Int64 11
    parent: Nothing nothing
    time: ErrorException
      msg: String "WorkspaceArray типа :time не имеет поля time"
    value: ErrorException
      msg: String "WorkspaceArray типа :time не имеет поля value"
  value: WorkspaceArray{Any}
    name: String "out"
    vecsize: Int64 11
    method: Symbol file
    chunks: OrderedCollections.OrderedDict{Int64, Array}
      slots: Array{Int32}((16,)) Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      keys: Array{Int64}((0,)) Int64[]
      vals: Array{Array}((0,))
      ndel: Int64 0
      maxprobe: Int64 0
      dirty: Bool false
    type: Symbol value
    range: StepRange{Int64, Int64}
      start: Int64 1
      step: Int64 1
      stop: Int64 11
    parent: Nothing nothing
    time: ErrorException
      msg: String "WorkspaceArray типа :value не имеет поля time"
    value: ErrorException
      msg: String "WorkspaceArray типа :value не имеет поля value"
In [ ]:
data = collect(out)
Out[0]:

11 rows × 2 columns

timevalue
AnyAny
10.01.08801
21.01.10887
32.01.12973
43.00.681743
54.00.233753
65.00.0
76.00.0
87.00.0
98.00.0
109.00.0
1110.00.0
In [ ]:
using Plots
plot(df.time,df.value) # Входные данные
plot!(data.time,data.value) # Выходные данные
Out[0]:

As we can see from the comparison, as a result, the data we fed into the model was doubled.

Conclusion

We have demonstrated the options for transferring data from the workspace to models and back. These features of the environment greatly simplify your interaction with models.

Blocks used in example