Package com.opengamma.engine.depgraph

Examples of com.opengamma.engine.depgraph.DependencyGraph


    assertFalse(ak.equals(bk));
    assertFalse(bk.equals(ak));
  }

  public void testDependencyGraphKey_node() {
    final DependencyGraph a = createDependencyGraph();
    final DependencyNode n = new DependencyNode(new ComputationTarget(ComputationTargetType.PRIMITIVE, UniqueId.of("Test", "A")));
    n.setFunction(new MockFunction("Foo", new ComputationTarget(ComputationTargetType.PRIMITIVE, UniqueId.of("Test", "A"))));
    n.addInputValue(new ValueSpecification("1", ComputationTargetSpecification.of(UniqueId.of("Test", "X")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Bar").get()));
    n.addInputValue(new ValueSpecification("2", ComputationTargetSpecification.of(UniqueId.of("Test", "X")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Bar").get()));
    n.addOutputValue(new ValueSpecification("1", ComputationTargetSpecification.of(UniqueId.of("Test", "A")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Foo").get()));
    n.addOutputValue(new ValueSpecification("2", ComputationTargetSpecification.of(UniqueId.of("Test", "A")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Foo").get()));
    a.addDependencyNode(n);
    final DependencyGraph b = createDependencyGraph();
    final DependencyGraphKey ak = new DependencyGraphKey(a, 0);
    final DependencyGraphKey bk = new DependencyGraphKey(b, 0);
    assertFalse(ak.equals(bk));
    assertFalse(bk.equals(ak));
  }
View Full Code Here


  }

  //-------------------------------------------------------------------------
  public void testCache_identity() {
    final CachingExecutionPlanner cache = new CachingExecutionPlanner(createExecutionPlanner(), _cacheManager);
    final DependencyGraph graph = createDependencyGraph();
    final GraphExecutionPlan plan1 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    final GraphExecutionPlan plan2 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    assertNotNull(plan1);
    assertNotNull(plan2);
    assertSame(plan2, plan1);
View Full Code Here

    cache.shutdown();
  }

  public void testCache_identity_differentGraph() {
    final CachingExecutionPlanner cache = new CachingExecutionPlanner(createExecutionPlanner(), _cacheManager);
    final DependencyGraph graph = createDependencyGraph();
    final GraphExecutionPlan plan1 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    // The caching by identity is to avoid the overhead of constructing the key. This is okay if the graph is not modified after it has been
    // used, but will cause problems if we change that behaviour. Currently, even an incremental graph build will construct a new dependency
    // graph object afterwards - although graph nodes may be reused and altered.
    graph.addTerminalOutput(new ValueRequirement("1", ComputationTargetSpecification.of(UniqueId.of("Test", "X"))),
        new ValueSpecification("1", ComputationTargetSpecification.of(UniqueId.of("Test", "X")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Foo1").get()));
    final GraphExecutionPlan plan2 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    assertNotNull(plan1);
    assertNotNull(plan2);
    assertSame(plan2, plan1);
View Full Code Here

    cache.shutdown();
  }

  public void testCache_mismatch() {
    final CachingExecutionPlanner cache = new CachingExecutionPlanner(createExecutionPlanner(), _cacheManager);
    DependencyGraph graph = createDependencyGraph();
    final GraphExecutionPlan plan1 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    graph = createDependencyGraph();
    graph.addTerminalOutput(new ValueRequirement("1", ComputationTargetSpecification.of(UniqueId.of("Test", "X"))),
        new ValueSpecification("1", ComputationTargetSpecification.of(UniqueId.of("Test", "X")), ValueProperties.with(ValuePropertyNames.FUNCTION, "Foo1").get()));
    final GraphExecutionPlan plan2 = cache.createPlan(graph, Mockito.mock(ExecutionLogModeSource.class), 0);
    assertNotSame(plan2, plan1);
    assertNotNull(plan1);
    assertNotNull(plan2);
View Full Code Here

        throw new RuntimeException("Unexpected node type" + node.getComputationTarget().getType());
      }
    }
    // Execute primitives and wait for completion
    s_logger.info("Executing {} PRIMITIVE nodes", primitiveNodes.size());
    final DependencyGraph primitiveGraph = graph.subGraph(primitiveNodes);
    try {
      final Future<?> future = _delegate.execute(primitiveGraph);
      future.get();
    } catch (final InterruptedException e) {
      Thread.interrupted();
      throw new RuntimeException("Should not have been interrupted");
    } catch (final ExecutionException e) {
      throw new RuntimeException("Execution of primitives failed", e);
    }
    // Execute securities and positions, pass by pass, one by one and wait for completion
    s_logger.info("Executing {} passes of SECURITY and POSITION nodes", passNumber2Target2SecurityAndPositionNodes.size());
    int passNumber = 0;
    for (final Map<UniqueId, Collection<DependencyNode>> target2SecurityAndPositionNodes : passNumber2Target2SecurityAndPositionNodes) {
      s_logger.info("Executing pass number {}", passNumber, target2SecurityAndPositionNodes.size());
      final LinkedList<Future<?>> secAndPositionFutures = new LinkedList<Future<?>>();
      int nodeCount = 0;
      for (final Collection<DependencyNode> nodesRelatedToSingleTarget : target2SecurityAndPositionNodes.values()) {
        final DependencyGraph secAndPositionGraph = graph.subGraph(nodesRelatedToSingleTarget);
        nodeCount += nodesRelatedToSingleTarget.size();
        final Future<?> future = _delegate.execute(secAndPositionGraph);
        secAndPositionFutures.add(future);
      }
      s_logger.info("Pass number {} has {} different computation targets, and a total of {} nodes",
          new Object[] {passNumber, target2SecurityAndPositionNodes.size(), nodeCount });
      for (final Future<?> secAndPositionFuture : secAndPositionFutures) {
        try {
          secAndPositionFuture.get();
        } catch (final InterruptedException e) {
          Thread.interrupted();
          throw new RuntimeException("Should not have been interrupted");
        } catch (final ExecutionException e) {
          throw new RuntimeException("Execution of securities failed", e);
        }
      }
      passNumber++;
    }
    // Execute portfolios and wait for completion
    s_logger.info("Executing {} PORTFOLIO_NODE nodes", portfolioNodes.size());
    final DependencyGraph portfolioGraph = graph.subGraph(portfolioNodes);
    try {
      final Future<?> future = _delegate.execute(portfolioGraph);
      future.get();
    } catch (final InterruptedException e) {
      Thread.interrupted();
View Full Code Here

  public void execute() throws InterruptedException {
    final DependencyGraphExecutor executor = getCycle().getViewProcessContext().getDependencyGraphExecutorFactory().createExecutor(getCycle());
    for (final String calcConfigurationName : getCycle().getAllCalculationConfigurationNames()) {
      s_logger.info("Executing plans for calculation configuration {}", calcConfigurationName);
      final DependencyGraph depGraph = getCycle().createExecutableDependencyGraph(calcConfigurationName);
      s_logger.info("Submitting {} for execution by {}", depGraph, executor);
      final DependencyGraphExecutionFuture future = executor.execute(depGraph);
      _executing.put(calcConfigurationName, new ExecutingCalculationConfiguration(getCycle(), depGraph, future));
      future.setListener(this);
    }
View Full Code Here

    final ExecutingCalculationConfiguration calcConfig = _executing.get(calculationConfiguration);
    if (calcConfig == null) {
      s_logger.warn("Job fragment result for already completed configuration {}", calculationConfiguration);
      return;
    }
    final DependencyGraph graph = calcConfig.getDependencyGraph();
    final Iterator<CalculationJobItem> jobItemItr = job.getJobItems().iterator();
    final Iterator<CalculationJobResultItem> jobResultItr = jobResult.getResultItems().iterator();
    final ExecutionLogModeSource logModes = getCycle().getLogModeSource();
    final DependencyNodeJobExecutionResultCache jobExecutionResultCache = calcConfig.getResultCache();
    final Set<ValueSpecification> terminalOutputs = calcConfig.getTerminalOutputs();
    final String computeNodeId = jobResult.getComputeNodeId();
    while (jobItemItr.hasNext()) {
      assert jobResultItr.hasNext();
      final CalculationJobItem jobItem = jobItemItr.next();
      final CalculationJobResultItem jobResultItem = jobResultItr.next();
      // Mark the node that corresponds to this item
      final DependencyNode node = graph.getNodeProducing(jobItem.getOutputs()[0]);
      if (jobResultItem.isFailed()) {
        getCycle().markFailed(node);
      } else {
        getCycle().markExecuted(node);
      }
View Full Code Here

    final Collection<CompiledViewCalculationConfiguration> compiledViewCalculationConfigurations = new ArrayList<>();

    for (Map.Entry<String, DependencyGraphExplorer> entry : graphsByConfiguration.entrySet()) {

      String configName = entry.getKey();
      DependencyGraph graph = entry.getValue().getWholeGraph();
      CompiledViewCalculationConfiguration cvcc = createCalculationConfiguration(configName, graph, selectionsByGraph, paramsByGraph, compiledCalculationConfigurations);
      compiledViewCalculationConfigurations.add(cvcc);
    }

    return compiledViewCalculationConfigurations;
View Full Code Here

      final Set<ValueRequirement> specificRequirements = calcConfig.getSpecificRequirements();
      final Pair<DependencyGraph, Set<ValueRequirement>> previousGraphEntry = previousGraphs.get(calcConfig.getName());
      if (previousGraphEntry == null) {
        continue;
      }
      final DependencyGraph previousGraph = previousGraphEntry.getFirst();
      final Map<ValueSpecification, Set<ValueRequirement>> terminalOutputs = previousGraph.getTerminalOutputs();
      final ValueSpecification[] removeSpecifications = new ValueSpecification[terminalOutputs.size()];
      @SuppressWarnings("unchecked")
      final List<ValueRequirement>[] removeRequirements = new List[terminalOutputs.size()];
      int remove = 0;
      for (final Map.Entry<ValueSpecification, Set<ValueRequirement>> entry : terminalOutputs.entrySet()) {
        if (unmapped.contains(entry.getKey().getTargetSpecification().getUniqueId())) {
          List<ValueRequirement> removal = null;
          for (final ValueRequirement requirement : entry.getValue()) {
            if (!specificRequirements.contains(requirement)) {
              if (removal == null) {
                removal = new ArrayList<>(entry.getValue().size());
              }
              removal.add(requirement);
            }
            // Anything that was in the specific requirements will be captured by the standard invalid identifier tests
          }
          if (removal != null) {
            removeSpecifications[remove] = entry.getKey();
            removeRequirements[remove++] = removal;
          }
        }
      }
      for (int i = 0; i < remove; i++) {
        previousGraph.removeTerminalOutputs(removeRequirements[i], removeSpecifications[i]);
      }
      if (!mapped.isEmpty()) {
        final ComputationTargetIdentifierRemapVisitor remapper = new ComputationTargetIdentifierRemapVisitor(mapped);
        final Collection<Object> replacements = new ArrayList<>(mapped.size() * 2);
        for (DependencyNode node : previousGraph.getDependencyNodes()) {
          final ComputationTargetSpecification newTarget = remapper.remap(node.getComputationTarget());
          if (newTarget != null) {
            replacements.add(node);
            replacements.add(newTarget);
          }
        }
        Iterator<Object> itrReplacements = replacements.iterator();
        while (itrReplacements.hasNext()) {
          final DependencyNode node = (DependencyNode) itrReplacements.next();
          final ComputationTargetSpecification newTarget = (ComputationTargetSpecification) itrReplacements.next();
          s_logger.debug("Rewriting {} to {}", node, newTarget);
          previousGraph.replaceNode(node, newTarget);
        }
        // Rewrite the original value requirements that might have referenced the original nodes
        for (Map.Entry<ValueSpecification, Set<ValueRequirement>> terminalOutput : previousGraph.getTerminalOutputs().entrySet()) {
          final Set<ValueRequirement> oldReqs = terminalOutput.getValue();
          replacements.clear();
          for (ValueRequirement req : oldReqs) {
            final ComputationTargetReference newTarget = req.getTargetReference().accept(remapper);
            if (newTarget != null) {
View Full Code Here

      final CompiledViewDefinitionWithGraphs compiledViewDefinition) {
    if (previousGraphs == null) {
      final Collection<DependencyGraphExplorer> graphExps = compiledViewDefinition.getDependencyGraphExplorers();
      previousGraphs = Maps.newHashMapWithExpectedSize(graphExps.size());
      for (DependencyGraphExplorer graphExp : graphExps) {
        final DependencyGraph graph = graphExp.getWholeGraph();
        previousGraphs.put(graph.getCalculationConfigurationName(), Pair.<DependencyGraph, Set<ValueRequirement>>of(graph, new HashSet<ValueRequirement>()));
      }
    }
    return previousGraphs;
  }
View Full Code Here

TOP

Related Classes of com.opengamma.engine.depgraph.DependencyGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.