-
Notifications
You must be signed in to change notification settings - Fork 0
Structure of package_info.yaml
The package_info.yaml
file contains the configuration used to generate PyChaste wrappers. The cppwg tool (which generates the wrappers) inspects the contents of package_info.yaml
and uses this information to determine which C++ files to parse, which template parameter values to apply for explicit instantiation, and various other options that influence how the wrapper code is generated.
This page describes the structure of the package_info.yaml
configuration file. A list of keys at each level is provided and an explanation is given for how the generated wrapper code is affected by the values set for each key.
For guidance on creating PyChaste wrappers from the configuration file, see the documentation on generating bindings.
The top-level keys in package_info.yaml
are:
name
source_includes
smart_ptr_type
common_include_file
template_substitutions
pointer_call_policy
reference_call_policy
modules
Project name. Used as a prefix for Python-importable modules.
Example:
name: chaste_project_PyChaste
This will result in module names such as _chaste_project_PyChaste_cell_based
for the cell_based
module.
List of headers to be included in all C++ wrappers.
Example:
source_includes:
- <set>
- <vector>
- <string>
- <map>
- SmartPointers.hpp
- UblasIncludes.hpp
From the configuration above, the following will be added at the top of all wrapper code:
#include <set>
#include <vector>
#include <string>
#include <map>
#include "SmartPointers.hpp"
#include "UblasIncludes.hpp"
Default smart pointer type to be used with PYBIND11_DECLARE_HOLDER_TYPE
in all C++ wrappers:
Example:
smart_ptr_type: boost::shared_ptr
From the setting above, this will be be added in all wrapper code:
PYBIND11_DECLARE_HOLDER_TYPE(T, boost::shared_ptr<T>);
As part of the wrapper generation process, a wrapper_header_collection.hpp
file is created which contains headers, template instantiations, and typedefs needed for all wrappers. For example:
#include "ChastePoint.hpp"
#include "Node.hpp"
template class ChastePoint<2>;
template class ChastePoint<3>;
template class Node<2>;
template class Node<3>;
typedef ChastePoint<2> ChastePoint2;
typedef ChastePoint<3> ChastePoint3;
typedef Node<2> Node2;
typedef Node<3> Node3;
The common_include_file
key allows supplying the path to a manually created wrapper_header_collection.hpp
. Setting it to OFF
will cause the file to be generated automatically:
common_include_file: OFF
This specifies a list of signature
and replacement
pairs for explicitly instantiating all matching templates.
Example:
template_substitutions:
- signature: <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
replacement: [[2, 2], [3, 3]]
- signature: <unsigned DIM, unsigned DIM>
replacement: [[2, 2], [3, 3]]
- signature: <unsigned ELEMENT_DIM, unsigned SPACE_DIM=ELEMENT_DIM>
replacement: [[2, 2], [3, 3]]
- signature: <unsigned SPACE_DIM>
replacement: [[2], [3]]
- signature: <unsigned DIM>
replacement: [[2], [3]]
From the above settings, all templates which have the signature <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
will be explicitly instantiated in wrapper code with <2,2>
and <3,3>
, etc.
The default value of pybind11::return_value_policy
for pointers.
Example:
pointer_call_policy: reference
The default value of pybind11::return_value_policy
for references.
Example:
reference_call_policy: reference_internal
A list of Python modules to group the wrappers into.
- name
- source_locations
- classes
Example:
modules:
- name: core
source_locations: ...
classes: ...
- name: cell_based
source_locations: ...
classes: ...
The name of the module.
Example:
modules:
- name: core
Paths to source files to be included in the module
Example:
modules:
- name: core
source_locations:
- global/src
- io/src
- linalg/src
A list of classes to be wrapped into the module
Example:
modules:
- name: core
classes:
- name: Identifiable
- name: PetscTools
- name: ReplicatableVector
- name: Timer
- name: RelativeTo # enum
- name: FileFinder
- name: OutputFileHandler
- name: ProgressReporter
- name: RandomNumberGenerator
- name: TimeStepper
- name: ChasteBuildInfo
- name
- name_override
- constructor_arg_type_excludes
- custom_generator
- excluded_methods
- excluded_variables
- prefix_code
- source_file
- source_includes
- template_substitutions
The name of the class to wrap.
Example:
modules:
- name: mesh
classes:
- name: VertexMesh
A class name to be used in place of the original.
Example:
modules:
- name: mesh
classes:
- name: SharedPottsMeshGenerator
name_override: PottsMeshGenerator
The configuration above results in wrapper code such as:
typedef SharedPottsMeshGenerator<2> PottsMeshGenerator2;
pybind11::class_<PottsMeshGenerator2, ...>(m, "PottsMeshGenerator2").def(...);
List of constructor signatures to exclude from the wrapped class.
Example:
modules:
- name: mesh
classes:
- name: VertexMesh
constructor_arg_type_excludes:
- TetrahedralMesh<3, 3>
- TetrahedralMesh<2, 2>
Specifies the path to a custom script for generating wrappers for a class.
Example:
modules:
- name: cell_based
classes:
- name: CellsGenerator
custom_generator: CPPWG_SOURCEROOT/projects/PyChaste/dynamic/wrapper_generators/CellsGenerator_custom.py
CPPWG_SOURCEROOT
is a variable holding the path to the root directory of the source tree.
Class methods that should not be wrapped.
Example:
modules:
- name: core
classes:
- name: PetscTools
excluded_methods:
- GetWorld # MPI not wrapped here
- Destroy # No non-const ref to PETSc types
- ReadPetscObject
- SetupMat
Class variables that should not be wrapped. This setting currently does nothing as class variables are not wrapped.
Example:
modules:
- name: core
classes:
- name: PetscTools
excluded_variables:
- MASTER_RANK # MPI not wrapped here
Custom C++ code to place at the top of a class wrapper.
Example:
modules:
- name: core
classes:
- name: PetscTools
prefix_code:
- PYBIND11_MAKE_OPAQUE(Vec);
- PYBIND11_MAKE_OPAQUE(Mat);
Specifies the source file that contains the class definition. This is necessary if the filename does not match the class name.
Example:
modules:
- name: core
classes:
- name: ChasteBuildInfo
source_file: Version.hpp
A list of headers to be included in the C++ wrappers for this class.
Example:
modules:
- name: core
classes:
- name: PetscTools
source_includes:
- <petsc/private/vecimpl.h> # forward decl
- <petsc/private/matimpl.h> # forward decl
A list of explicit template instantiations to be made for this class.
Example:
modules:
- name: cell_based
classes:
- name: CellsGenerator
template_substitutions:
- signature: <class CELL_CYCLE_MODEL, unsigned DIM>
replacement:
- [NoCellCycleModel, 2]
- [NoCellCycleModel, 3]
- [UniformCellCycleModel, 2]
- [UniformCellCycleModel, 3]
- [SimpleOxygenBasedCellCycleModel, 2]
- [SimpleOxygenBasedCellCycleModel, 3]
- [UniformG1GenerationalCellCycleModel, 2]
- [UniformG1GenerationalCellCycleModel, 3]
- [BiasedBernoulliTrialCellCycleModel, 2]
- [BiasedBernoulliTrialCellCycleModel, 3]
- [LabelDependentBernoulliTrialCellCycleModel, 2]
- [LabelDependentBernoulliTrialCellCycleModel, 3]
The above configuration will instantiate templates such as CellsGenerator<NoCellCycleModel,2>
etc.