Skip to content

Commit

Permalink
Migrate XstsCli to Clikt
Browse files Browse the repository at this point in the history
  • Loading branch information
RipplB committed Aug 7, 2024
1 parent 3a2e2b0 commit 33b8240
Show file tree
Hide file tree
Showing 26 changed files with 965 additions and 1,104 deletions.
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ buildscript {

allprojects {
group = "hu.bme.mit.theta"
version = "6.4.0"
version = "6.5.0"

apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts"))
}
Expand All @@ -38,8 +38,10 @@ sonar {
property("sonar.projectKey", "ftsrg_theta")
property("sonar.organization", "ftsrg-github")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.coverage.jacoco.xmlReportPaths",
"${project.layout.buildDirectory.asFile.get()}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml")
property(
"sonar.coverage.jacoco.xmlReportPaths",
"${project.layout.buildDirectory.asFile.get()}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.util.Optional;

public final class BfsProvider implements MddTransformationProvider<AbstractNextStateDescriptor> {
public final class BfsProvider implements FixedPointEnumerationProvider {
public static boolean verbose = false;

private final CacheManager<BinaryOperationCache<MddNode, AbstractNextStateDescriptor, MddNode>> cacheManager = new CacheManager<>(
Expand Down Expand Up @@ -135,4 +135,14 @@ public void cleanup() {
public Cache getRelProdCache() {
return relProdProvider.getRelProdCache();
}

@Override
public Cache getCache() {
return getRelProdCache();
}

@Override
public CacheManager<?> getCacheManager() {
return cacheManager;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hu.bme.mit.theta.analysis.algorithm.mdd.fixedpoint;

import hu.bme.mit.delta.java.mdd.*;
import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor;

public interface FixedPointEnumerationProvider extends MddTransformationProvider<AbstractNextStateDescriptor> {
MddHandle compute(
AbstractNextStateDescriptor.Postcondition initializer,
AbstractNextStateDescriptor nextStateRelation,
MddVariableHandle highestAffectedVariable
);

Cache getCache();

CacheManager<?> getCacheManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.function.Consumer;
import java.util.function.ToLongFunction;

public final class GeneralizedSaturationProvider implements MddTransformationProvider<AbstractNextStateDescriptor> {
public final class GeneralizedSaturationProvider implements FixedPointEnumerationProvider {
public static boolean verbose = false;

private MddVariableOrder variableOrder;
Expand Down Expand Up @@ -541,4 +541,14 @@ public long getHitCount() {

return new RelProdCache(cacheManager);
}

@Override
public Cache getCache() {
return getRelProdCache();
}

@Override
public CacheManager<?> getCacheManager() {
return cacheManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.function.Consumer;
import java.util.function.ToLongFunction;

public final class SimpleSaturationProvider implements MddTransformationProvider<AbstractNextStateDescriptor> {
public final class SimpleSaturationProvider implements FixedPointEnumerationProvider {
public static boolean verbose = false;

private MddVariableOrder variableOrder;
Expand Down Expand Up @@ -546,4 +546,14 @@ public long getHitCount() {

return new RelProdCache(cacheManager);
}

@Override
public Cache getCache() {
return getRelProdCache();
}

@Override
public CacheManager<?> getCacheManager() {
return cacheManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package hu.bme.mit.theta.common.visualization.writer;

import hu.bme.mit.theta.common.visualization.Graph;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import hu.bme.mit.theta.common.visualization.Graph;

/**
* Base class for writing graphs.
*/
Expand All @@ -33,17 +33,14 @@ public abstract class AbstractGraphWriter implements GraphWriter {
public final void writeFile(final Graph graph, final String fileName)
throws FileNotFoundException {
final File file = new File(fileName);
PrintWriter printWriter = null;
try {
printWriter = new PrintWriter(file);
writeFile(graph, file);
}

public final void writeFile(final Graph graph, final File file)
throws FileNotFoundException {
try (PrintWriter printWriter = new PrintWriter(file)) {
final String graphAsString = writeString(graph);
printWriter.write(graphAsString);
} catch (final FileNotFoundException e) {
throw e;
} finally {
if (printWriter != null) {
printWriter.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package hu.bme.mit.theta.frontend.petrinet.analysis;

import com.koloboke.collect.map.hash.HashObjObjMaps;
import hu.bme.mit.theta.frontend.petrinet.model.Identified;
import hu.bme.mit.theta.frontend.petrinet.model.PetriNet;
import hu.bme.mit.theta.frontend.petrinet.model.Place;

Expand All @@ -28,11 +29,15 @@
import java.util.stream.Collectors;

public final class VariableOrderingFactory {
public static List<Place> fromFile(String orderingPath, PetriNet petriNet) throws Exception {
public static List<Place> fromPathString(String orderingPath, PetriNet petriNet) throws Exception {
final File orderingFile = new File(orderingPath);
if (!orderingFile.exists()) {
throw new IOException("Cannot open ordering file: " + orderingPath);
}
return fromFile(orderingFile, petriNet);
}

public static List<Place> fromFile(File orderingFile, PetriNet petriNet) throws Exception {
List<String> orderingIds = Files.readAllLines(orderingFile.toPath());
orderingIds.removeIf(s -> s.trim().isEmpty());
if (orderingIds.size() != petriNet.getPlaces().size()) {
Expand All @@ -41,7 +46,7 @@ public static List<Place> fromFile(String orderingPath, PetriNet petriNet) throw
Map<String, Place> placeIdMap = HashObjObjMaps.newImmutableMap(petriNet
.getPlaces()
.stream()
.collect(Collectors.toMap(p -> p.getId(), p -> p)));
.collect(Collectors.toMap(Identified::getId, p -> p)));
final List<Place> ordering = new ArrayList<>(orderingIds.size());
for (String s : orderingIds) {
Place p = placeIdMap.get(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testBfs() throws Exception {

assertEquals(1, petriNets.size());

final List<Place> ordering = VariableOrderingFactory.fromFile(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0));
final List<Place> ordering = VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0));
// ordering = new ArrayList<>(petriNets.get(0).getPlaces());
// ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()),
// reverseString(p2.getId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import hu.bme.mit.delta.mdd.LatticeDefinition;
import hu.bme.mit.delta.mdd.MddInterpreter;
import hu.bme.mit.delta.mdd.MddVariableDescriptor;
import hu.bme.mit.theta.analysis.algorithm.mdd.fixedpoint.GeneralizedSaturationProvider;
import hu.bme.mit.theta.analysis.algorithm.mdd.fixedpoint.CursorRelationalProductProvider;
import hu.bme.mit.theta.analysis.algorithm.mdd.fixedpoint.GeneralizedSaturationProvider;
import hu.bme.mit.theta.frontend.petrinet.model.PetriNet;
import hu.bme.mit.theta.frontend.petrinet.model.Place;
import hu.bme.mit.theta.frontend.petrinet.pnml.PetriNetParser;
Expand All @@ -48,7 +48,7 @@ public void testGS() throws Exception {

assertEquals(1, petriNets.size());

final List<Place> ordering = VariableOrderingFactory.fromFile(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0));
final List<Place> ordering = VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0));
// ordering = new ArrayList<>(petriNets.get(0).getPlaces());
// ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()),
// reverseString(p2.getId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testSS() throws Exception {
assertEquals(1, petriNets.size());

final List<Place> ordering =
VariableOrderingFactory.fromFile(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(),
VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(),
petriNets.get(0));
// ordering = new ArrayList<>(petriNets.get(0).getPlaces());
// ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
import com.google.common.collect.ImmutableList;
import hu.bme.mit.theta.common.Tuple2;
import hu.bme.mit.theta.common.logging.Logger;
import hu.bme.mit.theta.solver.HornSolver;
import hu.bme.mit.theta.solver.ItpSolver;
import hu.bme.mit.theta.solver.Solver;
import hu.bme.mit.theta.solver.SolverBase;
import hu.bme.mit.theta.solver.SolverFactory;
import hu.bme.mit.theta.solver.SolverManager;
import hu.bme.mit.theta.solver.UCSolver;
import hu.bme.mit.theta.solver.*;
import hu.bme.mit.theta.solver.smtlib.impl.bitwuzla.BitwuzlaSmtLibSolverInstaller;
import hu.bme.mit.theta.solver.smtlib.impl.boolector.BoolectorSmtLibSolverInstaller;
import hu.bme.mit.theta.solver.smtlib.impl.cvc4.CVC4SmtLibSolverInstaller;
Expand All @@ -43,17 +37,11 @@
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Preconditions.*;

public final class SmtLibSolverManager extends SolverManager {

Expand All @@ -77,14 +65,12 @@ public final class SmtLibSolverManager extends SolverManager {
}

private final Path home;
private final Logger logger;
private final Map<String, SmtLibSolverInstaller> installers;
private final Tuple2<String, GenericSmtLibSolverInstaller> genericInstaller;
private final Set<SolverBase> instantiatedSolvers;
private boolean closed = false;

private SmtLibSolverManager(final Path home, final Logger logger) {
this.logger = logger;
checkNotNull(home);
checkArgument(Files.exists(home), "Home directory does not exist");

Expand Down Expand Up @@ -160,8 +146,7 @@ private static String decodeSolverName(final String name, final int part) {

public static SmtLibSolverManager create(final Path home, final Logger logger)
throws IOException {
createIfNotExists(home);
return new SmtLibSolverManager(home, logger);
return new SmtLibSolverManager(createIfNotExists(home), logger);
}

private static Path createIfNotExists(final Path path) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
*/
package hu.bme.mit.theta.solver.z3legacy;

import hu.bme.mit.theta.solver.ItpSolver;
import hu.bme.mit.theta.solver.Solver;
import hu.bme.mit.theta.solver.SolverBase;
import hu.bme.mit.theta.solver.SolverFactory;
import hu.bme.mit.theta.solver.SolverManager;
import hu.bme.mit.theta.solver.UCSolver;
import hu.bme.mit.theta.solver.*;

import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
*/
package hu.bme.mit.theta.solver.z3;

import hu.bme.mit.theta.solver.HornSolver;
import hu.bme.mit.theta.solver.ItpSolver;
import hu.bme.mit.theta.solver.Solver;
import hu.bme.mit.theta.solver.SolverBase;
import hu.bme.mit.theta.solver.SolverFactory;
import hu.bme.mit.theta.solver.SolverManager;
import hu.bme.mit.theta.solver.UCSolver;
import hu.bme.mit.theta.solver.*;

import java.util.HashSet;
import java.util.Set;
Expand Down
6 changes: 4 additions & 2 deletions subprojects/xsts/xsts-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ dependencies {
implementation(project(":theta-analysis"))
implementation(project(":theta-core"))
implementation(project(":theta-common"))
implementation(project(":theta-solver"))
implementation(project(":theta-solver-z3-legacy"))
implementation(project(":theta-solver-z3"))
implementation(project(":theta-solver-smtlib"))
implementation(project(":theta-solver"))
implementation(project(":theta-solver-javasmt"))
}

application {
mainClass.set("hu.bme.mit.theta.xsts.cli.XstsCli")
mainClass.set("hu.bme.mit.theta.xsts.cli.XstsCliMainKt")
}
Loading

0 comments on commit 33b8240

Please sign in to comment.