Skip to content

Version 1.4.0 release

Compare
Choose a tag to compare
@daveraja daveraja released this 30 May 03:44
· 85 commits to master since this release

This version adds a lot of new type annotation features and performance enhancements. Note: in order to provide the performance enhancements the API has changed very slightly. However, the standard usage of clorm has not changed so would only affect more unusual usages of the library; for example, not using the provided clorm functions to unify predicate classes with symbols. The main features are:

  • Better support for type annotations. Modern Python code makes heavy use of type annotations. You can see this in popular libraries such as Pydantic. Clorm should now behave a lot better when used with modern tools such as mypy, pylint, and integrated IDEs.
  • Type annotations for Clorm's query API. If you use the new type annotated format for specifying Predicate sub-classes, tools like mypy can infer function inputs and outputs for clorm queries. This should make it much easier to use the query API for first-time or casual users.
  • A more compact way to declare your Predicate sub-classes. Instead of writing:
    class SomePredicate(Predicate):
         i = IntegerField

        class Meta:
             name = "some_predicate"

you can write:

    class SomePredicate(Predicate, name="some_predicate"):
         i: int
  • Performance enchancement. The overhead of using Clorm facts has now been reduced. So creating Clorm fact instances and extracting/unifying facts from clingo models has been made a lot more efficient. Note: this required a small change to the API but it shouldn't affect normal user code. In particular, it is only if a user was explicitly passing a clingo symbol to the initialiser (eg. Predicate.__init__(raw=clingo.Function("something",[])) will their code need to change. The API is now cleaner (calling raw=XX was really ugly), and you will need to call the Predicate.unify() class function.

  • No Clingo Mode. Currently, clingo.Symbol objects cannot be freed. This makes it potentially problematic to use clingo within long running processes. Clorm solves this by offering a NOCLINGO mode where you can use an internal clorm noclingo.Symbol objects in a long running parent process, and only use real clingo symbol objects in spawned sub-processes. To enable no clingo mode you must now set the environment variable CLORM_NOCLINGO. This must be set before the library is loaded. For example from the bash shell:

export CLORM_NOCLINGO=True