[ANN] Invariants.jl: Compose and check invariants and get detailed error messages

Happy to announce a smaller package this time, Invariants.jl! (GitHub, Documentation)

Invariants.jl is a Julia package for writing invariants for

  • providing helpful, detailed error messages to package users when they misuse the API
  • creating interface test suites (as described here)

Designing the package, I focused on:

  • reusability: invariants are easy to define and reuse, reducing boilerplate
  • composability: invariants can be composed to create more complex invariants
  • rich error messages: to be helpful, rich error messages should be easy to create

At its core, you can create invariants and check inputs against them:

You can also compose invariants to create more complex invariants. Checking against an input will then tell you exactly which part of the invariant was violated:

See the tutorial for more information.

I plan to use this package in FastAI.jl which requires validating data formats in various configurations. The composability of Invariants.jl makes it possible to get specific, contextual error messages without tons of duplicated checks and error messages:

(from FastAI.jl#230)

21 Likes

Nice package! I especially like the focus on visuals.

There’s a small bug in your example image, it checks for dimensionality 2, errors and says it has dimensionality 2.

1 Like

Thanks for pointing it out, I’ll take a look to fix that in the FastAI.jl PR :slight_smile:

1 Like