|
|
This is just a collection of ideas what to try.
|
|
|
Currently, we do not use a type registry, so each type should really be bound only once, everything else is a bug.
|
|
|
In my current example, when executing
|
|
|
```python
|
|
|
import dune.xt.functions
|
|
|
```
|
|
|
I get
|
|
|
```python
|
|
|
ImportError: ImportError: generic_type: type "GridFunctionInterface2dSimplexAlunonconformgridTo1d" is already registered!
|
|
|
```
|
|
|
|
|
|
# find the module which triggers the error
|
|
|
|
|
|
Running
|
|
|
```python
|
|
|
ipython --pdb -c "import dune.xt.functions"
|
|
|
```
|
|
|
I can step up once with `u` and then `print(mod_name)`, which gives:
|
|
|
```python
|
|
|
ipdb> print(mod_name)
|
|
|
_functions_checkerboard
|
|
|
```
|
|
|
Thus, importing `_functions_checkerboard.so` triggers the bindings of the `GridFunctionInterface2dSimplexAlunonconformgridTo1d`, while that one is supposed to happen somewhere else.
|
|
|
|
|
|
# look at the sources of the triggering `.so`
|
|
|
|
|
|
The `_functions_checkerboard` target is built by `python/dune/xt/functions/checkerboard.cc` (look at `python/dune/xt/functions/CMakeLists.txt` to find out).
|
|
|
We can see at the bottom, that it includes the respective dependencies
|
|
|
```cpp
|
|
|
py::module::import("dune.xt.common");
|
|
|
py::module::import("dune.xt.grid");
|
|
|
py::module::import("dune.xt.la");
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_1d");
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_2d");
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_3d");
|
|
|
```
|
|
|
and afterwards adds the checkerboard bindings
|
|
|
```cpp
|
|
|
CheckerboardFunction_for_all_grids<>::bind(m);
|
|
|
```
|
|
|
|
|
|
We can deduce that either one `_functions_interfaces_grid_function_?d` is the problem, or `CheckerboardFunction_for_all_grids`
|
|
|
|
|
|
# find the error
|
|
|
|
|
|
From here on, we can try different things which are equally likely to trigger the problem. So make your pick
|
|
|
|
|
|
## make sure the interface name is not used again in the function
|
|
|
|
|
|
Since the code to bind the checkerboard function is most likely copied from somewhere, the error might stem from leftovers.
|
|
|
Lets have a look at the name we use for the bound class, which is usually built at the beginning of the `bind` function (here the `bind` function of `Functions::bindings::CheckerboardFunction` in `python/dune/xt/functions/checkerboard.cc`):
|
|
|
```cpp
|
|
|
static bound_type bind(pybind11::module& m,
|
|
|
const std::string& grid_id = Grid::bindings::grid_name<G>::value(),
|
|
|
const std::string& layer_id = "",
|
|
|
const std::string& class_id = "checkerboard_function")
|
|
|
{
|
|
|
namespace py = pybind11;
|
|
|
using namespace pybind11::literals;
|
|
|
|
|
|
std::string class_name = class_id;
|
|
|
class_name += "_" + grid_id;
|
|
|
if (!layer_id.empty())
|
|
|
class_name += "_" + layer_id;
|
|
|
class_name += "_to_" + Common::to_string(r);
|
|
|
if (rC > 1)
|
|
|
class_name += "x" + Common::to_string(rC);
|
|
|
class_name += "d";
|
|
|
if (!std::is_same<R, double>::value)
|
|
|
class_name += "_" + Common::Typename<R>::value(/*fail_wo_typeid=*/true);
|
|
|
const auto ClassName = Common::to_camel_case(class_name);
|
|
|
bound_type c(m, ClassName.c_str(), Common::to_camel_case(class_id).c_str());
|
|
|
```
|
|
|
As we can see, the prefix of the class name comes from `const std::string& class_id = "checkerboard_function"`, which is not `grid_function_interface` (make sure the default argument is used by checking the `CheckerboardFunction_for_all_grids<>::bind(m);` call).
|
|
|
This would have been an easy mistake, if the copied over `bind` function still contained the `grid_function_interface` default argument.
|
|
|
But it does not, so the source of the error is most likely not here.
|
|
|
|
|
|
## ensure the offending code is somewhere else
|
|
|
|
|
|
Looking at the imports of other bindings, we note
|
|
|
```cpp
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_1d");
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_2d");
|
|
|
py::module::import("dune.xt.functions._functions_interfaces_grid_function_3d");
|
|
|
```
|
|
|
which might be the source of the error.
|
|
|
This is easily checked by running the imports in an ipython shell
|
|
|
```python
|
|
|
import dune.xt.functions._functions_interfaces_grid_function_1d
|
|
|
import dune.xt.functions._functions_interfaces_grid_function_2d
|
|
|
import dune.xt.functions._functions_interfaces_grid_function_3d
|
|
|
```
|
|
|
|
|
|
In our example, the first line already triggers the failure, so the actual problem is already in the `_functions_interfaces_grid_function_1d` target.
|
|
|
This is of course weird, since that target is supposed to bind the interface for 1d grids, while the name `GridFunctionInterface2dSimplexAlunonconformgridTo1d` suggest a 2d grid.
|
|
|
|
|
|
## start over
|
|
|
|
|
|
Now we more or less start the same process again, but using the `_functions_interfaces_grid_function_1d` target instead of `_functions_checkerboard`.
|
|
|
|
|
|
I will continue the concrete example but being more brief, the ideas are similar to above.
|
|
|
|
|
|
* look at `python/dune/xt/functions/CMakeLists.txt`
|
|
|
* find that the `_functions_interfaces_grid_function_1d` target is built by `python/dune/xt/functions/interfaces/grid-function_1d.cc`
|
|
|
|
|
|
### make sure we import the correct `.so`
|
|
|
|
|
|
* make some whitespace change to `python/dune/xt/functions/interfaces/grid-function_1d.cc`
|
|
|
* compile the `_functions_interfaces_grid_function_1d` target again
|
|
|
* go to the build dir, e.g. `cd envs/$DXT_ENVIRONMENT/build-$OPTS/dune-xt/python/dune/xt/functions`
|
|
|
* make sure there is something like `_functions_interfaces_grid_function_1d.cpython-38-x86_64-linux-gnu.so` with a recent date
|
|
|
* import the `.so` directly in that folder:
|
|
|
```python
|
|
|
python -c "import _functions_interfaces_grid_function_1d"
|
|
|
```
|
|
|
|
|
|
In my example, this works without error, *sigh*. |
|
|
\ No newline at end of file |