Git Product home page Git Product logo

Comments (6)

rkaminsk avatar rkaminsk commented on July 28, 2024

Hi, the program is not correct. The backend has to be closed before grounding; it cannot be used while grounding. Segfaults are possible here.

from clingo.

rkaminsk avatar rkaminsk commented on July 28, 2024

You could use something like this. In principle it is possible to use the control object in the execute function of the script. However, currently there is no nice way to pass it there.

import clingo
import clingo.script

class VtlScript:
    def __init__(self):
        self.control = None

    def execute(self, location, code):
        with self.control.backend() as backend:
            for i in range(10):
                atm = backend.add_atom(clingo.Function('vtl', [clingo.Number(i)]))  # <= without this, no segv
                backend.add_rule([atm], [])
        self.control.ground()
        self.control.solve(on_model=print)

# a script should be registered only once
vtls = VtlScript()
clingo.script.register_script('vtl', vtls)

def run_vtl_asp(program):
    control = clingo.Control()
    # set the control object of the script
    # this has to be done with care, for example, there should be only one thread
    # the script interface could be extended to pass the control object at hand to execute
    # to make this use case safe
    vtls.control = control
    control.add(program)

for i in range(10):                                             # <= with 1 run, no segv
    print("run", i)
    run_vtl_asp(""" #script (vtl) my vtl script #end. """)

from clingo.

ejgroene avatar ejgroene commented on July 28, 2024

Hi Roland,

Thank you for your quick reply. I begin to understand the various objects a bit better. Is there an overview somewhere that I missed, so I can read up?

[EDIT: I got it working now!]

I am trying to create a cross-over language in which logic can be expressed in VTL (railway oriented) or ASP. The idea is to provide a migration path to gradually move from VTL to ASP. Meanwhile, the result must be output in VTL so it can be compiled and fed to the controllers, and it must be output in ASP, to be able to apply formal methods and unit tests.

I see now that all scripts are executed first, in control.add(). That forces me to reconsider my approach, since VTL depends on order. For example: a = a * b in VTL means a(T) :- a(T-1), b in ASP.

As for this issue: I think it can be closed. Although later on, it could be that I will contribute a patch to give meaningful error messages instead of segv. I am quite good at C++ and Python, but not yet in ASP, so don't expect it soon.

As for tips on my approach to the cross-over langue, that is possible better sought elsewhere?

Best regards,
Erik

from clingo.

rkaminsk avatar rkaminsk commented on July 28, 2024

A script is intended to be called while grounding. Maybe it is not even the right choice for your problem. A translated VTL program could be added directly using Control.add or the ast module.

If you just want to pass your VTL program via the script tag, you could use the ast module to extract the tag and keep the rest of the program unchanged. Afterward, you can add a translation to the program.

Unfortunately, there are is no comprehensive user guide of the API. However, there is some info available in the our papers and the examples:

from clingo.

ejgroene avatar ejgroene commented on July 28, 2024

Roland,

Thank you for the paper. Its is an interesting read. I have updated my plans. But first a short holiday!

Erik

from clingo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.