Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/trace master merge #225

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6b1c1b7
Initial commit
MarkBeB Jan 14, 2025
dcb49ae
Initial commit
MarkBeB Jan 14, 2025
ad8be1e
Initial commit
MarkBeB Jan 14, 2025
84143c5
Initial commit
MarkBeB Jan 14, 2025
494623a
Add trace statements to gipsl -> gips
MarkBeB Jan 14, 2025
aa60a35
Initial commit
MarkBeB Jan 14, 2025
5880b2e
Refactor class name
MarkBeB Jan 16, 2025
d2c22c5
Update IEditorTraceConnection class description
MarkBeB Jan 16, 2025
28f5dfb
Fix graph pathfinding after refactoring
MarkBeB Jan 16, 2025
4bb9769
Refactor trace update from builder to utils
MarkBeB Jan 16, 2025
b5b2071
TODO Note
MarkBeB Jan 26, 2025
d5044a1
Set gips.debugger dependency to reexport in main plugin
MarkBeB Jan 26, 2025
ce82f39
Squash and merge of trace-rmi
MarkBeB Jan 27, 2025
caf0d02
Squash and merge of trace-preference
MarkBeB Jan 27, 2025
0b81a9d
Squashed commit of trace-cache
MarkBeB Jan 29, 2025
f4ffb12
Remove unused caching preference setting
MarkBeB Jan 29, 2025
44297c0
Refactor cache preference checks
MarkBeB Jan 29, 2025
892ac0e
Squashed commit of tracing-ui
MarkBeB Feb 3, 2025
ce0a318
Remove time measurement code
MarkBeB Feb 4, 2025
4e0ee49
Replace RMI Service name with a constant
MarkBeB Feb 4, 2025
5c1e196
Refactor TraceManager event api
MarkBeB Feb 4, 2025
8bd1a91
Add delete entry/link menu item to trace view
MarkBeB Feb 8, 2025
7b5bf26
Change model id from file name to relative path within project
MarkBeB Feb 8, 2025
9c30eda
Fix XMIEditor model id computation
MarkBeB Feb 9, 2025
8d04425
Add open file handler to trace view
MarkBeB Feb 9, 2025
9b6583a
Refactoring trace view
MarkBeB Feb 10, 2025
087059a
Fix missing interfaces
MarkBeB Feb 10, 2025
c1daac0
Merge branch 'feature/tracing' into feature/trace-master-merge
MarkBeB Feb 12, 2025
6d9e654
Add localized plugin name
MarkBeB Feb 12, 2025
8c76d90
Rename LP trace keywords for GIPSL 1.5
MarkBeB Feb 12, 2025
13633ba
Remove test projects from cplex lp gen file
MarkBeB Feb 12, 2025
2a62420
Enhance trace view labels
MarkBeB Feb 12, 2025
1b594fe
Refactor cherry pick from trace-optimization
MarkBeB Jan 28, 2025
48216f7
Rename TraceMarker to TraceAnnotation
MarkBeB Jan 28, 2025
f0d44c7
TraceOp cherry pick
MarkBeB Feb 13, 2025
85bf7d5
Prototype LP Editor Connection based on annotations and jobs
MarkBeB Jan 28, 2025
6146b57
Fix removal of trace context on project close
MarkBeB Feb 13, 2025
7c9a6ec
Fix possible NPE
MarkBeB Feb 13, 2025
b7df30f
Adjustments to cplex dsl to support gipsl 1.5
MarkBeB Feb 14, 2025
930ece9
Move resource marker code out of editor connector
MarkBeB Feb 14, 2025
f6ca50a
Refactor methods to work with cplex ast nodes
MarkBeB Feb 14, 2025
0bfdbeb
Clarification of ITraceContext#getModelChain parameters
MarkBeB Feb 14, 2025
7fc1865
Add new visualisation algorithm
MarkBeB Feb 14, 2025
1f0f382
Bugfix for cplex constraints with multiple underscores
MarkBeB Feb 21, 2025
8844665
Add a datatype for annotation/position pairs and restore auto-scrolli…
MarkBeB Feb 21, 2025
77dc4c1
Switch GIPSL editor from marker to annotation highlighter
MarkBeB Feb 21, 2025
a396da0
Refactor cache file path building into its own method
MarkBeB Feb 21, 2025
c25546c
Intermediate -> LP tracing can be enabled/disabled (by default disabled)
MarkBeB Feb 21, 2025
5293097
Merge branch 'master' into feature/trace-master-merge
MarkBeB Feb 21, 2025
c8f7593
Enable RMI Port preference settings
MarkBeB Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions org.emoflon.gips.build/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Require-Bundle: org.emoflon.gips.intermediate;bundle-version="1.5.0",
org.emoflon.ibex.gt,
org.moflon.core.plugins,
org.emoflon.gips.core.dependencies,
org.emoflon.gips.debugger.trace,
org.emoflon.gips.debugger,
org.junit,
junit-jupiter-api
Bundle-Vendor: Real-Time Systems Lab - TU Darmstadt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -29,6 +30,13 @@
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.emoflon.gips.build.generator.GipsImportManager;
import org.emoflon.gips.build.transformation.GipsToIntermediate;
import org.emoflon.gips.debugger.api.ITraceContext;
import org.emoflon.gips.debugger.api.ITraceManager;
import org.emoflon.gips.debugger.trace.TraceMap;
import org.emoflon.gips.debugger.trace.TraceModelLink;
import org.emoflon.gips.debugger.trace.resolver.ResolveEcore2Id;
import org.emoflon.gips.debugger.utility.HelperEclipse;
import org.emoflon.gips.intermediate.GipsIntermediate.GipsIntermediateModel;
import org.emoflon.gips.intermediate.GipsIntermediate.TypeConstraint;
import org.emoflon.ibex.gt.codegen.EClassifiersManager;
Expand Down Expand Up @@ -151,7 +159,7 @@ public static URI saveResource(EObject object, String path) {
saveOptions.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
saveOptions.put(XMLResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION, Boolean.TRUE);
try {
((XMIResource) output).save(saveOptions);
output.save(saveOptions);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -292,6 +300,49 @@ public static void generateEMoflonAPI(final IProject project, final GipsAPIData
});
}

/**
* Updates the project specific model transformation trace
*
* @param project used to determine the project to be update
* @param gipslModelURI used to generate an id for the gipsl model
* @param intermediateModelURI used to generate an id the intermediate model
* @param transformer Provides the gipsl-intermediate trace
*/
public static void updateTrace(final IProject project, final URI gipslModelURI, final URI intermediateModelURI,
final GipsToIntermediate transformer) {

// each project has it's own trace.
ITraceContext traceContext = ITraceManager.getInstance().getContext(project.getName());

try {
// adjust file extension from xmi to gipsl
URI gipslURI = HelperEclipse.toPlatformURI(gipslModelURI.trimFileExtension().appendFileExtension("gipsl"));
// first segment of an URI is the project name, by removing it we get a
// project relative path
IPath gipslPath = IPath.fromOSString(gipslURI.toPlatformString(true)).makeRelative().removeFirstSegments(1);

URI intermediateURI = HelperEclipse.toPlatformURI(intermediateModelURI);
// FIXME: the intermediate URI isn't a valid URI. The first segment is not the
// project name.
IPath intermediatePath = IPath.fromOSString(intermediateURI.toPlatformString(true)).makeRelative();

String gipslModelId = gipslPath.toString(); // gipslModelURI.trimFileExtension().lastSegment();
String intermediateModelId = intermediatePath.toString(); // intermediateModelURI.trimFileExtension().lastSegment();

if (gipslModelId.equalsIgnoreCase(intermediateModelId))
throw new IllegalArgumentException(
"GIPSL and Intermediate model id should not be equal: '" + gipslModelId + "'");

TraceMap<String, String> gipsl2intermediateMppings = TraceMap.normalize(transformer.getTrace(),
ResolveEcore2Id.INSTANCE, ResolveEcore2Id.INSTANCE);

traceContext
.updateTraceModel(new TraceModelLink(gipslModelId, intermediateModelId, gipsl2intermediateMppings));
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Gets the class name prefix for a given project
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void build(IProject project, Resource resource) {
GipsBuilderUtils.saveResource(model, gipsApiData.apiPackageFolder.getLocation() + "/gips/gips-model.xmi");
gipsApiData.intermediateModelURI = URI.createPlatformResourceURI(
gipsApiData.apiPackageFolder.getProjectRelativePath() + "/gips/gips-model.xmi", true);
// FIXME; createPlatformResourceURI requires a path of the form
// "/project-name/path", but getProjectRelativePath() does not include
// "project-name"
// TODO: See if this can be easily fixed.

// build HiPE engine code
if (ibexModel != null && !ibexModel.getPatternSet().getContextPatterns().isEmpty()) {
Expand All @@ -99,6 +103,12 @@ public void build(IProject project, Resource resource) {
// generate files
GipsCodeGenerator gipsGen = new GipsCodeGenerator(model, gipsApiData, manager);
gipsGen.generate();

// update gipsl->intermediate tracing
LogUtils.info(logger, "GipsProjectBuilder: update trace...");
GipsBuilderUtils.updateTrace(project, gipsSlangFile.eResource().getURI(), gipsApiData.intermediateModelURI,
transformer);

LogUtils.info(logger, "GipsProjectBuilder: Done!");

try {
Expand All @@ -108,5 +118,4 @@ public void build(IProject project, Resource resource) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.emoflon.gips.build.transformation.transformer.ArithmeticExpressionTransformer;
import org.emoflon.gips.build.transformation.transformer.BooleanExpressionTransformer;
import org.emoflon.gips.build.transformation.transformer.TransformerFactory;
import org.emoflon.gips.debugger.trace.TraceMap;
import org.emoflon.gips.gipsl.gipsl.EditorGTFile;
import org.emoflon.gips.gipsl.gipsl.GipsArithmeticExpression;
import org.emoflon.gips.gipsl.gipsl.GipsBooleanExpression;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class GipsToIntermediate {
protected GipsIntermediateFactory factory = GipsIntermediateFactory.eINSTANCE;
final protected GipsTransformationData data;
final protected TransformerFactory transformationFactory;
final private TraceMap<EObject, EObject> gipsl2gipsTrace = new TraceMap<>();
protected int constraintCounter = 0;

public GipsToIntermediate(final EditorGTFile gipslFile) {
Expand Down Expand Up @@ -131,6 +133,10 @@ public GipsIntermediateModel transform() throws Exception {
return data.model();
}

public TraceMap<EObject, EObject> getTrace() {
return gipsl2gipsTrace;
}

protected void preprocessGipslFile() {
EditorToIBeXPatternTransformation ibexTransformer = new EditorToIBeXPatternTransformation();
data.model().setIbexModel(ibexTransformer.transform(data.gipslFile()));
Expand Down Expand Up @@ -218,6 +224,7 @@ protected void transformConfig() {
}

data.model().setConfig(config);
gipsl2gipsTrace.map(eConfig, config);
}

protected void transformMappings() {
Expand Down Expand Up @@ -254,6 +261,7 @@ protected void transformMappings() {

data.model().getMappings().add(mapping);
data.eMapping2Mapping().put(eMapping, mapping);
gipsl2gipsTrace.map(eMapping, mapping);
});
}

Expand Down Expand Up @@ -286,6 +294,7 @@ protected void transformMappingVariables(GipsMapping mapping, RuleMapping ruleMa
ruleMapping.getBoundVariables().add(var);
data.model().getVariables().add(var);
data.eVariable2Variable().put(gipsVar, var);
gipsl2gipsTrace.map(gipsVar, var);
} else {
Variable var = factory.createVariable();
var.setType(GipsTransformationUtils.typeToVariableType(gipsVar.getType()));
Expand All @@ -295,6 +304,7 @@ protected void transformMappingVariables(GipsMapping mapping, RuleMapping ruleMa
ruleMapping.getFreeVariables().add(var);
data.model().getVariables().add(var);
data.eVariable2Variable().put(gipsVar, var);
gipsl2gipsTrace.map(gipsVar, var);
}
}
}
Expand All @@ -312,6 +322,7 @@ protected void transformMappingVariables(GipsMapping mapping, PatternMapping pat
patternMapping.getFreeVariables().add(var);
data.model().getVariables().add(var);
data.eVariable2Variable().put(gipsVar, var);
gipsl2gipsTrace.map(gipsVar, var);
}
}

Expand Down Expand Up @@ -350,6 +361,7 @@ protected void transformConstraints() throws Exception {
case DISJUNCTION_OF_LITERALS -> {
Constraint disjunction = createDisjunctConstraint(eSubConstraint, constraintCounter);
data.model().getConstraints().add(disjunction);
gipsl2gipsTrace.map(eConstraint, disjunction);
constraintCounter++;

Map<GipsConstraint, Collection<Constraint>> transformed = new HashMap<>();
Expand All @@ -363,6 +375,7 @@ protected void transformConstraints() throws Exception {
symbolicVariable);
constraints.forEach(c -> c.setSymbolicVariable(symbolicVariable));
transformed.put(subConstraint, constraints);
gipsl2gipsTrace.mapOneToMany(eConstraint, constraints);
disjunction.getDependencies().addAll(constraints);
}

Expand Down Expand Up @@ -442,12 +455,17 @@ protected void transformConstraints() throws Exception {

substituteRelation.setLhs(substituteSum);
disjunction.setExpression(substituteRelation);
gipsl2gipsTrace.map(eConstraint.getExpression(), disjunction.getExpression());
}
case LITERAL -> {
transformConstraint(eSubConstraint.result().values().iterator().next(), false, null);
Collection<Constraint> constraints = transformConstraint(
eSubConstraint.result().values().iterator().next(), false, null);
gipsl2gipsTrace.mapOneToMany(eConstraint, constraints);
}
case NEGATED_LITERAL -> {
transformConstraint(eSubConstraint.result().values().iterator().next(), true, null);
Collection<Constraint> constraints = transformConstraint(
eSubConstraint.result().values().iterator().next(), true, null);
gipsl2gipsTrace.mapOneToMany(eConstraint, constraints);
}
default -> {
throw new IllegalArgumentException("Unknown constraint annotation type.");
Expand Down Expand Up @@ -519,6 +537,7 @@ protected void transformLinearFunctions() throws Exception {
LinearFunction linearFunction = createLinearFunction(eLinearFunction);
data.model().getFunctions().add(linearFunction);
data.eFunction2Function().put(eLinearFunction, linearFunction);
gipsl2gipsTrace.map(eLinearFunction, linearFunction);

// Create all constants
if (eLinearFunction.getConstants() != null && !eLinearFunction.getConstants().isEmpty()) {
Expand All @@ -543,6 +562,7 @@ protected void transformLinearFunctions() throws Exception {
// of products.
linearFunction.setExpression(
new GipsArithmeticTransformer(factory).normalizeAndExpand(linearFunction.getExpression()));
gipsl2gipsTrace.map(eLinearFunction.getExpression(), linearFunction.getExpression());
}
}

Expand All @@ -554,6 +574,7 @@ protected void transformObjective() throws Exception {

Objective objective = factory.createObjective();
data.model().setObjective(objective);
gipsl2gipsTrace.map(eObjective, objective);

// Create all constants
if (eObjective.getConstants() != null && !eObjective.getConstants().isEmpty()) {
Expand Down Expand Up @@ -588,6 +609,7 @@ protected void transformObjective() throws Exception {
// Rewrite the expression, which will be translated into ILP-Terms, into a sum
// of products.
objective.setExpression(new GipsArithmeticTransformer(factory).normalizeAndExpand(objective.getExpression()));
gipsl2gipsTrace.map(eObjective.getExpression(), objective.getExpression());
}

protected Constraint createConstraint(final GipsConstraint eConstraint, int counter) {
Expand Down Expand Up @@ -782,6 +804,7 @@ protected void mapGT2IBeXElements() {
for (IBeXRule rule : data.model().getIbexModel().getRuleSet().getRules()) {
if (rule.getName().equals(ePattern.getName())) {
data.addRule(ePattern, rule);
gipsl2gipsTrace.map(ePattern, rule);
}
}
}
Expand All @@ -795,10 +818,12 @@ protected void mapGT2IBeXElements() {
for (IBeXContext pattern : data.model().getIbexModel().getPatternSet().getContextPatterns()) {
if (pattern.getName().equals(ePattern.getName())) {
data.addPattern(ePattern, pattern);
gipsl2gipsTrace.map(ePattern, pattern);
for (EditorNode eNode : ePattern.getNodes()) {
for (IBeXNode node : toContextPattern(pattern).getSignatureNodes()) {
if (eNode.getName().equals(node.getName())) {
data.eNode2Node().putIfAbsent(eNode, node);
gipsl2gipsTrace.map(eNode, node);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions org.emoflon.gips.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Automatic-Module-Name: org.emoflon.gips.core
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.emoflon.ibex.gt;visibility:=reexport,
org.emoflon.gips.intermediate;visibility:=reexport,
org.emoflon.gips.core.dependencies;visibility:=reexport,
org.emoflon.gips.build
org.emoflon.gips.core.dependencies;bundle-version="1.0.0";visibility:=reexport,
org.emoflon.gips.build,
org.emoflon.gips.debugger;bundle-version="[1.0.0,2.0.0)";visibility:=reexport
Export-Package: org.emoflon.gips.core,
org.emoflon.gips.core.api,
org.emoflon.gips.core.gt,
Expand Down
55 changes: 55 additions & 0 deletions org.emoflon.gips.core/src/org/emoflon/gips/core/GipsEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import org.emoflon.gips.core.milp.Solver;
import org.emoflon.gips.core.milp.SolverOutput;
import org.emoflon.gips.core.milp.SolverStatus;
import org.emoflon.gips.core.milp.model.Constraint;
import org.emoflon.gips.core.milp.model.Term;
import org.emoflon.gips.core.milp.model.Variable;
import org.emoflon.gips.core.util.Observer;
import org.emoflon.gips.core.validation.GipsConstraintValidationLog;
import org.emoflon.gips.debugger.api.ILPTraceKeywords;
import org.emoflon.gips.debugger.api.Intermediate2IlpTracer;

public abstract class GipsEngine {

Expand All @@ -24,6 +28,7 @@ public abstract class GipsEngine {
final protected Map<String, GipsLinearFunction<?, ?, ?>> functions = Collections.synchronizedMap(new HashMap<>());
protected GipsObjective objective;
protected Solver solver;
final protected Intermediate2IlpTracer tracer = new Intermediate2IlpTracer();

public abstract void update();

Expand Down Expand Up @@ -108,6 +113,52 @@ public void buildProblem(boolean doUpdate) {
objective.buildObjectiveFunction();

solver.buildILPProblem();
buildTracingTree();
}

protected void buildTracingTree() {
Intermediate2IlpTracer tracer = getTracer();
if (!tracer.isTracingEnabled())
return;

// try to build a bridge between ILP model and ILP text file

for (GipsMapper<?> mapper : this.mappers.values()) {
tracer.map(mapper.mapping,
ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_MAPPING, mapper.getName()));
// final var fragmentPath = EcoreUtil.getURI(mapper.mapping);
}

for (GipsConstraint<?, ?, ?> constraint : this.constraints.values()) {
tracer.map(constraint.constraint,
ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_CONSTRAINT, constraint.getName()));
for (Constraint ilpConstraint : constraint.getConstraints()) {
for (Term ilpTerm : ilpConstraint.lhsTerms()) {
tracer.map(constraint.constraint.getExpression(), ILPTraceKeywords
.buildElementId(ILPTraceKeywords.TYPE_CONSTRAINT_VAR, ilpTerm.variable().getName()));
}
}

for (Variable<?> variables : constraint.getAdditionalVariables()) {
tracer.map(constraint.constraint.getExpression(),
ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_CONSTRAINT_VAR, variables.getName()));
}
}

for (GipsLinearFunction<?, ?, ?> function : this.functions.values()) {
tracer.map(function.linearFunction,
ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_FUNCTION, function.getName()));
for (Term term : function.terms) {
tracer.map(function.linearFunction,
ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_FUNCTION_VAR, term.variable().getName()));
}
}

if (objective != null) {
tracer.map(objective.objective, ILPTraceKeywords.buildElementId(ILPTraceKeywords.TYPE_OBJECTIVE, ""));
}

tracer.postTraceToRMIService();
}

public SolverOutput solveProblemTimed() {
Expand Down Expand Up @@ -233,4 +284,8 @@ protected void setObjective(final GipsObjective objective) {
public void setSolver(final Solver solver) {
this.solver = solver;
}

public Intermediate2IlpTracer getTracer() {
return this.tracer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public ResourceSet getResourceSet() {
* Terminates the GipsEngine (super class) and the eMoflon::IBeX engine
* (including the pattern matcher).
*/
@Override
public void terminate() {
// Terminate the GipsEngine
super.terminate();
Expand Down Expand Up @@ -292,6 +293,7 @@ private void initInternalCommon(final URI gipsModelURI) {
initTypeIndexer();
validationLog = new GipsConstraintValidationLog();
setSolverConfig(gipsModel.getConfig());
initTracer();
initMapperFactory();
createMappers();
initConstraintFactory();
Expand Down Expand Up @@ -327,6 +329,11 @@ protected void loadIntermediateModel(final URI gipsModelURI) {
gipsModel.getMappings().forEach(mapping -> name2Mapping.put(mapping.getName(), mapping));
}

protected void initTracer() {
tracer.computeGipsModelId(gipsModel.eResource().getURI());
tracer.computeLpModelId(gipsModel.getConfig().getLpPath());
}

protected abstract void createMappers();

protected void createConstraints() {
Expand Down
Loading