viatra / VIATRA-Generator

An efficient graph solver for generating well-formed models
Eclipse Public License 1.0
26 stars 5 forks source link

java.lang.IllegalArgumentException in transformQueries method #5

Open mayerkr opened 7 years ago

mayerkr commented 7 years ago

Description

The transformQueries method found in viatra2logic runs into an IllegalArgumentException with the following query:

Query used:

pattern availableGreaterThanTotalCpu(host : HostInstance) {
    HostInstance.availableCpu(host, aCpu);
    HostInstance.totalCpu(host, tCpu);

    check(aCpu > tCpu);
}

Relevant code in main:

    def static void main(String[] args) {
        val inputs = new FileSystemWorkspace('''initialModels/''',"")
        val workspace = new FileSystemWorkspace('''outputModels/''',"")
        workspace.initAndClear

        println("Input and output workspaces are created")

        val metamodel = loadMetamodel()
        val partialModel = loadPartialModel(inputs)
        val queries = loadQueries(metamodel)

        println("DSL loaded")

        val Ecore2Logic ecore2Logic = new Ecore2Logic
        val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic)
        val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic)
        val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic        
        val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel,new Ecore2LogicConfiguration())
        val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem,partialModel)
        val validModelExtensionProblem = viatra2Logic.transformQueries(queries,modelGenerationProblem,new Viatra2LogicConfiguration)
//...
}

Log/Trace:

...
hostInstance (scoped) http://org.eclipse.viatra/model/cps/HostInstance
pattern cpsgen patterns availableGreaterThanTotalCpu
host (scoped) http://org.eclipse.viatra/model/cps/HostInstance
Exception in thread "main" java.lang.IllegalArgumentException: The map does not contains the key "PQuery<cpsgen.patterns.stateTransition>=cpsgen.patterns.internal.StateTransitionQuerySpecification$GeneratedPQuery@72ef8d15"!
--- Elements: ---
PQuery<cpsgen.patterns.reachableAppInstance>=cpsgen.patterns.util.ReachableAppInstanceQuerySpecification$GeneratedPQuery@1b410b60 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@6aa8e115 (name: pattern cpsgen patterns reachableAppInstance)
PQuery<cpsgen.patterns.notAllocatedButRunning>=cpsgen.patterns.util.NotAllocatedButRunningQuerySpecification$GeneratedPQuery@1ec9bd38 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@5e21e98f (name: pattern cpsgen patterns notAllocatedButRunning)
PQuery<cpsgen.patterns.availableGreaterThanTotalHdd>=cpsgen.patterns.util.AvailableGreaterThanTotalHddQuerySpecification$GeneratedPQuery@70e38ce1 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@51a9ad5e (name: pattern cpsgen patterns availableGreaterThanTotalHdd)
PQuery<cpsgen.patterns.initialStateNotContainedByStateMachine>=cpsgen.patterns.util.InitialStateNotContainedByStateMachineQuerySpecification$GeneratedPQuery@51bf5add -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@5f20155b (name: pattern cpsgen patterns initialStateNotContainedByStateMachine)
PQuery<cpsgen.patterns.appTypeInstanceAndHost>=cpsgen.patterns.util.AppTypeInstanceAndHostQuerySpecification$GeneratedPQuery@4bc222e -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@72ade7e3 (name: pattern cpsgen patterns appTypeInstanceAndHost)
PQuery<cpsgen.patterns.transitionWithoutTargetState>=cpsgen.patterns.util.TransitionWithoutTargetStateQuerySpecification$GeneratedPQuery@638ef7ed -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@239105a8 (name: pattern cpsgen patterns transitionWithoutTargetState)
PQuery<cpsgen.patterns.targetStateNotContainedBySameStateMachine>=cpsgen.patterns.util.TargetStateNotContainedBySameStateMachineQuerySpecification$GeneratedPQuery@1ebea008 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@3fce8fd9 (name: pattern cpsgen patterns targetStateNotContainedBySameStateMachine)
PQuery<cpsgen.patterns.hostCommunication>=cpsgen.patterns.util.HostCommunicationQuerySpecification$GeneratedPQuery@471a9022 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@609bcfb6 (name: pattern cpsgen patterns hostCommunication)
PQuery<cpsgen.patterns.reachableHosts>=cpsgen.patterns.util.ReachableHostsQuerySpecification$GeneratedPQuery@6f8e8894 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@7d94beb9 (name: pattern cpsgen patterns reachableHosts)
PQuery<cpsgen.patterns.multipleApplicationInstanceInCommunicationGroup>=cpsgen.patterns.util.MultipleApplicationInstanceInCommunicationGroupQuerySpecification$GeneratedPQuery@478db956 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@560348e6 (name: pattern cpsgen patterns multipleApplicationInstanceInCommunicationGroup)
PQuery<cpsgen.patterns.availableGreaterThanTotalRam>=cpsgen.patterns.util.AvailableGreaterThanTotalRamQuerySpecification$GeneratedPQuery@4b2c5e02 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@1df8b5b8 (name: pattern cpsgen patterns availableGreaterThanTotalRam)
PQuery<cpsgen.patterns.availableGreaterThanTotalCpu>=cpsgen.patterns.util.AvailableGreaterThanTotalCpuQuerySpecification$GeneratedPQuery@102cec62 -> hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.impl.RelationDefinitionImpl@23202fce (name: pattern cpsgen patterns availableGreaterThanTotalCpu)
-----------------
    at hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.lookup(CollectionsUtil.java:51)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Constraint2Logic._transformConstraint(Constraint2Logic.java:83)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Constraint2Logic.transformConstraint(Constraint2Logic.java:218)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic.lambda$4(Viatra2Logic.java:303)
    at org.eclipse.xtext.xbase.lib.internal.FunctionDelegate.apply(FunctionDelegate.java:42)
    at com.google.common.collect.Iterators$7.transform(Iterators.java:750)
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47)
    at com.google.common.collect.Iterators$6.computeNext(Iterators.java:616)
    at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:145)
    at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:140)
    at com.google.common.collect.TransformedIterator.hasNext(TransformedIterator.java:42)
    at com.google.common.collect.Iterators.addAll(Iterators.java:366)
    at com.google.common.collect.Iterables.addAll(Iterables.java:332)
    at hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder.lambda$47(LogicProblemBuilder.java:957)
    at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
    at hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder.And(LogicProblemBuilder.java:959)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic.transformBody(Viatra2Logic.java:306)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic.transformQuerySpecification(Viatra2Logic.java:193)
    at hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic.transformQueries(Viatra2Logic.java:113)
    at cpsgen.Run.main(Run.java:84)
mayerkr commented 7 years ago

Seems like it was caused by referenced private queries.

mayerkr commented 7 years ago

Original issue can be worked around by explicitly adding all patterns to the ViatraQuerySetDescriptor.

It should be considered to collect all referenced patterns by the framework automatically.