Skip to content

Commit 69c5049

Browse files
committed
update tutorial due to change in interface
1 parent c0d0dfb commit 69c5049

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

docs/tutorials/trajectory-optimization/trajectory-optimization.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# Trajectory Optimization
22

3-
<div class="md-source-date"><small>Author: Zizhou Huang</small></div>
3+
<div class="md-source-date"><small>Author: Zizhou Huang, Date: Feb. 19, 2024</small></div>
44

55
In this tutorial, we will demonstrate how to use polyfem to optimize the initial velocity of throwing a ball to match a given trajectory.
66

77
<p float="left">
88
<img src="../sim.gif" width="60%" />
99
</p>
1010

11-
The data for this tutorial can be found [here](https://github.com/polyfem/polyfem-data/tree/main/multi-material).
12-
1311
## Prerequisites
1412

15-
The following items are necessary to complete this tutorial. To replicate the experiment, you can feel free to use either the given mesh files or your own mesh.
13+
The following items are necessary to complete this tutorial. To reproduce the experiment, you can feel free to use either the given mesh files or your own mesh.
1614

17-
- [ ] [Build PolyFEM](../../../cxx_index)
15+
- [ ] [Build PolyFEM](../../cxx_index)
1816
- [ ] [Download File: square.obj](https://github.com/polyfem/polyfem-data/blob/main/contact/meshes/2D/simple/square.obj)
1917
- [ ] [Download File: circle.msh](https://github.com/polyfem/polyfem-data/blob/main/differentiable/circle.msh)
2018
- [ ] [Download File: barycenter-opt.json](https://github.com/polyfem/polyfem-data/blob/main/differentiable/optimizations/initial-condition-trajectory-opt/barycenter-opt.json)
2119
- [ ] [Download File: barycenter.json](https://github.com/polyfem/polyfem-data/blob/main/differentiable/optimizations/initial-condition-trajectory-opt/barycenter.json)
2220
- [ ] [Download File: barycenter-target.json](https://github.com/polyfem/polyfem-data/blob/main/differentiable/optimizations/initial-condition-trajectory-opt/barycenter-target.json)
2321

22+
The files can also be found at [polyfem-data](https://github.com/polyfem/polyfem-data/blob/main/differentiable/optimizations/initial-condition-trajectory-opt/).
23+
2424
### Build PolyFEM
2525

26-
The instructions for building PolyFEM can be found [here](../../../cxx_index).
26+
The instructions for building PolyFEM can be found [here](../../cxx_index).
2727

2828
Then you can use it by
2929

@@ -33,7 +33,7 @@ polyfem --help
3333

3434
## Setting up the Optimization
3535

36-
We will setup the optimization using PolyFEM's JSON interface. For more details, please refer to the [JSON Input](../../../json) documentation.
36+
We will setup the optimization using PolyFEM's JSON interface. For more details, please refer to the [JSON Input](../../json.md) documentation.
3737

3838
We will only go over the JSON script for the optimization configuration, please refer to other tutorials for the JSON script for the simulation configuration.
3939

@@ -69,7 +69,7 @@ In more complex optimizations, where several types of parameters are optimized,
6969
}
7070
```
7171

72-
In `states`, we specify the path to the JSON files of simulations, they follow the same [rules](../../../json) for the simulation JSON scripts. PolyFEM will create a number of simulators, one for each JSON file, whose parameters can be optimized. During the optimization, certain parameters in these configurations are optimized, but the optimized values will not overwrite the values in these JSON files. Each simulator gets an ID starting from 0, following the order in this list. The ID of simulators may be used in `variable to simulation` and `functionals`.
72+
In `states`, we specify the path to the JSON files of simulations, they follow the same [rules](../../json.md) for the simulation JSON scripts. PolyFEM will create a number of simulators, one for each JSON file, whose parameters can be optimized. During the optimization, certain parameters in these configurations are optimized, but the optimized values will not overwrite the values in these JSON files. Each simulator gets an ID starting from 0, following the order in this list. The ID of simulators may be used in `variable to simulation` and `functionals`.
7373

7474
Here we have two simulators: The first one is the simulator being optimized, while the second one is a fixed simulation that generates a reference trajectory. These JSON files are only for initializing the simulators, so one can use the same path for multiple simulators if possible.
7575

@@ -104,7 +104,7 @@ The initial condition parameter has a dimension of `2 * dim * n_basis`, where `d
104104

105105
In this tutorial, we only optimize the initial velocity of the ball, so we need to build a mapping, which we call `composition` in the JSON script, from the variable of size 2 to the full initial condition parameter of size `2 * dim * n_basis`. The `composition` is a list of some pre-defined mappings, which will apply to the optimization variables in order, and the final output of the mappings will be assigned to the initial condition parameter.
106106

107-
There are two objects with different volume IDs, specified in `barycenter.json` and `barycenter-target.json`, and we only want to control the initial velocity of the ball, with volume ID 1. First, in `append-values` we append two zeros to the optimization variable, which represents the zero initial velocity of the floor. Second, in `per-body-to-per-node` we map the per-volume values to per-node, whose output has the dimension of `dim * n_basis`. Finally, in `append-const` we append more zeros to the start of the vector, to account for the zero initial displacement. Please refer to the [opt-input-spec.json](https://github.com/geometryprocessing/adjoint-polyfem/blob/shock/opt-input-spec.json) for the documentation of compositions.
107+
There are two objects with different volume IDs, specified in `barycenter.json` and `barycenter-target.json`, and we only want to control the initial velocity of the ball, with volume ID 1. First, in `append-values` we append two zeros to the optimization variable, which represents the zero initial velocity of the floor. Second, in `per-body-to-per-node` we map the per-volume values to per-node, whose output has the dimension of `dim * n_basis`. Finally, in `append-const` we append more zeros to the start of the vector, to account for the zero initial displacement. Please refer to the [opt-input-spec.json](https://github.com/polyfem/polyfem/blob/main/json-specs/opt-input-spec.json) for the documentation of compositions.
108108

109109
### Functionals
110110

@@ -127,7 +127,7 @@ There are two objects with different volume IDs, specified in `barycenter.json`
127127
}
128128
```
129129

130-
The `functionals` specify the objective being minimized in the optimization. Please refer to [objective-input-spec.json](https://github.com/geometryprocessing/adjoint-polyfem/blob/shock/objective-input-spec.json) for the documentation of `functionals`.
130+
The `functionals` specify the objective being minimized in the optimization. Please refer to [objective-input-spec.json](https://github.com/polyfem/polyfem/blob/main/json-specs/objective-spec.json) for the documentation of `functionals`.
131131

132132
Here we perform trajectory optimization on the ball, so the objective is the $L^2$ difference between the two ball barycenters in the two simulations, integrated over time.
133133

@@ -157,11 +157,13 @@ The `transient integral` computes the integral over time of the `static objectiv
157157

158158
```json
159159
"output": {
160-
"solve_log_level": 3
160+
"log": {
161+
"level": 1
162+
}
161163
}
162164
```
163165

164-
The `output` contains options regarding the logging of the optimization, here `solve_log_level` specifies a log level of 3, corresponding to `warning`, for simulations so that we can focus more on the optimization logs.
166+
The `output` contains options regarding the logging of the optimization, here `output/log/level` specifies a log level of 1, corresponding to `debugging`, to log the energy and gradient during the optimization. The log level for simulations are specified in each state json, normally the simulation log level is set to `info` or `warn` so that we can focus more on the optimization logs.
165167

166168
### Solver
167169

0 commit comments

Comments
 (0)