Search in sources :

Example 96 with Model

use of com.google.cloud.aiplatform.v1.Model in project xtext-core by eclipse.

the class Bug311337Test method testNoCyclicLinkingException.

@Test
public void testNoCyclicLinkingException() throws Exception {
    Model model = (Model) getModel("/************************************/\n" + "(def) local :\n" + "   (child) local_Child : def_depth1\n" + "   (ref) local_Child:depth1_Child\n" + "\n" + "/************************************/\n" + "\n" + "(def) def_depth1 :\n" + "   (child) depth1_Child : def_depth2\n" + "\n" + "/************************************/\n" + "\n" + "(def) def_depth2 :\n" + "   (child) depth2_Child :\n");
    assertTrue(model.eResource().getErrors().isEmpty());
}
Also used : Model(org.eclipse.xtext.linking.lazy.bug311337.Model) Test(org.junit.Test)

Example 97 with Model

use of com.google.cloud.aiplatform.v1.Model in project xtext-core by eclipse.

the class Bug362902Test method testNoExceptionUncaught.

@Test
public void testNoExceptionUncaught() throws Exception {
    String modelAsString = "Hello max ! Hello peter! favourite peter";
    Model model = (Model) getModelAndExpect(modelAsString, 2);
    EList<Diagnostic> errors = model.eResource().getErrors();
    Diagnostic diagnosticSyntax = errors.get(0);
    Diagnostic diagnosticLinking = errors.get(1);
    assertTrue(diagnosticSyntax instanceof XtextSyntaxDiagnostic);
    assertTrue(diagnosticLinking instanceof XtextLinkingDiagnostic);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Model(org.eclipse.xtext.linking.bug362902.Model) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 98 with Model

use of com.google.cloud.aiplatform.v1.Model in project batfish by batfish.

the class PropertyChecker method checkProperty.

/*
   * General purpose logic for checking a property that holds that
   * handles the various flags and parameters for a query with endpoints
   *
   * q is the question from the user.
   * instrument instruments each router in the graph as needed to check the property.
   * answer takes the result from Z3 and produces the answer for the user.
   *
   */
private AnswerElement checkProperty(HeaderLocationQuestion q, TriFunction<Encoder, Set<String>, Set<GraphEdge>, Map<String, BoolExpr>> instrument, Function<VerifyParam, AnswerElement> answer) {
    long totalTime = System.currentTimeMillis();
    PathRegexes p = new PathRegexes(q);
    Graph graph = new Graph(_batfish);
    Set<GraphEdge> destPorts = findFinalInterfaces(graph, p);
    List<String> sourceRouters = PatternUtils.findMatchingSourceNodes(graph, p);
    if (destPorts.isEmpty()) {
        throw new BatfishException("Set of valid destination interfaces is empty");
    }
    if (sourceRouters.isEmpty()) {
        throw new BatfishException("Set of valid ingress nodes is empty");
    }
    inferDestinationHeaderSpace(graph, destPorts, q);
    Set<GraphEdge> failOptions = failLinkSet(graph, q);
    Tuple<Stream<Supplier<NetworkSlice>>, Long> ecs = findAllNetworkSlices(q, graph, true);
    Stream<Supplier<NetworkSlice>> stream = ecs.getFirst();
    Long timeAbstraction = ecs.getSecond();
    AnswerElement[] answerElement = new AnswerElement[1];
    VerificationResult[] result = new VerificationResult[2];
    List<VerificationStats> ecStats = new ArrayList<>();
    // Checks ECs in parallel, but short circuits when a counterexample is found
    boolean hasCounterExample = stream.anyMatch(lazyEc -> {
        long timeEc = System.currentTimeMillis();
        NetworkSlice slice = lazyEc.get();
        timeEc = System.currentTimeMillis() - timeEc;
        synchronized (_lock) {
            // Make sure the headerspace is correct
            HeaderLocationQuestion question = new HeaderLocationQuestion(q);
            question.setHeaderSpace(slice.getHeaderSpace());
            // Get the EC graph and mapping
            Graph g = slice.getGraph();
            Set<String> srcRouters = mapConcreteToAbstract(slice, sourceRouters);
            long timeEncoding = System.currentTimeMillis();
            Encoder enc = new Encoder(_settings, g, question);
            enc.computeEncoding();
            timeEncoding = System.currentTimeMillis() - timeEncoding;
            // Add environment constraints for base case
            if (question.getDiffType() != null) {
                if (question.getEnvDiff()) {
                    addEnvironmentConstraints(enc, question.getDeltaEnvironmentType());
                }
            } else {
                addEnvironmentConstraints(enc, question.getBaseEnvironmentType());
            }
            Map<String, BoolExpr> prop = instrument.apply(enc, srcRouters, destPorts);
            // If this is a equivalence query, we create a second copy of the network
            Encoder enc2 = null;
            Map<String, BoolExpr> prop2 = null;
            if (question.getDiffType() != null) {
                HeaderLocationQuestion q2 = new HeaderLocationQuestion(question);
                q2.setFailures(0);
                long timeDiffEncoding = System.currentTimeMillis();
                enc2 = new Encoder(enc, g, q2);
                enc2.computeEncoding();
                timeDiffEncoding = System.currentTimeMillis() - timeDiffEncoding;
                timeEncoding += timeDiffEncoding;
            }
            if (question.getDiffType() != null) {
                assert (enc2 != null);
                // create a map for enc2 to lookup a related environment variable from enc
                Table2<GraphEdge, EdgeType, SymbolicRoute> relatedEnv = new Table2<>();
                enc2.getMainSlice().getLogicalGraph().getEnvironmentVars().forEach((lge, r) -> relatedEnv.put(lge.getEdge(), lge.getEdgeType(), r));
                BoolExpr related = enc.mkTrue();
                addEnvironmentConstraints(enc2, question.getBaseEnvironmentType());
                if (!question.getEnvDiff()) {
                    related = relateEnvironments(enc, enc2);
                }
                prop2 = instrument.apply(enc2, srcRouters, destPorts);
                // Add diff constraints
                BoolExpr required = enc.mkTrue();
                for (String source : srcRouters) {
                    BoolExpr sourceProp1 = prop.get(source);
                    BoolExpr sourceProp2 = prop2.get(source);
                    BoolExpr val;
                    switch(q.getDiffType()) {
                        case INCREASED:
                            val = enc.mkImplies(sourceProp1, sourceProp2);
                            break;
                        case REDUCED:
                            val = enc.mkImplies(sourceProp2, sourceProp1);
                            break;
                        case ANY:
                            val = enc.mkEq(sourceProp1, sourceProp2);
                            break;
                        default:
                            throw new BatfishException("Missing case: " + q.getDiffType());
                    }
                    required = enc.mkAnd(required, val);
                }
                related = enc.mkAnd(related, relatePackets(enc, enc2));
                enc.add(related);
                enc.add(enc.mkNot(required));
            } else {
                // Not a differential query; just a query on a single version of the network.
                BoolExpr allProp = enc.mkTrue();
                for (String router : srcRouters) {
                    BoolExpr r = prop.get(router);
                    if (q.getNegate()) {
                        r = enc.mkNot(r);
                    }
                    allProp = enc.mkAnd(allProp, r);
                }
                enc.add(enc.mkNot(allProp));
            }
            addFailureConstraints(enc, destPorts, failOptions);
            Tuple<VerificationResult, Model> tup = enc.verify();
            VerificationResult res = tup.getFirst();
            Model model = tup.getSecond();
            if (q.getBenchmark()) {
                VerificationStats stats = res.getStats();
                stats.setAvgComputeEcTime(timeEc);
                stats.setMaxComputeEcTime(timeEc);
                stats.setMinComputeEcTime(timeEc);
                stats.setAvgEncodingTime(timeEncoding);
                stats.setMaxEncodingTime(timeEncoding);
                stats.setMinEncodingTime(timeEncoding);
                stats.setTimeCreateBdds((double) timeAbstraction);
                synchronized (_lock) {
                    ecStats.add(stats);
                }
            }
            if (!res.isVerified()) {
                VerifyParam vp = new VerifyParam(res, model, srcRouters, enc, enc2, prop, prop2);
                AnswerElement ae = answer.apply(vp);
                synchronized (_lock) {
                    answerElement[0] = ae;
                    result[0] = res;
                }
                return true;
            }
            synchronized (_lock) {
                result[1] = res;
            }
            return false;
        }
    });
    totalTime = (System.currentTimeMillis() - totalTime);
    VerificationResult res;
    AnswerElement ae;
    if (hasCounterExample) {
        res = result[0];
        ae = answerElement[0];
    } else {
        res = result[1];
        VerifyParam vp = new VerifyParam(res, null, null, null, null, null, null);
        ae = answer.apply(vp);
    }
    if (q.getBenchmark()) {
        VerificationStats stats = VerificationStats.combineAll(ecStats, totalTime);
        res.setStats(stats);
    }
    return ae;
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) HeaderLocationQuestion(org.batfish.datamodel.questions.smt.HeaderLocationQuestion) ArrayList(java.util.ArrayList) PathRegexes(org.batfish.symbolic.utils.PathRegexes) NetworkSlice(org.batfish.symbolic.abstraction.NetworkSlice) Table2(org.batfish.symbolic.collections.Table2) Stream(java.util.stream.Stream) Supplier(java.util.function.Supplier) BatfishException(org.batfish.common.BatfishException) SmtOneAnswerElement(org.batfish.symbolic.answers.SmtOneAnswerElement) SmtDeterminismAnswerElement(org.batfish.symbolic.answers.SmtDeterminismAnswerElement) SmtReachabilityAnswerElement(org.batfish.symbolic.answers.SmtReachabilityAnswerElement) AnswerElement(org.batfish.datamodel.answers.AnswerElement) SmtManyAnswerElement(org.batfish.symbolic.answers.SmtManyAnswerElement) Graph(org.batfish.symbolic.Graph) Model(com.microsoft.z3.Model) GraphEdge(org.batfish.symbolic.GraphEdge)

Example 99 with Model

use of com.google.cloud.aiplatform.v1.Model in project bmoth by hhu-stups.

the class ReplViewTest method formatCouplesInSetTest.

@Test
public void formatCouplesInSetTest() {
    Context ctx = new Context();
    Solver s = ctx.mkSolver();
    BoolExpr constraint = translatePredicate("x = {(1,2,3),(4,5,6)}", ctx);
    s.add(constraint);
    s.check();
    Model model = s.getModel();
    String output = new PrettyPrinter(model).getOutput();
    assertEquals("{x={((1,2),3),((4,5),6)}}", output);
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) Model(com.microsoft.z3.Model) Test(org.junit.Test)

Example 100 with Model

use of com.google.cloud.aiplatform.v1.Model in project bmoth by hhu-stups.

the class ExplicitStateModelChecker method doModelCheck.

@Override
protected ModelCheckingResult doModelCheck() {
    final int maxInitialStates = BMothPreferences.getIntPreference(BMothPreferences.IntPreference.MAX_INITIAL_STATE);
    final int maxTransitions = BMothPreferences.getIntPreference(BMothPreferences.IntPreference.MAX_TRANSITIONS);
    stateSpace = new StateSpace();
    visited = new HashSet<>();
    Queue<State> queue = new LinkedList<>();
    // prepare initial states
    BoolExpr initialValueConstraint = getMachineTranslator().getInitialValueConstraint();
    Set<Model> models = finder.findSolutions(initialValueConstraint, maxInitialStates);
    models.stream().map(this::getStateFromModel).filter(this::isUnknown).forEach(root -> {
        stateSpace.addRootVertex(root);
        queue.add(root);
    });
    final BoolExpr invariant = getMachineTranslator().getInvariantConstraint();
    solver.add(invariant);
    // create joint operations constraint and permanently add to separate
    // solver
    final BoolExpr operationsConstraint = getMachineTranslator().getCombinedOperationConstraint();
    opSolver.add(operationsConstraint);
    while (!isAborted() && !queue.isEmpty()) {
        solver.push();
        State current = queue.poll();
        visited.add(current);
        // apply current state - remains stored in solver for loop iteration
        BoolExpr stateConstraint = current.getStateConstraint(getContext());
        solver.add(stateConstraint);
        // check invariant & state
        Status check = solver.check();
        switch(check) {
            case UNKNOWN:
                return createUnknown(visited.size(), solver.getReasonUnknown());
            case UNSATISFIABLE:
                return createCounterExampleFound(visited.size(), current, stateSpace);
            case SATISFIABLE:
            default:
        }
        // compute successors on separate finder
        models = opFinder.findSolutions(stateConstraint, maxTransitions);
        models.stream().map(this::getStateFromModel).forEach(successor -> {
            if (isUnknown(successor)) {
                stateSpace.addVertex(successor);
                queue.add(successor);
            }
            stateSpace.addEdge(current, successor);
        });
        solver.pop();
    }
    if (isAborted()) {
        return createAborted(visited.size());
    } else {
        ModelCheckingResult resultVerified = createVerified(visited.size(), stateSpace);
        if (buechiAutomaton != null) {
            // do ltl model check
            labelStateSpace();
            List<List<State>> cycles = new TarjanSimpleCycles<>(stateSpace).findSimpleCycles();
            for (List<State> cycle : cycles) {
                // if there is an accepting Buechi state in the cycle, a counterexample is found
                for (State state : cycle) {
                    if (buechiAutomaton.isAcceptingSet(state.getBuechiNodes())) {
                        return createLTLCounterExampleFound(visited.size(), state);
                    }
                }
            }
        }
        return resultVerified;
    }
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Model(com.microsoft.z3.Model) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult)

Aggregations

Test (org.junit.Test)52 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 LocationName (com.google.cloud.aiplatform.v1.LocationName)17 ModelServiceClient (com.google.cloud.aiplatform.v1.ModelServiceClient)17 ModelServiceSettings (com.google.cloud.aiplatform.v1.ModelServiceSettings)17 Model (com.google.cloud.aiplatform.v1.Model)16 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)16 Model (com.google.cloud.automl.v1.Model)16 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)14 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)14 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)14 Value (com.google.protobuf.Value)14 InputDataConfig (com.google.cloud.aiplatform.v1.InputDataConfig)13 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)13 ArrayList (java.util.ArrayList)12 EndpointName (com.google.cloud.aiplatform.v1.EndpointName)11 FilterSplit (com.google.cloud.aiplatform.v1.FilterSplit)11 FractionSplit (com.google.cloud.aiplatform.v1.FractionSplit)11 PredefinedSplit (com.google.cloud.aiplatform.v1.PredefinedSplit)11