conjure-cp / conjure

Conjure: The Automated Constraint Modelling Tool
Other
96 stars 20 forks source link

Missing JSON <-> essence conversion #548

Closed ChrisJefferson closed 1 year ago

ChrisJefferson commented 1 year ago

Trying to have a given w: bool results in a notebook leads tothe following. I imagine this is easy to fix, just not implemented?

Exception: Error:
    Cannot convert this JSON to Essence yet.

    true
    Bool True

    Source: Constant

    Let us know if you need support for this please!
    As a workaround you can use --output-format=astjson
ChrisJefferson commented 1 year ago

Similar issue, I'd be getting into variants, but there I get This is not an int. Boo..

I wonder if I should be using astjson? Or maybe the JSON format needs slightly more info on the type of things? (I'd be happy to mark things with their type for distinguishing purposes, but the whole astjson is a bit serious)

ozgurakgun commented 1 year ago

I am keen to improve the json input. astjson would be too brittle (since it depends on the internal structure very much)

let me know if you have any other cases and I will fix them - as soon as I have some free time...

ozgurakgun commented 1 year ago

Can you give a variant example as well please?

ChrisJefferson commented 1 year ago
%load_ext conjure
<IPython.core.display.Javascript object>

Conjure extension is loaded.
For usage help run: %conjure_help
%%conjure

find w : variant { a: int(1..10), b: int(1..10) }

such that
w[a] = 2
{'w': {'a': 2}}
%conjure_clear
Conjure model cleared
q = {'a': 2}
%%conjure

given q : variant { a: int(1..10), b: int(1..10) }
find w : variant { a: int(1..10), b: int(1..10) }

such that
q = w
Exception: Error: This is not an int. Boo.
ChrisJefferson commented 1 year ago

Just to say, all issues I had are now fixed, and all types I've tried (including 2d matrices and functions) all translate both to and from JSON correctly.