CvO-Theory / apt

APT – Analysis of Petri nets and labelled transition systems
GNU General Public License v2.0
19 stars 9 forks source link

Is there any document where all the module usages/descriptions are listed? AND Do you provide JSON/XML output? #5

Closed tamarit closed 7 years ago

tamarit commented 7 years ago

Hi,

first of all, my sincere congratulations for the development of this tool. It's complete and really easy to use. I want to use your tool to perform several analyses on PNs. I'd like to know more information about each module, but I've only found a way to do it, by writing in the shell commands like this:

java -jar apt.jar check_all_cycle_prop

However, it's an annoying way to get all the module descriptions one by one. I've been looking for the complete list of all the modules with their respective descriptions, but I haven't found it. One promising document was APT.pdf, but unfortunately it doesn't list them in the way I'd find useful (besides it is in german). Another alternative that I've explored is to look for this info into the source code files. I've found that most of this info is in the function String getLongDescription() of some classes which are (most of them) in the directory /Users/tama/Documents/git/apt/src/module/uniol/apt/analysis/, e.g. /Users/tama/Documents/git/apt/src/module/uniol/apt/analysis/trapsAndSiphons/TrapsModule.java. Although I think that I could be able to create a document automatically using the information in all these modules, I wonder whether you have already done it and I could save some time :)

I have another question, now related with output formats. I didn't found information about this. I wonder whether you are providing an alternative way to report the result of the analyses, like JSON, XML, or another easy-parsing format. For instance LoLa provides output using JSON, and it'd be very convenient to have something similar to ease the parsing of the results.

Thanks in advance, and again congrats for your great work. Salva

renke commented 7 years ago

Regarding your first question: Have you tried java -jar apt.jar (without providing a module name)? It should print a short description of all modules (the main method eventually calls this method).

tamarit commented 7 years ago

Hi Renke,

yes, of course. However, this is the list of all the modules, with only a short description of each one. It would be more helpful to have something similar but with the complete descriptions instead.

Thanks! Salva

psychon commented 7 years ago

If I understand you correctly, you just want the help-output of all modules in a looooong list. For this, save the following code as ListAllModules.java and run javac -cp apt.jar ListAllModules.java && java -cp apt.jar:. ListAllModules (on unix-ish operating systems; adapt suitably for Windows):

import uniol.apt.module.AptModuleRegistry;
import uniol.apt.module.Module;
import uniol.apt.ui.impl.AptParametersTransformer;
import uniol.apt.ui.impl.UIUtils;

class ListAllModules {
    static public void main(String[] args) throws Exception {
        boolean first = true;
        for (Module module : AptModuleRegistry.INSTANCE.getModules()) {
            if (!first) {
                System.out.println("");
                System.out.println("-----------");
                System.out.println("");
            }
            System.out.println(UIUtils.getModuleUsage(module, AptParametersTransformer.INSTANCE));
            first = false;
        }
    }
}

The result will be something like this: https://gist.github.com/psychon/828d4db68db790bcda117dd17815f602

For output formats: No, currently we don't have anything else. Are you just looking at APT in general, or are you looking for some specific use? My (personal) preferred approach is to write everything in Java and to call the modules directly, but that's of course not general. Something like the following quick hack would produce something which might possibly count as JSON:

diff --git a/src/main/uniol/apt/APT.java b/src/main/uniol/apt/APT.java
index 19fa795..7a39c70 100644
--- a/src/main/uniol/apt/APT.java
+++ b/src/main/uniol/apt/APT.java
@@ -316,20 +316,24 @@ public class APT {
                        }

                        // Print all return values for which the module produced values
+                       System.out.println("{");
                        for (int i = 0; i < values.size(); i++) {
                                PrintStream out = outputs.get(i);
                                if (out == null)
                                        continue;

-                               if (outputWithName[i])
-                                       out.print(returnValues.get(i).getName() + ": ");
+                               out.print("\"" + returnValues.get(i).getName() + "\": \"");

                                OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
+                               // TODO: This could produce invalid JSON (no escaping is applied)
                                RETURN_VALUES_TRANSFORMER.transform(writer,
                                                values.get(i), returnValues.get(i).getKlass());
                                writer.flush();
-                               out.println();
+                               out.println("\"");
+                               if (i+1 < values.size())
+                                       out.println(",");
                        }
+                       System.out.println("}");
                }
                catch (IOException e) {
                        ERR_PRINTER.println("Error writing to file: " + e.getMessage());

Doing this properly would of course be better.

Side note: I think most modules in APT produce yes/no results (possible with a witness for a counter-example). If you are just interested in e.g. "is this Petri net plain", APT's exit code should provide this information.

I hope this helps. If you have some good ideas how to integrate this better, I'd like to hear about it. Also, I'm curious about your use case. Are you just looking at APT in general or do you have some specific "itch to scratch"?

Cheers, Uli

tamarit commented 7 years ago

Hi Uli @psychon,

first of all thank you for your prompt and very helpful answer.

With respect to my first question, yes it is exactly what I needed. With the output of this class, it is easier to my to know what are the functionality provided by your tool and how I should use it. Thanks for that :)

With respect to my second question, it seems that the proposed hack should work fine. It's true that the default output of the tool generally is simple and maybe can be parsed directly. I'm not parsing the output yet. I was just asking beforehand in case I need some analysis with a more difficult-to-parse output. I'm going to use your tool in Erlang. Both languages can communicate quite well, but for the moment I'm not going to integrate them and just call APT as a shell command from my Erlang program.

With respect my goal, I'm doing some tests on different algorithms that slice PNs. The output of the slice process is a smaller PNs where some of the properties are preserved and others not. I want to use your tool to check whether it is true through empirical evaluation, ensuring by this way that the implementation is correct. It is in a very initial phase (it has only 20 days old), but if your are interested you can take a look here.

Thanks again for your help and hope you follow building great tools like this one :) Salva

psychon commented 7 years ago

In case you did not see it already (and since you seem to be working with PNML): You can convert a PNML file into an APT file via ./apt.sh pn_convert pnml apt foo.pnml foo.apt.

tamarit commented 7 years ago

Yes, I knew that you have multiples converters. I've already implemented some of them, because I didn't know about your tool yet. In any case, it is useful to have yours also. Maybe I'll use some of your conversions in the future. Thanks again!

psychon commented 7 years ago

It took a while, but I just added a "proper" JSON interface to APT: https://github.com/CvO-Theory/apt/blob/master/doc/json.md (But I guess you already managed to do something else for what you wanted to do)

tamarit commented 7 years ago

Thanks @psychon . They are really good news. Yes, I managed to do it "manually". However, it still can be useful for next steps or similar projects. Thanks for the info!