"Then we need to create a new class that inherets from the class `RunSimulator` and override the abstract method `simulator()`. The `simulator()` method cannot have any positional-only arguments and it has to return the results in form of a numpy array.\n",
"Then we need to create a new class that inherets from the class `RunSimulator` and override the abstract method `simulator()`. The `simulator()` method cannot have any positional-only arguments, has to contain the `**kwargs` argument and it has to return the results in form of a numpy array.\n",
"\n",
"Here we're going to use the function `mpmsolver` from the module `psimpy.simulator.mass_point_model` as our simulator. `mpmsolver()` solves the mass point model using the ode solver `scipy.integrate.ode` given following inputs: topography, friction parameters, and initial condition of the mass point (location and velocity).\n",
"Here we're going to use the method `run` of the class `MPM` from the module `psimpy.simulator.mass_point_model` as our simulator. This method solves the mass point model using the ode solver `scipy.integrate.ode` given following inputs: topography, friction parameters, and initial condition of the mass point (location and velocity).\n",
"\n",
"Therefore, we define the child class `MpmSolve` and override the `simulator()` method in order to return the outputs of the function `mpmsolver()`. "
"To do this, we first define the child class `MpmSolver`, override the `__init__` method to create a new instance of `MPM`, then we override the `simulator()` method in order to return the outputs of the method `run()` from the `MPM` class. "
"Now we can create a new instance of `MpmSolve`. In order to initialize `MpmSolve`, which has the same `__init__()` method as `RunSimulator`, the user needs to define the parent folder to save simulation outputs `sim_dir`, a list consists of all variable input names `var_inp_name` and a dictionary consists of all fixed input name-value pairs `fix_inp`."
"Now we can create a new instance of `MpmSolver`. In order to initialize `MpmSolver`, which has the same `__init__()` method as `RunSimulator`, the user needs to define the parent folder to save simulation outputs `sim_dir`, a list consists of all variable input names `var_inp_name` and a dictionary consists of all fixed input name-value pairs `fix_inp`."
"`mu` and `xi` are variable inputs and the other inputs are fixed. We may vary `mu` between 0.1 to 0.3 and `xi` between 500 to 2000."
"`coulomb_friction` and `turbulent_friction` are variable inputs and the other inputs are fixed. We may vary `coulomb_friction` between 0.1 to 0.3 and `turbulent_friction` between 500 to 2000."
]
},
{
...
...
@@ -107,10 +120,10 @@
"import numpy as np\n",
"import itertools\n",
"\n",
"mu = np.arange(0.1, 0.30, 0.05)\n",
"xi = np.arange(500, 2000, 150)\n",
"cf = np.arange(0.1, 0.3, 0.05)\n",
"tf = np.arange(500, 2000, 150)\n",
"\n",
"var_samples = np.array([x for x in itertools.product(mu, xi)])"
"var_samples = np.array([x for x in itertools.product(cf, tf)])"
]
},
{
...
...
@@ -119,7 +132,7 @@
"metadata": {},
"source": [
"## Serial Execution\n",
"In order to perform a serial execution of the simulator, we need to pass `var_samples` to the `serial_run()` method. The user can also specify optional arguments like `append` and `save_out`."
"In order to perform a serial execution of the simulator, we need to pass `var_samples` to the `serial_run()` method. The user can also specify optional arguments like `prefixes`, `append` or `save_out`. Here we like to save the results with the \"serial\" prefixes."
]
},
{
...
...
@@ -129,7 +142,9 @@
"metadata": {},
"outputs": [],
"source": [
"mpm.serial_run(var_samples=var_samples)"
"serial_prefixes = [\"serial\"+str(i) for i in range(len(var_samples))]\n",
"To check the results one could either check `mpm.outputs` or load the files available in `sim_dir`.\n",
"To check the results one could either check `mpmsolver.outputs` or load the files available in `sim_dir`.\n",
"\n",
"## Parallel Execution\n",
"Now let's run the same simulator in parallel. Once again we prepare samples of the variable inputs."
...
...
@@ -150,10 +165,10 @@
"metadata": {},
"outputs": [],
"source": [
"mu = np.arange(0.1, 0.30, 0.04)\n",
"xi = np.arange(500, 2000, 100)\n",
"cf = np.arange(0.1, 0.30, 0.04)\n",
"tf = np.arange(500, 2000, 100)\n",
"\n",
"var_samples = np.array([x for x in itertools.product(mu, xi)])"
"var_samples = np.array([x for x in itertools.product(cf, tf)])"
]
},
{
...
...
@@ -161,7 +176,7 @@
"id": "c87aeaf8",
"metadata": {},
"source": [
"This time we will pass the first 40 samples and then append the rest. We can also specify the maximum number of tasks running in parallel `max_workers` as well as `append` and `save_out`."
"This time we will pass the first 40 samples and then append the rest. We can also specify the maximum number of tasks running in parallel `max_workers` as well as `prefixes`, `append` and `save_out`."
Then we need to create a new class that inherets from the class `RunSimulator` and override the abstract method `simulator()`. The `simulator()` method cannot have any positional-only arguments and it has to return the results in form of a numpy array.
Then we need to create a new class that inherets from the class `RunSimulator` and override the abstract method `simulator()`. The `simulator()` method cannot have any positional-only arguments, has to contain the `**kwargs` argument and it has to return the results in form of a numpy array.
Here we're going to use the function `mpmsolver` from the module `psimpy.simulator.mass_point_model` as our simulator. `mpmsolver()` solves the mass point model using the ode solver `scipy.integrate.ode` given following inputs: topography, friction parameters, and initial condition of the mass point (location and velocity).
Here we're going to use the method `run` of the class `MPM` from the module `psimpy.simulator.mass_point_model` as our simulator. This method solves the mass point model using the ode solver `scipy.integrate.ode` given following inputs: topography, friction parameters, and initial condition of the mass point (location and velocity).
Therefore, we define the child class `MpmSolve` and override the `simulator()` method in order to return the outputs of the function `mpmsolver()`.
To do this, we first define the child class `MpmSolver`, override the `__init__` method to create a new instance of `MPM`, then we override the `simulator()` method in order to return the outputs of the method `run()` from the `MPM` class.
Now we can create a new instance of `MpmSolve`. In order to initialize `MpmSolve`, which has the same `__init__()` method as `RunSimulator`, the user needs to define the parent folder to save simulation outputs `sim_dir`, a list consists of all variable input names `var_inp_name` and a dictionary consists of all fixed input name-value pairs `fix_inp`.
Now we can create a new instance of `MpmSolver`. In order to initialize `MpmSolver`, which has the same `__init__()` method as `RunSimulator`, the user needs to define the parent folder to save simulation outputs `sim_dir`, a list consists of all variable input names `var_inp_name` and a dictionary consists of all fixed input name-value pairs `fix_inp`.
`mu` and `xi` are variable inputs and the other inputs are fixed. We may vary `mu` between 0.1 to 0.3 and `xi` between 500 to 2000.
`coulomb_friction` and `turbulent_friction` are variable inputs and the other inputs are fixed. We may vary `coulomb_friction` between 0.1 to 0.3 and `turbulent_friction` between 500 to 2000.
In order to perform a serial execution of the simulator, we need to pass `var_samples` to the `serial_run()` method. The user can also specify optional arguments like `append`and`save_out`.
In order to perform a serial execution of the simulator, we need to pass `var_samples` to the `serial_run()` method. The user can also specify optional arguments like `prefixes`, `append`or`save_out`. Here we like to save the results with the "serial" prefixes.
This time we will pass the first 40 samples and then append the rest. We can also specify the maximum number of tasks running in parallel `max_workers` as well as `append` and `save_out`.
This time we will pass the first 40 samples and then append the rest. We can also specify the maximum number of tasks running in parallel `max_workers` as well as `prefixes`, `append` and `save_out`.