Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib initial commit Aug 2, 2019
src/main initial commit Aug 2, 2019
LICENSE initial commit Aug 2, 2019
README.md initial commit Aug 2, 2019
pom.xml initial commit Aug 2, 2019

README.md

README

LogicBox Examples

What is this repository for?

This repo contains code examples for programming using the LogicBox system. The aim of LogicBox is to provide a modern programming paradigm and tooling to meet today's complex software needs. LogicBox has verification in mind at it has been designed from the ground up to minimize and detected programming errors, whilst being a practical tool for industry.

We are looking for a pilot customer who could benefit from this technology and who could help us perfect it, with the aim of open sourcing as soon as commercially possible.

The LogicBox system has two key components:

  1. LogicBox, a concise and formal embedded DSL for executing computations.

  2. Exhaust, a runtime verification system that leverages intelligent fuzzing which provides a significant extra layer of verification on top of LogicBox.

Currently this repo only provides access to LogicBox. Access to Exhaust will be coming soon.

Visit www.cognitionbox.io for information and access to the whitepaper.

How do I get set up?

Simply clone the repo and run the examples. The repo includes a free trial (valid till end of 2019) for the LogicBox core (currently closed source), which is named logicbox-pre-alpha.jar and can be found in the lib folder. Also in the lib folder is the logicbox-pre-alpha-dependencies.jar which logicbox depends on. The lib folder is about 30mb in total and will take a short time to download.

All the examples are setup for in-process execution except for the trading system which can run in distributed mode.

Examples for Exhaust verification system will be coming soon.

Examples

Hello World
package io.cognitionbox.logicbox.examples.simple;

import io.cognitionbox.logicbox.core.impls.LogicComputer;
import io.cognitionbox.logicbox.core.impls.XGraph;

public class HelloWorld {
    /*
     * This simple example consumes an input A,
     * does nothing with it and passes it straight
     * through to the the post-condition.
     *
     * Once it is output from the root of the graph A's message is printed.
     */
    public static void main(String[] args){
        System.setProperty("mode", "PAR");
        System.setProperty("optimizeMode","NONE");

        class A{public String value = "hello world.";}
        class AtoA extends XGraph<A,A> {
            AtoA(){
                consumes(A.class);
                step(A.class, a->a,A.class);
                produces(A.class);
            }
        }

        A output = new LogicComputer<A, A>().computeWithInput(new AtoA(),new A());
        System.out.println("OUTPUT: "+output.value);
    }
}
Transform
package io.cognitionbox.logicbox.examples.simple;

import io.cognitionbox.logicbox.core.impls.LogicComputer;
import io.cognitionbox.logicbox.core.impls.XGraph;

public class Transform {
    /*
     * A simple example showing how an object of one type is mapped into another.
     * Here we use simple pre and post conditions in the consumes/produces functions, in that
     * we only use a class type and no stronger pre/post conditions using predicates.
     *
     * We could have achieved the same with the following pre/post conditions:
     *
     * consumes(A.class,a->true);
     * produces(B.class,b->true);
     *
     * Above we explicitly define a predicate on A and B which always returns true.
     *
     */
    public static void main(String[] args){
        System.setProperty("mode", "PAR");
        System.setProperty("optimizeMode","NONE");

        class A{}
        class B{}
        class AtoB extends XGraph<A,B> {
            AtoB(){
                consumes(A.class);
                step(A.class, a->new B(),B.class);
                produces(B.class);
            }
        }

        B output = new LogicComputer<A, B>().computeWithInput(new AtoB(),new A());
        System.out.println("OUTPUT: "+output.getClass().getSimpleName());
    }
}
Disorderly Programming
package io.cognitionbox.logicbox.examples.simple;

import io.cognitionbox.logicbox.core.annotations.Extract;
import io.cognitionbox.logicbox.core.impls.LogicComputer;
import io.cognitionbox.logicbox.core.impls.None;
import io.cognitionbox.logicbox.core.impls.XGraph;

import static io.cognitionbox.logicbox.core.impls.None.none;

public class DisorderlyProgramming {
    /*
     * This demonstrates disorderly programming.
     * The steps can be defined in any order and the outcome is always the same.
     * It shows a more logical way to program.
     *
     * Will print out E and F and then terminate.
     *
     * First A is consumed,
     * then A is transformed to B,
     * then B is transformed to C,
     * then C is tranformed to D (which contains E amd F)
     * then D is deconstucted into E and F
     * then E and F are printed
     * then it terminates
     */
    public static void main(String[] args){
        System.setProperty("mode", "PAR");
        System.setProperty("optimizeMode","NONE");

        class A{}
        class B{}
        class C{}

        class E{}
        class F{}

        @Extract
        class D{
            @Extract E e;
            @Extract F f;

            public D(E e, F f) {
                this.e = e;
                this.f = f;
            }
        }

        class DependancyGraph extends XGraph<A, None> {
            DependancyGraph(){
                consumes(A.class);
                step(A.class, a->new B(),B.class);
                step(C.class, c->new D(new E(),new F()),D.class);
                step(B.class, b->new C(),C.class);
                step(E.class, e->{
                    System.out.println(e.getClass().getSimpleName());
                    return none();
                },None.class);
                step(F.class, f->{
                    System.out.println(f.getClass().getSimpleName());
                    return none();
                },None.class);
                produces(None.class);
            }
        }

        new LogicComputer<A, None>().computeWithInput(new DependancyGraph(),new A());
    }
}
Dynamic Step Parallelism
package io.cognitionbox.logicbox.examples.simple;

import io.cognitionbox.logicbox.core.annotations.Extract;
import io.cognitionbox.logicbox.core.impls.LogicComputer;
import io.cognitionbox.logicbox.core.impls.None;
import io.cognitionbox.logicbox.core.impls.XGraph;
import io.cognitionbox.logicbox.core.impls.XList;

import static io.cognitionbox.logicbox.core.impls.None.none;

public class DynamicStepParallelism {
    /*
     * Demonstrates Dynamic Step Parallelism through different type of extractions...
     *
     * X is market @Extract and contains two references to A objects marked @Extract
     * X also contains a reference to a list marked @Extract.
     * This list an extension of XList.
     * XList is part of a family of LogicBox cross-runtime-mode collections, including:
     * XSet, XMap etc. These collections can be used in SEQ, PAR and DIS modes out the box.
     * (DIS mode requires the objects contained by the collections to be Serializable).
     * In order for a collection to be deconstructed it must be extended and its extension
     * must be marked @Extract. Future versions will allow @Extract to be used directly on
     * the collections with out the need for extended them.
     *
     * X will be matched by PrintA and then be deconstructed into 6 A objects.
     * 2 from A references directed referenced in X and 4 within the list referenced by X.
     *
     */
    public static void main(String[] args){

    System.setProperty("mode", "PAR");
    System.setProperty("optimizeMode","NONE");

    class A{}
    @Extract
    class AList extends XList<A>{}

    @Extract
    class X{
        @Extract A a1 = new A();
        @Extract A a2 = new A();
        @Extract
        AList aList = new AList();
        {
            aList.add(new A());
            aList.add(new A());
            aList.add(new A());
            aList.add(new A());
        }
    }
    class PrintA extends XGraph<X,None> {
        PrintA(){
            consumes(X.class);
            step(A.class, a->{
                System.out.println(a);
                return none();
            },None.class);
            produces(None.class);
        }
    }

     new LogicComputer<X, None>().computeWithInput(new PrintA(),new X());

    }
}

Config

In-process
System.setProperty("mode", "SEQ");
System.setProperty("optimizeMode","NONE");
Distributed

For distributed execution make sure your classes are Serializable and use:

System.setProperty("mode", "DIS");
System.setProperty("optimizeMode","NONE");

// LogicBox will wait for the Hazelcast cluster size to reach this number before starting the computation.
System.setProperty("expectedClusterSize","3"); // or what ever your hazelcast node size is.

Creating a new LogicComputer() in DIS mode, will start a Hazelcast JET/IMDG node.

Please get in contact if you have any questions at all, we are looking forward to your feedback.

Who do I talk to?

You can’t perform that action at this time.