Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/config params #5

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions examples/example1.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
! does it submit to any jurisdiction.
program my_program

use iso_c_binding, only : c_null_char
use iso_c_binding, only : c_null_char, c_double
use plume_module
use atlas_module, only : atlas_Field, atlas_integer

Expand All @@ -28,6 +28,10 @@ program my_program
integer :: param_k = 100
type(atlas_Field) :: field

integer :: config_param_1 = 9
real(c_double) :: config_param_2 = 99.99
type(atlas_Field) :: config_param_3

integer :: iter

write(*,*) "*** Running Example 1 (Fortran interface) ***\n"
Expand All @@ -44,18 +48,30 @@ program my_program
call plume_check(offers%offer_int("K", "always", "this is param K"))
call plume_check(offers%offer_atlas_field("field_dummy_1", "always", "this is param K"))

call plume_check(offers%offer_int("config-param-1", "always", "this is param config-param-1"))
call plume_check(offers%offer_double("config-param-2", "always", "this is param config-param-2"))
call plume_check(offers%offer_atlas_field("config-param-3", "always", "this is param config-param-3"))

! negotiate
call plume_check(manager%initialise())
call plume_check(manager%configure(trim(plume_config_path)//c_null_char))
call plume_check(manager%negotiate(offers))

! fill in data
field = atlas_Field("field_dummy_1", atlas_integer(), (/0,10/))
config_param_3 = atlas_Field("config-param-3", atlas_integer(), (/0,10/))

call plume_check(data%initialise())
call plume_check(data%provide_int("I", param_i) )
call plume_check(data%provide_int("J", param_j) )
call plume_check(data%provide_int("K", param_k) )
field = atlas_Field("field_dummy_1", atlas_integer(), (/0,10/))
call plume_check( data%provide_atlas_field_shared("field_dummy_1", field) )
call plume_check(data%provide_atlas_field_shared("field_dummy_1", field) )

call plume_check(data%provide_int("config-param-1", config_param_1) )
call plume_check(data%provide_double("config-param-2", config_param_2) )
call plume_check(data%provide_atlas_field_shared("config-param-3", config_param_3) )



! pass data to the plugins
call plume_check(manager%feed_plugins(data))
Expand Down
12 changes: 12 additions & 0 deletions examples/example1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ int main(int argc, char** argv) {
offers.offerInt("J", "always", "this is param J");
offers.offerInt("K", "always", "this is param K");
offers.offerAtlasField("field_dummy_1", "always", "this is dummy_field");

offers.offerInt("config-param-1", "always", "this is param config-param-1");
offers.offerDouble("config-param-2", "always", "this is param config-param-2");
offers.offerAtlasField("config-param-3", "always", "this is param config-param-3");
plume::Manager::negotiate(offers);

// data
Expand All @@ -56,12 +60,20 @@ int main(int argc, char** argv) {
int param_k = 100;
atlas::Field field = createAtlasField();

int config_param_1 = 9;
double config_param_2 = 99.99;
atlas::Field config_param_3 = createAtlasField();

plume::data::ModelData data;
data.provideInt("I", &param_i);
data.provideInt("J", &param_j);
data.provideInt("K", &param_k);
data.provideAtlasFieldShared("field_dummy_1", field.get());

data.provideInt("config-param-1", &config_param_1);
data.provideDouble("config-param-2", &config_param_2);
data.provideAtlasFieldShared("config-param-3", config_param_3.get());

// Feed plugins with the data
plume::Manager::feedPlugins(data);

Expand Down
18 changes: 17 additions & 1 deletion examples/example2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
! does it submit to any jurisdiction.
program my_program

use iso_c_binding, only : c_bool, c_null_char
use iso_c_binding, only : c_bool, c_null_char, c_double
use plume_module
use atlas_module, only : atlas_Field, atlas_integer

Expand All @@ -27,6 +27,11 @@ program my_program
character(*), parameter :: field_name = "field_dummy_1"//c_null_char
type(atlas_Field) :: field

integer :: config_param_1 = 9
real(c_double) :: config_param_2 = 99.99
type(atlas_Field) :: config_param_3


logical(c_bool) :: is_param_requested
integer :: iter

Expand All @@ -45,6 +50,11 @@ program my_program
call plume_check(offers%offer_int("K", "always", "this is param K"))
call plume_check(offers%offer_atlas_field(field_name, "on-request", "this is an atlas field"))

call plume_check(offers%offer_int("config-param-1", "always", "this is param config-param-1"))
call plume_check(offers%offer_double("config-param-2", "always", "this is param config-param-2"))
call plume_check(offers%offer_atlas_field("config-param-3", "always", "this is param config-param-3"))


! negotiate
call plume_check(manager%initialise())
call plume_check(manager%configure(trim(plume_config_path)//c_null_char))
Expand All @@ -70,6 +80,12 @@ program my_program
call plume_check( data%provide_atlas_field_shared(field_name, field) )
endif

config_param_3 = atlas_Field("config-param-3", atlas_integer(), (/0,10/))
call plume_check(data%provide_int("config-param-1", config_param_1) )
call plume_check(data%provide_double("config-param-2", config_param_2) )
call plume_check(data%provide_atlas_field_shared("config-param-3", config_param_3) )


call plume_check(data%print())

! pass data to the plugins
Expand Down
39 changes: 34 additions & 5 deletions examples/example2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ int main(int argc, char** argv) {
offers.offerInt("I", "always", "this is param I");
offers.offerInt("J", "always", "this is param J");
offers.offerInt("K", "always", "this is param K");

offers.offerAtlasField("field_dummy_1", "on-request", "this is dummy_field");

offers.offerInt("config-param-1", "on-request", "this is param config-param-1");
offers.offerDouble("config-param-2", "on-request", "this is param config-param-2");
offers.offerAtlasField("config-param-3", "on-request", "this is param config-param-3");

plume::Manager::negotiate(offers);

// data
int param_i = 0;
int param_j = 10;
int param_k = 100;
atlas::Field field_dummy;

int config_param_1 = 9;
double config_param_2 = 99.99;
atlas::Field config_param_3;

plume::data::ModelData data;

// Insert some int parameters (regardless of whether
Expand All @@ -69,12 +81,29 @@ int main(int argc, char** argv) {
// => This information can be used to insert "on-request" params
// (i.e parameters that are inserted only if requested by plugins)
//
// For example, if "field_dummy_1" has been requested, then insert it:
std::string name = "field_dummy_1";
atlas::Field field;
// For example, if "field_dummy_1" has been requested, then insert it:
std::string name;

name = "field_dummy_1";
if ( plume::Manager::isParamRequested(name) ) {
field_dummy = createAtlasField(name);
data.provideAtlasFieldShared(name, field_dummy.get());
}

name = "config-param-1";
if ( plume::Manager::isParamRequested(name) ) {
data.provideInt(name, &config_param_1);
}

name = "config-param-2";
if ( plume::Manager::isParamRequested(name) ) {
data.provideDouble(name, &config_param_2);
}

name = "config-param-3";
if ( plume::Manager::isParamRequested(name) ) {
field = createAtlasField(name);
data.provideAtlasFieldShared(name, field.get());
config_param_3 = createAtlasField(name);
data.provideAtlasFieldShared(name, config_param_3.get());
}

// Once data is ready.. feed the plugins!
Expand Down
166 changes: 91 additions & 75 deletions examples/example3.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,94 @@
! does it submit to any jurisdiction.
program my_program

use iso_c_binding, only : c_null_char
use plume_module
use atlas_module, only : atlas_Field, atlas_integer


implicit none

character(1024) :: plume_config_path

! plume structures
type(plume_protocol) :: offers
type(plume_manager) :: manager
type(plume_data) :: data

! data
type(atlas_Field) :: field

integer :: iter

write(*,*) "*** Running Example 3 (Fortran interface) ***\n"

CALL get_command_argument(1, plume_config_path)

! init
call plume_check(plume_initialise())

! make offers
call plume_check(offers%initialise())
call plume_check(offers%offer_int("I", "always", "this is param I"))
call plume_check(offers%offer_int("J", "always", "this is param J"))
call plume_check(offers%offer_int("K", "always", "this is param K"))
call plume_check(offers%offer_atlas_field("field_dummy_1", "always", "this is param K"))

! negotiate
call plume_check(manager%initialise())
call plume_check(manager%configure(trim(plume_config_path)//c_null_char))
call plume_check(manager%negotiate(offers))

! fill in data
call plume_check(data%initialise())

! make space for new parameters in the data
call plume_check(data%create_int("I", 0) )
call plume_check(data%create_int("J", 10) )
call plume_check(data%create_int("K", 100) )

field = atlas_Field("field_dummy_1", atlas_integer(), (/0,10/))
call plume_check( data%provide_atlas_field_shared("field_dummy_1", field) )

! pass data to the plugins
call plume_check(manager%feed_plugins(data))

! Run the model for 10 iterations
do iter=1,10

! update the internal parameters
call plume_check(data%update_int("I", 0+iter) )
call plume_check(data%update_int("J", 10+iter) )
call plume_check(data%update_int("K", 100+iter) )

! run the model..
call plume_check(manager%run())
enddo

! finalise
call plume_check(data%finalise())
call plume_check(manager%finalise())
call plume_check(offers%finalise())
call plume_check(plume_finalise())

write(*,*) "*** Example 3 complete. ***"
write(*,*)

end program

use iso_c_binding, only : c_null_char, c_double
use plume_module
use atlas_module, only : atlas_Field, atlas_integer


implicit none

character(1024) :: plume_config_path

! plume structures
type(plume_protocol) :: offers
type(plume_manager) :: manager
type(plume_data) :: data

! data
type(atlas_Field) :: field

integer :: config_param_1 = 9
real(c_double) :: config_param_2 = 99.99
type(atlas_Field) :: config_param_3


integer :: iter

write(*,*) "*** Running Example 3 (Fortran interface) ***\n"

CALL get_command_argument(1, plume_config_path)

! init
call plume_check(plume_initialise())

! make offers
call plume_check(offers%initialise())
call plume_check(offers%offer_int("I", "always", "this is param I"))
call plume_check(offers%offer_int("J", "always", "this is param J"))
call plume_check(offers%offer_int("K", "always", "this is param K"))
call plume_check(offers%offer_atlas_field("field_dummy_1", "always", "this is param K"))

call plume_check(offers%offer_int("config-param-1", "always", "this is param config-param-1"))
call plume_check(offers%offer_double("config-param-2", "always", "this is param config-param-2"))
call plume_check(offers%offer_atlas_field("config-param-3", "always", "this is param config-param-3"))


! negotiate
call plume_check(manager%initialise())
call plume_check(manager%configure(trim(plume_config_path)//c_null_char))
call plume_check(manager%negotiate(offers))

! fill in data
call plume_check(data%initialise())

! make space for new parameters in the data
call plume_check(data%create_int("I", 0) )
call plume_check(data%create_int("J", 10) )
call plume_check(data%create_int("K", 100) )

field = atlas_Field("field_dummy_1", atlas_integer(), (/0,10/))
call plume_check( data%provide_atlas_field_shared("field_dummy_1", field) )

! Some more parameters that will be requested through the configuration
config_param_3 = atlas_Field("config-param-3", atlas_integer(), (/0,10/))
call plume_check(data%provide_int("config-param-1", config_param_1) )
call plume_check(data%provide_double("config-param-2", config_param_2) )
call plume_check(data%provide_atlas_field_shared("config-param-3", config_param_3) )


! pass data to the plugins
call plume_check(manager%feed_plugins(data))

! Run the model for 10 iterations
do iter=1,10

! update the internal parameters
call plume_check(data%update_int("I", 0+iter) )
call plume_check(data%update_int("J", 10+iter) )
call plume_check(data%update_int("K", 100+iter) )

! run the model..
call plume_check(manager%run())
enddo

! finalise
call plume_check(data%finalise())
call plume_check(manager%finalise())
call plume_check(offers%finalise())
call plume_check(plume_finalise())

write(*,*) "*** Example 3 complete. ***"
write(*,*)

end program my_program
16 changes: 16 additions & 0 deletions examples/example3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ int main(int argc, char** argv) {
offers.offerInt("J", "always", "this is param J");
offers.offerInt("K", "always", "this is param K");
offers.offerAtlasField("field_dummy_1", "always", "this is dummy_field");

offers.offerInt("config-param-1", "on-request", "this is param config-param-1");
offers.offerDouble("config-param-2", "on-request", "this is param config-param-2");
offers.offerAtlasField("config-param-3", "on-request", "this is param config-param-3");

// Negotiate with plugins
plume::Manager::negotiate(offers);

// data
Expand All @@ -60,6 +66,16 @@ int main(int argc, char** argv) {
data.createInt("K", 100);
data.provideAtlasFieldShared("field_dummy_1", field.get());


// parameters requested by the plugins through configuration
int config_param_1 = 9;
double config_param_2 = 99.99;
atlas::Field config_param_3 = createAtlasField();

data.provideInt("config-param-1", &config_param_1);
data.provideDouble("config-param-2", &config_param_2);
data.provideAtlasFieldShared("config-param-3", config_param_3.get());

// Feed plugins with the data
plume::Manager::feedPlugins(data);

Expand Down
Loading
Loading