Comments (6)
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.
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.
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.
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:
- https://www.cs.uni-potsdam.de/wv/publications/DBLP_journals/tplp/KaminskiRSW23.pdf
- https://github.com/potassco/clingo/tree/master/examples/clingo
from clingo.
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)
- Problems building clingo for static linking HOT 1
- Performance degradation when an incremental solve times out HOT 2
- Optional HOT 1
- quick arithmetic between two aggregate expression in place HOT 1
- Tychecking control.solve HOT 1
- I am confused with the OR logic. HOT 2
- domRec ignored for heuristic with external atom HOT 3
- Evaluate using Profile-Guided Optimization (PGO) and Post Link Optimization (PLO) for Clingo HOT 1
- Issues Running Python Inside Clingo - MacOs - M2 Chip HOT 4
- disable printing info HOT 1
- Build Failure with Ubuntu 22.04.3 HOT 1
- A propagator-based approach to timeout a solve? HOT 8
- How to to Make Preference Criteria Effective HOT 1
- Clingo/gringo/clasp: incorrect behavior on Android 11+ HOT 9
- Capture the logger HOT 2
- C++ API throws exception from destructor that cannot be caught HOT 3
- Code that has no effect HOT 1
- The Python extension fails to compile: 'math/wide_integer/uintwide_t.h' file not found HOT 6
- Clingo programs with python scripts hang with Python3.12 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clingo.