In [ ]:
import veneer
from veneer.manage import BulkVeneer
%matplotlib inline
import geopandas as gpd
import pandas as pd

In [3]:
from veneer.batch import BatchRunner

Connect to Source and test connection

Using 4 instances


In [4]:
## Veneer started elsewhere (probably from a command line using veneer.manager.start)
ports = list(range(15004,15008))
ports


Out[4]:
[15004, 15005, 15006, 15007]

In [5]:
bv = BulkVeneer(ports)

In [8]:
v = bv.veneers[1]

In [9]:
network = v.network()
network.as_dataframe().plot()


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x11604dd30>

In [10]:
network.outlet_nodes()


Out[10]:
[{'geometry': {'coordinates': [564000, 5799000], 'type': 'Point'}, 'id': '/network/nodes/4', 'properties': {'name': 'Generated node name #1', 'feature_type': 'node', 'icon': '/resources/ConfluenceNodeModel'}, 'type': 'Feature'}]

In [11]:
outlet_node = network.outlet_nodes()[0]['properties']['name'] + '$'

Enumerate the parameter combinations


In [12]:
import numpy as np

In [13]:
N_RUNS=100

In [14]:
params = {
    'x1':np.random.uniform(1.0,1500.0,size=N_RUNS),
    'x2':np.random.uniform(1.0,5.0,size=N_RUNS),
    'x3':np.random.uniform(1.0,200.0,size=N_RUNS),
    'x4':np.random.uniform(0.5,3.0,size=N_RUNS)
}
params = pd.DataFrame(params)
params


Out[14]:
x1 x2 x3 x4
0 1437.038293 4.589127 156.416815 1.917925
1 490.635325 1.373342 66.261211 2.132400
2 503.157913 3.837195 139.371838 1.133919
3 762.522418 4.915908 23.330254 1.689078
4 1476.447618 1.865532 25.549203 2.020109
5 594.121244 3.441850 20.646041 0.730907
6 280.045280 2.909545 58.588357 0.605880
7 529.685542 3.981529 193.636181 1.359530
8 584.717939 1.327539 184.592716 2.273602
9 1023.641410 3.958867 133.133076 2.675517
10 370.904067 3.148611 143.983675 2.579772
11 350.967407 1.949238 6.787760 2.660127
12 664.557025 4.446197 119.777828 2.564932
13 912.798499 3.079663 63.729398 1.003530
14 766.192900 3.529385 136.411999 2.860476
15 580.399385 4.355302 128.348910 1.168536
16 1127.673214 3.331318 142.670363 1.311310
17 1421.135505 4.054419 20.854834 2.357169
18 230.268771 2.057784 42.221202 1.073698
19 657.959869 2.339957 62.624697 2.935122
20 457.814578 2.931548 147.712729 2.317671
21 1301.815604 1.898408 33.378968 1.639443
22 242.981840 4.356230 154.873787 1.661152
23 673.838269 1.952150 47.285481 2.241080
24 130.803826 1.922639 78.256532 1.997422
25 1348.168226 2.238456 55.061444 1.375816
26 822.873974 4.005278 117.497883 1.112867
27 1471.888058 3.783675 59.822640 2.164370
28 1120.989844 2.370592 95.682067 0.969325
29 1398.517494 2.022906 180.895274 2.359341
... ... ... ... ...
70 428.288327 1.647562 4.443335 1.923212
71 1332.860743 4.878352 152.294051 2.554772
72 822.145149 1.601861 42.536527 1.165801
73 1348.400313 1.461570 187.190518 1.837775
74 581.542663 1.709848 44.832470 2.033216
75 193.118629 2.043706 89.205092 2.411392
76 146.815764 4.116197 125.781932 2.658140
77 362.223258 3.050768 154.680540 1.689425
78 1454.742000 2.636304 196.682298 2.430883
79 833.476299 2.389415 17.825310 2.912991
80 706.568911 3.649193 102.749883 2.090388
81 303.307670 3.121287 52.370184 2.708715
82 1103.624499 4.995963 148.092095 1.288812
83 60.730648 1.822377 91.397038 2.385393
84 96.129219 1.659616 6.224495 2.377158
85 240.666243 3.538954 8.312790 1.198550
86 490.546755 2.470175 156.049329 1.770770
87 321.673647 3.923853 18.695061 0.723023
88 1488.320972 4.174391 12.761590 0.919655
89 1457.886039 3.313954 58.095473 2.935384
90 280.561653 2.102812 168.702005 2.409801
91 896.541055 2.326365 100.283841 1.907426
92 1447.998424 3.348734 16.542053 2.217863
93 53.388734 3.416532 3.480260 2.212477
94 682.525637 3.262332 15.593709 0.646525
95 36.940805 4.478442 174.214335 2.718074
96 117.663056 3.255782 39.143288 2.993388
97 1268.722867 1.545351 17.300040 2.875409
98 763.765273 1.874043 65.388955 2.259460
99 419.782539 2.429699 23.686389 1.789150

100 rows × 4 columns

Specify the model changes

(Much like we do when setting up a PEST job)


In [15]:
runner = BatchRunner(bv.veneers)

In [16]:
v.model.catchment.runoff.set_param_values?

In [17]:
for p in ['x1','x2','x3','x4']:
    runner.parameters.model.catchment.runoff.set_param_values(p,'$%s$'%p,fus=['Grazing'])

Specify the result 'y' that we want to retrieve


In [18]:
runner.retrieve('y').retrieve_multiple_time_series(criteria={'NetworkElement':outlet_node,'RecordingVariable':'Downstream Flow Volume'}).sum()[0]


Out[18]:
<veneer.utils.DeferredCall at 0x116305198>

In [19]:
%xmode Verbose
print(runner._retrieval.script())


Exception reporting mode: Verbose
results['y'] = v.retrieve_multiple_time_series(criteria={'NetworkElement': 'Generated node name #1$', 'RecordingVariable': 'Downstream Flow Volume'}).sum()[0]

Trigger the run...

Will run the 100 simulations across the four instances of Source (25 runs each)


In [20]:
jobs,results = runner.run(params)


0 x1    1437.038293
x2       4.589127
x3     156.416815
x4       1.917925
Name: 0, dtype: float64
1 x1    490.635325
x2      1.373342
x3     66.261211
x4      2.132400
Name: 1, dtype: float64
2 x1    503.157913
x2      3.837195
x3    139.371838
x4      1.133919
Name: 2, dtype: float64
3 x1    762.522418
x2      4.915908
x3     23.330254
x4      1.689078
Name: 3, dtype: float64
4 x1    1476.447618
x2       1.865532
x3      25.549203
x4       2.020109
Name: 4, dtype: float64
5 x1    594.121244
x2      3.441850
x3     20.646041
x4      0.730907
Name: 5, dtype: float64
6 x1    280.045280
x2      2.909545
x3     58.588357
x4      0.605880
Name: 6, dtype: float64
7 x1    529.685542
x2      3.981529
x3    193.636181
x4      1.359530
Name: 7, dtype: float64
8 x1    584.717939
x2      1.327539
x3    184.592716
x4      2.273602
Name: 8, dtype: float64
9 x1    1023.641410
x2       3.958867
x3     133.133076
x4       2.675517
Name: 9, dtype: float64
10 x1    370.904067
x2      3.148611
x3    143.983675
x4      2.579772
Name: 10, dtype: float64
11 x1    350.967407
x2      1.949238
x3      6.787760
x4      2.660127
Name: 11, dtype: float64
12 x1    664.557025
x2      4.446197
x3    119.777828
x4      2.564932
Name: 12, dtype: float64
13 x1    912.798499
x2      3.079663
x3     63.729398
x4      1.003530
Name: 13, dtype: float64
14 x1    766.192900
x2      3.529385
x3    136.411999
x4      2.860476
Name: 14, dtype: float64
15 x1    580.399385
x2      4.355302
x3    128.348910
x4      1.168536
Name: 15, dtype: float64
16 x1    1127.673214
x2       3.331318
x3     142.670363
x4       1.311310
Name: 16, dtype: float64
17 x1    1421.135505
x2       4.054419
x3      20.854834
x4       2.357169
Name: 17, dtype: float64
18 x1    230.268771
x2      2.057784
x3     42.221202
x4      1.073698
Name: 18, dtype: float64
19 x1    657.959869
x2      2.339957
x3     62.624697
x4      2.935122
Name: 19, dtype: float64
20 x1    457.814578
x2      2.931548
x3    147.712729
x4      2.317671
Name: 20, dtype: float64
21 x1    1301.815604
x2       1.898408
x3      33.378968
x4       1.639443
Name: 21, dtype: float64
22 x1    242.981840
x2      4.356230
x3    154.873787
x4      1.661152
Name: 22, dtype: float64
23 x1    673.838269
x2      1.952150
x3     47.285481
x4      2.241080
Name: 23, dtype: float64
24 x1    130.803826
x2      1.922639
x3     78.256532
x4      1.997422
Name: 24, dtype: float64
25 x1    1348.168226
x2       2.238456
x3      55.061444
x4       1.375816
Name: 25, dtype: float64
26 x1    822.873974
x2      4.005278
x3    117.497883
x4      1.112867
Name: 26, dtype: float64
27 x1    1471.888058
x2       3.783675
x3      59.822640
x4       2.164370
Name: 27, dtype: float64
28 x1    1120.989844
x2       2.370592
x3      95.682067
x4       0.969325
Name: 28, dtype: float64
29 x1    1398.517494
x2       2.022906
x3     180.895274
x4       2.359341
Name: 29, dtype: float64
30 x1    598.356276
x2      4.171592
x3    135.611851
x4      2.458004
Name: 30, dtype: float64
31 x1    498.503417
x2      2.997619
x3    150.087832
x4      0.748170
Name: 31, dtype: float64
32 x1    908.965341
x2      4.841202
x3      8.198002
x4      0.587752
Name: 32, dtype: float64
33 x1    1254.175350
x2       3.881825
x3     136.707770
x4       1.352189
Name: 33, dtype: float64
34 x1    375.610178
x2      2.575641
x3    139.785061
x4      2.652186
Name: 34, dtype: float64
35 x1    1134.364063
x2       2.045506
x3     168.093393
x4       1.023673
Name: 35, dtype: float64
36 x1    529.222160
x2      3.351645
x3    196.423729
x4      0.629501
Name: 36, dtype: float64
37 x1    377.389543
x2      3.601640
x3     81.335629
x4      2.779631
Name: 37, dtype: float64
38 x1    1083.290521
x2       3.001364
x3     194.077254
x4       0.660371
Name: 38, dtype: float64
39 x1    822.387201
x2      3.891724
x3    166.424650
x4      1.725403
Name: 39, dtype: float64
40 x1    1458.370149
x2       3.052609
x3      67.142369
x4       2.355478
Name: 40, dtype: float64
41 x1    94.279780
x2     3.630626
x3    59.899105
x4     0.791427
Name: 41, dtype: float64
42 x1    1410.766046
x2       1.921577
x3     196.667116
x4       1.045949
Name: 42, dtype: float64
43 x1    246.498753
x2      3.972531
x3    186.735186
x4      1.945475
Name: 43, dtype: float64
44 x1    690.888717
x2      1.574567
x3    129.151133
x4      1.413614
Name: 44, dtype: float64
45 x1    639.460050
x2      1.314179
x3    115.837188
x4      1.000562
Name: 45, dtype: float64
46 x1    1473.607264
x2       1.735683
x3      70.687244
x4       0.963588
Name: 46, dtype: float64
47 x1    1382.503453
x2       4.912177
x3     120.848963
x4       2.256299
Name: 47, dtype: float64
48 x1    1376.422502
x2       3.306942
x3      37.047913
x4       2.587269
Name: 48, dtype: float64
49 x1    1194.222556
x2       3.826713
x3     107.627173
x4       2.496840
Name: 49, dtype: float64
50 x1    707.626004
x2      3.804598
x3    114.472693
x4      2.390447
Name: 50, dtype: float64
51 x1     10.496699
x2      4.434483
x3    198.886094
x4      0.612120
Name: 51, dtype: float64
52 x1    1427.712491
x2       3.679004
x3     183.121057
x4       2.522920
Name: 52, dtype: float64
53 x1    311.578382
x2      4.521798
x3     30.783609
x4      2.289353
Name: 53, dtype: float64
54 x1    719.807739
x2      2.265974
x3     38.043237
x4      1.470452
Name: 54, dtype: float64
55 x1    864.473538
x2      4.686704
x3    132.645269
x4      1.624907
Name: 55, dtype: float64
56 x1    1153.310001
x2       4.113556
x3     136.478798
x4       1.657297
Name: 56, dtype: float64
57 x1    977.941951
x2      2.524514
x3     44.863978
x4      1.254107
Name: 57, dtype: float64
58 x1    1055.237730
x2       4.192810
x3     103.690058
x4       2.377328
Name: 58, dtype: float64
59 x1    730.948377
x2      1.199999
x3     13.528121
x4      2.958076
Name: 59, dtype: float64
60 x1    791.471149
x2      2.436889
x3     82.033286
x4      0.648261
Name: 60, dtype: float64
61 x1    711.729901
x2      1.432959
x3    184.463984
x4      1.905971
Name: 61, dtype: float64
62 x1    792.592766
x2      2.691177
x3    153.316815
x4      2.168617
Name: 62, dtype: float64
63 x1    1261.463801
x2       3.914737
x3     167.854476
x4       2.567751
Name: 63, dtype: float64
64 x1    1326.997455
x2       4.856341
x3     114.300660
x4       1.893270
Name: 64, dtype: float64
65 x1    1309.216763
x2       2.657210
x3     158.140328
x4       2.105625
Name: 65, dtype: float64
66 x1    779.672849
x2      4.170265
x3    188.471640
x4      1.879650
Name: 66, dtype: float64
67 x1    760.502953
x2      3.190336
x3     93.536259
x4      2.340197
Name: 67, dtype: float64
68 x1    585.464703
x2      4.252193
x3    177.039125
x4      2.432385
Name: 68, dtype: float64
69 x1    732.088070
x2      3.380119
x3     87.216753
x4      0.620936
Name: 69, dtype: float64
70 x1    428.288327
x2      1.647562
x3      4.443335
x4      1.923212
Name: 70, dtype: float64
71 x1    1332.860743
x2       4.878352
x3     152.294051
x4       2.554772
Name: 71, dtype: float64
72 x1    822.145149
x2      1.601861
x3     42.536527
x4      1.165801
Name: 72, dtype: float64
73 x1    1348.400313
x2       1.461570
x3     187.190518
x4       1.837775
Name: 73, dtype: float64
74 x1    581.542663
x2      1.709848
x3     44.832470
x4      2.033216
Name: 74, dtype: float64
75 x1    193.118629
x2      2.043706
x3     89.205092
x4      2.411392
Name: 75, dtype: float64
76 x1    146.815764
x2      4.116197
x3    125.781932
x4      2.658140
Name: 76, dtype: float64
77 x1    362.223258
x2      3.050768
x3    154.680540
x4      1.689425
Name: 77, dtype: float64
78 x1    1454.742000
x2       2.636304
x3     196.682298
x4       2.430883
Name: 78, dtype: float64
79 x1    833.476299
x2      2.389415
x3     17.825310
x4      2.912991
Name: 79, dtype: float64
80 x1    706.568911
x2      3.649193
x3    102.749883
x4      2.090388
Name: 80, dtype: float64
81 x1    303.307670
x2      3.121287
x3     52.370184
x4      2.708715
Name: 81, dtype: float64
82 x1    1103.624499
x2       4.995963
x3     148.092095
x4       1.288812
Name: 82, dtype: float64
83 x1    60.730648
x2     1.822377
x3    91.397038
x4     2.385393
Name: 83, dtype: float64
84 x1    96.129219
x2     1.659616
x3     6.224495
x4     2.377158
Name: 84, dtype: float64
85 x1    240.666243
x2      3.538954
x3      8.312790
x4      1.198550
Name: 85, dtype: float64
86 x1    490.546755
x2      2.470175
x3    156.049329
x4      1.770770
Name: 86, dtype: float64
87 x1    321.673647
x2      3.923853
x3     18.695061
x4      0.723023
Name: 87, dtype: float64
88 x1    1488.320972
x2       4.174391
x3      12.761590
x4       0.919655
Name: 88, dtype: float64
89 x1    1457.886039
x2       3.313954
x3      58.095473
x4       2.935384
Name: 89, dtype: float64
90 x1    280.561653
x2      2.102812
x3    168.702005
x4      2.409801
Name: 90, dtype: float64
91 x1    896.541055
x2      2.326365
x3    100.283841
x4      1.907426
Name: 91, dtype: float64
92 x1    1447.998424
x2       3.348734
x3      16.542053
x4       2.217863
Name: 92, dtype: float64
93 x1    53.388734
x2     3.416532
x3     3.480260
x4     2.212477
Name: 93, dtype: float64
94 x1    682.525637
x2      3.262332
x3     15.593709
x4      0.646525
Name: 94, dtype: float64
95 x1     36.940805
x2      4.478442
x3    174.214335
x4      2.718074
Name: 95, dtype: float64
96 x1    117.663056
x2      3.255782
x3     39.143288
x4      2.993388
Name: 96, dtype: float64
97 x1    1268.722867
x2       1.545351
x3      17.300040
x4       2.875409
Name: 97, dtype: float64
98 x1    763.765273
x2      1.874043
x3     65.388955
x4      2.259460
Name: 98, dtype: float64
99 x1    419.782539
x2      2.429699
x3     23.686389
x4      1.789150
Name: 99, dtype: float64

In [ ]:
#jobs

The results


In [21]:
pd.DataFrame(results)


Out[21]:
y
0 2.972840e+09
1 2.972840e+09
2 2.972840e+09
3 -1.460854e+07
4 2.972840e+09
5 2.972840e+09
6 2.972840e+09
7 -1.460854e+07
8 2.972840e+09
9 2.972840e+09
10 2.972840e+09
11 -1.460854e+07
12 2.972840e+09
13 2.972840e+09
14 2.972840e+09
15 -1.460854e+07
16 2.972840e+09
17 2.972840e+09
18 2.972840e+09
19 -1.460854e+07
20 2.972840e+09
21 2.972840e+09
22 2.972840e+09
23 -1.460854e+07
24 2.972840e+09
25 2.972840e+09
26 2.972840e+09
27 -1.460854e+07
28 2.972840e+09
29 2.972840e+09
... ...
70 2.972840e+09
71 -1.460854e+07
72 2.972840e+09
73 2.972840e+09
74 2.972840e+09
75 -1.460854e+07
76 2.972840e+09
77 2.972840e+09
78 2.972840e+09
79 -1.460854e+07
80 2.972840e+09
81 2.972840e+09
82 2.972840e+09
83 -1.460854e+07
84 2.972840e+09
85 2.972840e+09
86 2.972840e+09
87 -1.460854e+07
88 2.972840e+09
89 2.972840e+09
90 2.972840e+09
91 -1.460854e+07
92 2.972840e+09
93 2.972840e+09
94 2.972840e+09
95 -1.460854e+07
96 2.972840e+09
97 2.972840e+09
98 2.972840e+09
99 -1.460854e+07

100 rows × 1 columns


In [ ]:


In [ ]: