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

Refactor ManifoldsBase to a two-level dispatch design #91

Merged
merged 177 commits into from
Feb 3, 2022
Merged
Changes from 1 commit
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
7295ec0
Sketch the new design in the Readme.
kellertuer Dec 15, 2021
78c4026
Apply suggestions from code review
kellertuer Dec 16, 2021
d9e60ff
Add documenter Workflow start transferring content from interface.md
kellertuer Dec 16, 2021
5550510
Sketching a little bit the new structure (still a lot of broken links).
kellertuer Dec 16, 2021
6990bfd
Fix most links (by e.g. removing a few links over to Manifolds).
kellertuer Dec 16, 2021
fbe450c
runs formatter.
kellertuer Dec 16, 2021
0e53e3c
write the first test with the retractions and finish the design docs.
kellertuer Dec 18, 2021
10acfb2
move the documenter workflow into the right place.
kellertuer Dec 18, 2021
d080fef
Reduce Ambiguities on 1.7 also to 2.
kellertuer Dec 18, 2021
512d16a
Add Project for documenter.
kellertuer Dec 18, 2021
22827cd
finish inverse retract lower level.
kellertuer Dec 18, 2021
262e35b
Apply suggestions from code review
kellertuer Dec 19, 2021
041855c
Apply suggestions from code review
kellertuer Dec 19, 2021
ae2a6cd
Merge branch 'kellertuer/two-level-refactor' of github.com:JuliaManif…
kellertuer Dec 19, 2021
cd8ee89
Further to nbew scheme
kellertuer Dec 20, 2021
79af4dc
introduce more functions now that we first clear retractions before g…
kellertuer Dec 20, 2021
891f5d7
Sketch Vector transport.
kellertuer Dec 20, 2021
86eea36
sketch of the high level with traits, remove old decorator - sketch m…
kellertuer Dec 21, 2021
762bb27
Rewrite docs to document the three layer design.
kellertuer Dec 22, 2021
db40e6e
speficy where mutating/allocating is combined, unify retraction defin…
kellertuer Dec 22, 2021
8929791
Unify vector transport to new 3-layer approach
kellertuer Dec 22, 2021
b79a4b3
refactor basis functions.
kellertuer Dec 22, 2021
ba5f595
Export Layer 3 functions, fix more tests.
kellertuer Dec 22, 2021
9649b4e
KNuffling around with bases real dimension and number of coordinates,…
kellertuer Dec 23, 2021
8cb9ca2
Finish debugging for today, since I am getting a headache. We have sa…
kellertuer Dec 23, 2021
d270b73
Fix ValidationManifold.
kellertuer Dec 23, 2021
2ce6b10
Finish debugging for today.
kellertuer Dec 23, 2021
479a703
minor fixes for bases
mateuszbaran Dec 23, 2021
ad0b21b
Merge branch 'kellertuer/two-level-refactor' of github.com:JuliaManif…
kellertuer Dec 23, 2021
446bd34
fixing basis tests
mateuszbaran Dec 23, 2021
3598bac
fixing some vector transports
mateuszbaran Dec 23, 2021
2d7564c
remove 2 ambiguities
kellertuer Dec 24, 2021
e350454
Reduce further problems, facing a next one.
kellertuer Dec 24, 2021
2e3a834
same code, just reduced space.
kellertuer Dec 24, 2021
d70061b
Hm, this defines functions but they are not called yet?
kellertuer Dec 24, 2021
bbefb16
This seems to nearly work, though I do not know why I need the brackets
kellertuer Dec 25, 2021
25d1b51
run formatter.
kellertuer Dec 25, 2021
56a2bfd
Removes artificial PowerVectorTransport since we do not have that amb…
kellertuer Dec 25, 2021
f091b21
Just a few Power errors left.
kellertuer Dec 25, 2021
d413710
Fixes more errors.
kellertuer Dec 25, 2021
f6aa8c4
just a few get vector errors left
kellertuer Dec 25, 2021
f41546b
Consistently name coordinates c and introduce a consistent way of acc…
kellertuer Dec 25, 2021
8b7ed9f
Sketch the new decorator and adapt embedded manifold
kellertuer Dec 25, 2021
87c2151
raiser ambiguities temporarily.
kellertuer Dec 25, 2021
3f19fe3
Reduce ambituigies.
kellertuer Dec 25, 2021
39c783a
remove the Manifold function not implemented – since all of these are…
kellertuer Dec 26, 2021
fb37b20
reintroduce embedded tests, document decorator.
kellertuer Dec 26, 2021
045e12f
Starts introducing and documenting the new Trait system.
kellertuer Dec 28, 2021
f445887
improving decorator traits
mateuszbaran Dec 28, 2021
88c8138
base_trait -> active_traits
mateuszbaran Dec 28, 2021
05b829e
Move nested trait to a separate file.
kellertuer Dec 28, 2021
e928567
tries to adapt the first function.
kellertuer Dec 28, 2021
eb94ea2
fixing some issues
mateuszbaran Dec 28, 2021
49c9dc9
fixing issues with embedded manifold
mateuszbaran Dec 29, 2021
1a38bab
EmbeddedManifold passess all tests now
mateuszbaran Dec 29, 2021
87f90a6
a better fix for EmbedededManifold
mateuszbaran Dec 29, 2021
1238ed3
Refactor to new scheme, remove Simple-traits dependency.
kellertuer Dec 30, 2021
dfdfdfa
Fixes a few bugs.
kellertuer Dec 30, 2021
3fef764
Forgot to remove a print.
kellertuer Dec 30, 2021
c9a3737
fixing some problems with embedded manifolds
mateuszbaran Dec 30, 2021
60f652d
introduce `next_trait` to iterate over traits
mateuszbaran Dec 30, 2021
0847529
Adapt a few tests, now all work as expected.
kellertuer Dec 30, 2021
23d6886
Fix a few bugs and increase code coverage.
kellertuer Dec 30, 2021
dfb8c29
repair the two broken tests - which is really easy in the new scheme.
kellertuer Dec 30, 2021
36682e7
Unify naming, adds a few tests.
kellertuer Dec 30, 2021
e810e0f
increase decorator trait tests.
kellertuer Dec 31, 2021
2449456
Test and debug Vector transport.
kellertuer Dec 31, 2021
f1f0ab6
Update CI, fix some minor further tests.
kellertuer Dec 31, 2021
094828d
Fix Diagonalizing basis, add a test.
kellertuer Dec 31, 2021
4bade4b
Fix Bases.
kellertuer Dec 31, 2021
f934f8f
Add coverage repots for Julia 1.0
kellertuer Dec 31, 2021
4da2560
Finish (hopefully) Testing for embedded and validation manifolds and …
kellertuer Dec 31, 2021
a49cc39
Increase power manifold cover.
kellertuer Jan 1, 2022
abebe94
Remove PowerRetraction and its inverse. Increase code cov.
kellertuer Jan 2, 2022
d2fadf9
Test further fallbacks.
kellertuer Jan 2, 2022
c248955
Codecov for bases.
kellertuer Jan 2, 2022
3516020
Fix string indent after reformating / grouping bases tests.
kellertuer Jan 2, 2022
1a463fd
runs formatter.
kellertuer Jan 2, 2022
142aefb
invoke_maker coverage
mateuszbaran Jan 2, 2022
8ee4132
hopefully improving coverage
mateuszbaran Jan 2, 2022
778fd9c
test and formatting
mateuszbaran Jan 2, 2022
af6fac8
add a few tests for traits.
kellertuer Jan 2, 2022
9e84eb3
Merge branch 'kellertuer/two-level-refactor' of github.com:JuliaManif…
kellertuer Jan 2, 2022
345d6e2
bump version, introduce retraction and inverse retraction types alrea…
kellertuer Jan 2, 2022
7d65884
Introduce meta retractions that employ retractions in the embedding a…
kellertuer Jan 2, 2022
1f446e3
Fix Docs and test cov.
kellertuer Jan 2, 2022
7081941
runs formatter.
kellertuer Jan 2, 2022
306626f
Increase code cov.
kellertuer Jan 2, 2022
78557fc
Fixes a signature type.
kellertuer Jan 2, 2022
a7c096f
Apply suggestions from code review
kellertuer Jan 2, 2022
e524a29
Apply suggestions from code review
kellertuer Jan 2, 2022
ff1de95
Apply suggestions from code review
kellertuer Jan 2, 2022
dc1057e
don't put imports in a macro
mateuszbaran Jan 2, 2022
feedffe
Merge branch 'kellertuer/two-level-refactor' of https://github.com/Ju…
mateuszbaran Jan 2, 2022
2d686eb
Update / Fix readme.
kellertuer Jan 3, 2022
3dbf17f
Remove level 3 functions from exports.
kellertuer Jan 3, 2022
7156672
Some work on the docs.
kellertuer Jan 3, 2022
181a812
remove more layer-3 functions.
kellertuer Jan 3, 2022
fc01ed8
Fix a few tests.
kellertuer Jan 3, 2022
f7549d4
`trait_function` macro and bugfixing
mateuszbaran Jan 3, 2022
3ead627
improve coverage
mateuszbaran Jan 3, 2022
a0759ce
Refactor parallel transport to be as important as exp and log. Adapt …
kellertuer Jan 4, 2022
4e8da84
Fix tests to at least run again.
kellertuer Jan 4, 2022
2ff31b0
test direction similar to along and to.
kellertuer Jan 4, 2022
cba6f10
Set parallel transport functions to be traits as well.
kellertuer Jan 5, 2022
b4c4aa6
Increase code coverage.
kellertuer Jan 5, 2022
e8362b5
Some work on the docs.
kellertuer Jan 5, 2022
8496031
Work on the docs
kellertuer Jan 6, 2022
4391cab
Finish the last coding for this feature – pass through macro for all …
kellertuer Jan 7, 2022
daf5c53
Add a zenodo metadata file.
kellertuer Jan 7, 2022
5484def
`trait_function` defines method for `EmptyTrait`
mateuszbaran Jan 7, 2022
6653aed
Apply suggestions from code review
kellertuer Jan 7, 2022
11a1f7b
Rephrase the intro.
kellertuer Jan 7, 2022
454718e
adds a logo idea.
kellertuer Jan 8, 2022
6dfcc0a
Increase code coverage.
kellertuer Jan 8, 2022
feb53db
forgot a final formatter.
kellertuer Jan 8, 2022
7a8f6c4
mutating functions also covered.
kellertuer Jan 8, 2022
819beda
Further tests and improvements on coverage
kellertuer Jan 8, 2022
10edd92
fixes a few variables.
kellertuer Jan 8, 2022
a0c14c7
fixes a stupid typo.
kellertuer Jan 8, 2022
2d71127
Extends the tutorial.
kellertuer Jan 8, 2022
be55c6a
fix a markdown typo.
kellertuer Jan 8, 2022
02ccc8c
fix another typo.
kellertuer Jan 8, 2022
2fa2593
fix the example,
kellertuer Jan 8, 2022
730900b
increase code coverage.
kellertuer Jan 9, 2022
133e0dd
Add new logo to docs and readme.
kellertuer Jan 9, 2022
4dc746a
switch to new logo link (that will work on master).
kellertuer Jan 9, 2022
4ff3a0b
add uncached bases again.
kellertuer Jan 9, 2022
76b5aab
runs formatter.
kellertuer Jan 9, 2022
446bede
Adds a retraction to vector transport to and direction to specify the…
kellertuer Jan 12, 2022
0ef4d02
fix one of the diff interfaces.
kellertuer Jan 12, 2022
a53e5ee
fixes an errornous allocate
kellertuer Jan 12, 2022
c0e545c
Fixes a few typos.
kellertuer Jan 13, 2022
6da1559
fixes a typo.
kellertuer Jan 13, 2022
07b07f6
`NestedTrait` -> `TraitList`
mateuszbaran Jan 13, 2022
dd7cf25
split obtaining the decorating manifold and the decorated manifold in…
kellertuer Jan 15, 2022
550a9f0
Remove the get_decorator function since not every decorator is a mani…
kellertuer Jan 15, 2022
b39fa45
runs formatter, fix is_point
kellertuer Jan 15, 2022
0274fe1
runs formatter again.
kellertuer Jan 15, 2022
9d744a8
Fix embed by using the allocating variant (in definition) since the o…
kellertuer Jan 16, 2022
2e1bbb2
two missing type annotations
mateuszbaran Jan 17, 2022
2534edd
diagonalizing basis nonmutating -> mutating
mateuszbaran Jan 17, 2022
c35380c
small fix
mateuszbaran Jan 17, 2022
56dbe37
Update src/bases.jl
kellertuer Jan 17, 2022
cb79936
Remove the double Manifold in a trait.
kellertuer Jan 17, 2022
91400f6
Merge branch 'kellertuer/two-level-refactor' of github.com:JuliaManif…
kellertuer Jan 17, 2022
da2cf7e
runs formatter
kellertuer Jan 17, 2022
1870e61
increase code cov.
kellertuer Jan 17, 2022
c8e9299
increase code cov further.
kellertuer Jan 17, 2022
4cf729b
make `active_traits` dependent on function
mateuszbaran Jan 17, 2022
6860cb9
generalize the EmptyTrait fallback to call first arguments supertype.
kellertuer Jan 18, 2022
02b7b32
unify vector transport.
kellertuer Jan 19, 2022
fce3c7b
finish unifying method to m, midpoint now mp.
kellertuer Jan 19, 2022
2bd6204
generalize projection vector transport
mateuszbaran Jan 20, 2022
27acb88
zero_vector forwarding
mateuszbaran Jan 20, 2022
f1757e9
generalize zero_vector forwarding
mateuszbaran Jan 20, 2022
d084f8c
formatting
mateuszbaran Jan 20, 2022
2633783
Fix a few diff dispatches in VT.
kellertuer Jan 21, 2022
bf5f08a
Fix a few diff dispatches in VT.
kellertuer Jan 21, 2022
ee5d596
Merge branch 'kellertuer/two-level-refactor' of github.com:JuliaManif…
kellertuer Jan 21, 2022
b0c719b
Set retraction to be implicit again but introduces VectorTransportTo …
kellertuer Jan 22, 2022
a8e1002
Polishing and exporting.
kellertuer Jan 22, 2022
e6fad77
missed one R.
kellertuer Jan 22, 2022
a114ab0
Runs formatter.
kellertuer Jan 22, 2022
d50da2e
Propose a default fallback to a field (nearly similar but more fleixi…
kellertuer Jan 22, 2022
0c4bbad
add tests for the new fallbacks
kellertuer Jan 22, 2022
5e15ec5
another run of formatter.
kellertuer Jan 22, 2022
5773d17
add mutating tests.
kellertuer Jan 22, 2022
a34ac12
use check_size more persistently.
kellertuer Jan 25, 2022
16d6bcf
avoid double definition.
kellertuer Jan 25, 2022
6e1862d
switch to decorated maniold, though this breaks the current divide.
kellertuer Jan 25, 2022
e312d3e
Code coverage for more thorough check size tests and the explicit fal…
kellertuer Jan 25, 2022
7218bdc
base_manifold -> decorated_manifold
mateuszbaran Jan 26, 2022
2fd3fa8
forwarding of basis-related functions
mateuszbaran Jan 27, 2022
3fd9d8e
tests and removal of incorrect code
mateuszbaran Jan 27, 2022
8aa2949
`representation_size` forwarding
mateuszbaran Jan 28, 2022
4693976
introduce an optional parameter for `get_embedding` so it might depen…
kellertuer Jan 29, 2022
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
118 changes: 103 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,93 @@ Basic interface for manifolds in Julia.
The project [`Manifolds.jl`](https://github.com/JuliaManifolds/Manifolds.jl)
is based on this interface and provides a variety of manifolds.

## Number system
## Main types

A number system represents the field a manifold is based upon.
Most prominently, these are real-valued (`ℝ`) and complex valued (`ℂ`) fields that
parametrize certain manifolds.
A further type to represent the field of quaternions (`ℍ`) can also be used.
This packages provides an [`AbstractManifold`](https://juliamanifolds.github.io/Manifolds.jl/stable/interface.html#ManifoldsBase.AbstractManifold) type, that is parametrized by its field, i.e., whether elements on the manifold are real (`ℝ`) or complex (`ℂ`) or even quaternions (`ℍ`).
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
A manifold is a set of points. These are usually represented by (real-, complex-, quarternion-) valued arrays, most prominently matrices.
Sometimes they are also vectors or tensors.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
For more advanced points, you can also use subtypes [`AbstractManifoldPoint`](https://juliamanifolds.github.io/Manifolds.jl/latest/interface.html#ManifoldsBase.AbstractManifoldPoint).
Sometimes points on a manifold can be represented in different forms.
While a first (default) representation can use just arrays, any further representation _must_ use a subtype to dispatch on. Then the default case can (and should) also have a default subtype that just unwrapps to the internal vallue (see [`@default_manifold_fallbacks`]()).
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

## Interface design

The interface for a manifold is defined to be as generic as possible, such that applications can be implemented as independent as possible from an actual manifold.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
This way, algorithms like those from [`Manopt.jl`](https://manoptjl.org) can be implemented on _arbitrary_ manifolds.

The main design criteria for the interface are

* aims to also provide _efficient_ and _inplace_ computations whenever possible.
* provide a high level interface that is easy to use
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

Therefore this interface has 3 main features, that we will explain using two (related)
concepts, the [exponential map](https://en.wikipedia.org/wiki/Exponential_map_(Riemannian_geometry)) that maps a tangent vector ``X`` at a point ``p`` to a point ``p`` or mathematically ``\exp_p;:T_p\mathcal M \to \mathcal M`` and its generalisation, a [retraction]() ``\operatorname{retr}_p`` with same domain and range.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

You do not need to know their exact definition at this point, just that there is _one_ exponential map on a Riemannian manifold, and several retractions, where one of them is the exponential map (sometime called exponential retraction for completeness). Every retraction has its own subtype of the {`AbstractRetractionMethod`]() that uniquely defines it.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

The following three design patterns aim to fulfill the criteria from above, while
also avoiding ambioguities in multiple dispatch using the [dispatch on one argument at a time](https://docs.julialang.org/en/v1/manual/methods/#Dispatch-on-one-argument-at-a-time) approach.

### General order of parameters

Since the central element for functions on a manifold is the manifold itself, it should always be the first parameter, even for mutating functions.

### Mutating and allocating functions

Every function, where this is applicable should provide a mutating and an allocating variant.
For example for the exponential map `exp(M,p,x)` returns a _new_ point `q` where the result is computed in.
On the other hand `exp!(M, q, p, X)` computes the result in place of `q`, where the design of the implementation
should keep in mind that also `exp!(M,p,p,X)` should be possible without side effects.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

The interface provides a way to determine the allocation type and a result (see [`allocate_result`]()) to compute/allocate
the resulting memory, such that the default implementation allocating functions, like `exp` is to allocate the resulting memory and call `exp!`.

!!! note
it might be useful to provide two distinct implementations, for example when using AD schemes.
The default is meant for ease of use (concerning implementation), since then one has to implement the mutating variants.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

### The higher level interface and ease of use

The higher level interface should aim for a convenience layer that resolves defaults and
creates fallbacks for certain input parameters, that have these properties.
It usually should not dispatch on a certain manifold nor on certain point or (co- or tangent) vector types.

This layer should also not resolve/dispatch from the allocating to the mutating variant.

This is maybe best illustrated by two examples

1. the exponential map usually has a long form, where one can specify a fraction (of `X`) where the evaluation should be. This is generically impülemented a

```julia
exp(M::AbstractManifold, p, X, t::Real) = exp(M, p, t * X)
```

On this level neither the manifold _nor_ the points should be too strictly typed, points and vectors should – for best of cases – never be types.

2. for the retraction, a default retraction (usually exp) is specified/defined via [`default_retraction_method`]().
This also means, that the last parameter of

```julia
retract(M::AbstractManifold, p, X, ::AbstractRetractionMethod=default_retraction_method(M))
```

is optional and for a concrete type the dispatch on a certain retraction is done next.
To avoid ambiguities, this concrete type should always be the first argument we dispatch on:
The `ExponentialRetractionMethod` calls `exp`, any other retraction calls a function of different name without this last parameter,
for example the `PolarRetractionMethod` by default calls `retract_polar(M,p,X)`, which is actualy a function from the lower level, see next section.

### The lower level interface – performance

This lower level aims for performance, that is, any function should have as less as possible optional and keyword arguments
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
and be typed as concrete as possible/necessary. This means

* the function name should be similar to its high level parent (for example `retract` and `retract_polar`from above)
* The manifold should always be a concrete manifold
kellertuer marked this conversation as resolved.
Show resolved Hide resolved
* the points/vectors should either be untyped (for the default representation of if there is only one) or provide all types concretely.

A first thing to do on this level is the aforementioned default to pass from allocating to mutating functions.
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

(TODO/Discuss - dispatch for decorators here instead of with the current/modular decorator pattern).
kellertuer marked this conversation as resolved.
Show resolved Hide resolved

## Bases

Expand All @@ -24,29 +105,27 @@ Methods are provided to obtain such a basis, to represent a tangent vector in a
The last two can be performed without computing the complete basis.
Further a basis can be cached and hence be reused, see [`CachedBasis`](https://juliamanifolds.github.io/Manifolds.jl/stable/interface.html#ManifoldsBase.CachedBasis).

## `DecoratorManifold`
## (Abstract) Example Manifolds

While this package does not provide _actual_, _concrete_ manifolds (see [`Manifolds.jl`](https://github.com/JuliaManifolds/Manifolds.jl) for these),
it provides a few generic (meta) manifolds that are helpful.

### `DecoratorManifold`

The decorator manifold enhances a manifold by certain, in most cases implicitly
assumed to have a standard case, properties, see for example the `EmbeddedManifold`.
The decorator acts semi transparently, i.e. `:transparent` for all functions not affected by that
decorator and `:intransparent` otherwise. Another possibility is, that the decorator just
passes to `:parent` in order to fill default values.

## `DefaultManifold`

This interface includes a simple `DefaultManifold`, which is a reduced version
of the [`Euclidean`](https://juliamanifolds.github.io/Manifolds.jl/stable/manifolds/euclidean.html)
manifold from [`Manifolds.jl`](https://github.com/JuliaManifolds/Manifolds.jl),
such that the interface functions can be tested.

## `EmbeddedManifold`
### `EmbeddedManifold`

The embedded manifold models the embedding of a manifold into another manifold.
This way a manifold can benefit from existing implementations.
One example is the `TransparentIsometricEmbeddingType` where a manifold uses the metric,
`inner`, from its embedding.

## `ValidationManifold`
### `ValidationManifold`

The `ValidationManifold` further illustrates how one can also used types to
represent points on a manifold, tangent vectors, and cotangent vectors,
Expand All @@ -59,7 +138,16 @@ by type.
This adds a semantic layer to the interface, and the default implementation of
`ValidationManifold` adds checks to all inputs and outputs of typed data.

### `DefaultManifold`

This interface includes a simple `DefaultManifold`, which is a reduced version
of the [`Euclidean`](https://juliamanifolds.github.io/Manifolds.jl/stable/manifolds/euclidean.html)
manifold from [`Manifolds.jl`](https://github.com/JuliaManifolds/Manifolds.jl).
This is indeed a concrete manifold, mainly to illustrate how a manifold is implemented
as well as for testing the interface functions.

## Citation

If you use `ManifoldsBase.jl` in your work, please cite the following

```biblatex
Expand Down