Skip to content

Parametric type hinting for control paths #359

Description

@tttc3

I would like to type hint that my custom term expects a control which has a certain type of path. E.G. only VirtualBrownianTree not UnsafeBrownianPath.

Ideally the code would look something like this:

from diffrax import AbstractTerm, ODETerm, WeaklyDiagonalControlTerm

class CustomTerm(AbstractTerm)
    ode: ODETerm
    cde: WeaklyDiagonalControlTerm[VirtualBrownianPath]

I'm not sure if this is already possible, or would require a change to the code. My thought was to do something like the following:

class _ControlTerm[T: Union[AbstractPath, Callable]](AbstractTerm):
    vector_field: ...
    control: T = ...

class WeaklyDiagonalControlTerm[T](_ControlTerm[T]):
    ...

I'm not very experienced with the more advanced aspects of type hinting so perhaps there is a better way, or this is already possible? Any thought are much appreciated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions