Package com.opengamma.engine.depgraph

Examples of com.opengamma.engine.depgraph.DependencyGraph


  private void filterPreviousGraphs(final Map<String, Pair<DependencyGraph, Set<ValueRequirement>>> previousGraphs, final DependencyNodeFilter filter, final Set<UniqueId> unchangedNodes) {
    final Iterator<Map.Entry<String, Pair<DependencyGraph, Set<ValueRequirement>>>> itr = previousGraphs.entrySet().iterator();
    final Filter subGrapher = new Filter(filter, unchangedNodes);
    while (itr.hasNext()) {
      final Map.Entry<String, Pair<DependencyGraph, Set<ValueRequirement>>> entry = itr.next();
      final DependencyGraph filtered = subGrapher.subGraph(entry.getValue().getFirst(), entry.getValue().getSecond());
      if (filtered != entry.getValue().getFirst()) {
        if (filtered.getSize() == 0) {
          s_logger.info("Discarded total dependency graph for {}", entry.getKey());
          itr.remove();
        } else {
          if (s_logger.isInfoEnabled()) {
            s_logger.info("Removed {} nodes from dependency graph for {} by {}",
                entry.getValue().getFirst().getSize() - filtered.getSize(),
                entry.getKey(),
                filter);
          }
          entry.setValue(Pair.of(filtered, entry.getValue().getSecond()));
        }
View Full Code Here


      Map<DependencyGraph, Map<DistinctMarketDataSelector, Set<ValueSpecification>>> selectionsByGraph = new HashMap<>();
      Map<DependencyGraph, Map<DistinctMarketDataSelector, FunctionParameters>> functionParamsByGraph = new HashMap<>();

      for (DependencyGraphExplorer graphExplorer : compiledViewDefinition.getDependencyGraphExplorers()) {

        DependencyGraph graph = graphExplorer.getWholeGraph();
        final Map<DistinctMarketDataSelector, Set<ValueSpecification>> selectorMapping =
            _marketDataSelectionGraphManipulator.modifyDependencyGraph(graph, resolver);

        if (!selectorMapping.isEmpty()) {

          selectionsByGraph.put(graph, selectorMapping);
          Map<DistinctMarketDataSelector, FunctionParameters> params =
              _specificMarketDataSelectors.get(graph.getCalculationConfigurationName());

          // _specificMarketDataSelectors has an entry for each graph, so no null check required
          if (!params.isEmpty()) {

            // Filter the function params so that we only have entries for active selectors
View Full Code Here

    if (_compiledViewDefinition == null) {
      return null;
    }
    String calcConfigName = target.getFirst();
    ValueSpecification valueSpec = target.getSecond();
    DependencyGraph depGraph = _graphs.get(calcConfigName);
    if (depGraph == null) {
      try {
        depGraph = _compiledViewDefinition.getDependencyGraphExplorer(calcConfigName).getWholeGraph();
      } catch (Exception e) {
        // No graph available - an empty one will return null for any of the value specifications
        depGraph = new DependencyGraph(calcConfigName);
      }
      _graphs.put(calcConfigName, depGraph);
    }
    DependencyNode node = depGraph.getNodeProducing(valueSpec);
    return node;
  }
View Full Code Here

              final Map<String, Collection<ComputationTargetSpecification>> configToComputationTargets = new HashMap<>();
              final Map<String, Map<ValueSpecification, Set<ValueRequirement>>> configToTerminalOutputs = new HashMap<>();
              final MarketDataSnapshot marketDataSnapshot = snapshotManager.getSnapshot();

              for (DependencyGraphExplorer graphExp : compiledViewDefinition.getDependencyGraphExplorers()) {
                final DependencyGraph graph = graphExp.getWholeGraph();
                configToComputationTargets.put(graph.getCalculationConfigurationName(), graph.getAllComputationTargets());
                configToTerminalOutputs.put(graph.getCalculationConfigurationName(), graph.getTerminalOutputs());
              }
              if (isTerminated()) {
                return;
              }
              cycleStarted(new DefaultViewCycleMetadata(
View Full Code Here

      }
      _terminalOutputs = graph.getTerminalOutputs();
    }

    public DependencyGraph get(final CompiledFunctionRepository functions) {
      final DependencyGraph graph = new DependencyGraph(_calcConfig);
      for (int i = 0; i < _nodeTargets.length; i++) {
        final DependencyNode node = new DependencyNode(_nodeTargets[i]);
        for (ValueSpecification input : _nodeInputs[i]) {
          node.addInputValue(input);
        }
        node.addOutputValues(_nodeOutputs[i]);
        node.setFunction(new ParameterizedFunction(functions.getDefinition(_nodeFunctions[i]), _nodeParameters[i]));
        graph.addDependencyNode(node);
      }
      for (DependencyNode node : graph.getDependencyNodes()) {
        for (ValueSpecification inputValue : node.getInputValues()) {
          final DependencyNode inputNode = graph.getNodeProducing(inputValue);
          if (inputNode != null) {
            node.addInputNode(inputNode);
          }
        }
      }
      graph.addTerminalOutputs(_terminalOutputs);
      return graph;
    }
View Full Code Here

    }
    return newNode;
  }

  private DependencyGraph copy(final DependencyGraph copyFrom) {
    final DependencyGraph copyTo = new DependencyGraph(copyFrom.getCalculationConfigurationName());
    for (DependencyNode node : copyFrom.getDependencyNodes()) {
      copyTo.addDependencyNode(getOrCreateCopy(node));
    }
    copyTo.addTerminalOutputs(copyFrom.getTerminalOutputs());
    return copyTo;
  }
View Full Code Here

        calculationConfiguration.getMarketDataSelections();

    if (!marketDataSelections.isEmpty()) {

      s_logger.info("Building function parameters for market data manipulation in graph [{}]", calcConfigurationName);
      DependencyGraph graph = _compiledViewDefinition.getDependencyGraphExplorer(calcConfigurationName).getWholeGraph();

      // Get function params configured through the view definition
      Map<DistinctMarketDataSelector, FunctionParameters> functionParameters =
          Maps.newHashMap(calculationConfiguration.getMarketDataSelectionFunctionParameters());
      s_logger.info("Added in function parameters from view definition - now have {} entries", functionParameters.size());

      // Add the function params passed through the execution options which will
      // potentially override the same functions from the view definition
      // A future enhancement could look at merging/composing the functions if desired
      functionParameters.putAll(_executionOptions.getFunctionParameters());
      s_logger.info("Added in function parameters from execution options - now have {} entries",
          functionParameters.size());

      int nodeCount = 0;

      for (Map.Entry<DistinctMarketDataSelector, Set<ValueSpecification>> entry : marketDataSelections.entrySet()) {

        DistinctMarketDataSelector selector = entry.getKey();
        Set<ValueSpecification> matchingSpecifications = entry.getValue();

        for (ValueSpecification valueSpecification : matchingSpecifications) {
          FunctionParameters parameters;
          if (functionParameters.containsKey(selector)) {
            parameters = functionParameters.get(selector);
          } else {
            parameters = new EmptyFunctionParameters();
          }
          DependencyNode node = graph.getNodeProducing(valueSpecification);
          node.setFunction(new ParameterizedFunction(node.getFunction().getFunction(), parameters));
          nodeCount++;
        }
      }
      s_logger.info("Inserted manipulation functions and parameters into {} nodes", nodeCount);
View Full Code Here

      throw new IllegalArgumentException("State of previous cycle must be " + ViewCycleState.EXECUTED);
    }
    final InMemoryViewComputationResultModel fragmentResultModel = constructTemplateResultModel();
    final InMemoryViewComputationResultModel fullResultModel = getResultModel();
    for (final DependencyGraphExplorer depGraphExplorer : getCompiledViewDefinition().getDependencyGraphExplorers()) {
      final DependencyGraph depGraph = depGraphExplorer.getWholeGraph();
      final ViewComputationCache cache = getComputationCache(depGraph.getCalculationConfigurationName());
      final ViewComputationCache previousCache = previousCycle.getComputationCache(depGraph.getCalculationConfigurationName());
      final DependencyNodeJobExecutionResultCache jobExecutionResultCache = getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
      final DependencyNodeJobExecutionResultCache previousJobExecutionResultCache = previousCycle.getJobExecutionResultCache(depGraph.getCalculationConfigurationName());
      final LiveDataDeltaCalculator deltaCalculator = new LiveDataDeltaCalculator(depGraph, cache, previousCache);
      deltaCalculator.computeDelta();
      s_logger.info("Computed delta for calculation configuration '{}'. {} nodes out of {} require recomputation.",
          depGraph.getCalculationConfigurationName(),
          deltaCalculator.getChangedNodes().size(),
          depGraph.getSize());
      final Collection<ValueSpecification> specsToCopy = new LinkedList<>();
      final Collection<ComputedValue> errors = new LinkedList<>();
      for (final DependencyNode unchangedNode : deltaCalculator.getUnchangedNodes()) {
        if (unchangedNode.isMarketDataSourcingFunction()) {
          // Market data is already in the cache, so don't need to copy it across again
          continue;
        }
        final DependencyNodeJobExecutionResult previousExecutionResult = previousJobExecutionResultCache.find(unchangedNode.getOutputValues());
        if (getLogModeSource().getLogMode(unchangedNode) == ExecutionLogMode.FULL
            && (previousExecutionResult == null || previousExecutionResult.getJobResultItem().getExecutionLog().getEvents() == null)) {
          // Need to rerun calculation to collect logs, so cannot reuse
          continue;
        }
        final NodeStateFlag nodeState = previousCycle.getNodeState(unchangedNode);
        if (nodeState != null) {
          setNodeState(unchangedNode, nodeState);
          if (nodeState == NodeStateFlag.EXECUTED) {
            specsToCopy.addAll(unchangedNode.getOutputValues());
          } else {
            for (final ValueSpecification outputValue : unchangedNode.getOutputValues()) {
              errors.add(new ComputedValue(outputValue, MissingOutput.SUPPRESSED));
            }
          }
        }
      }
      if (!specsToCopy.isEmpty()) {
        final ComputationCycleQuery reusableResultsQuery = new ComputationCycleQuery();
        reusableResultsQuery.setCalculationConfigurationName(depGraph.getCalculationConfigurationName());
        reusableResultsQuery.setValueSpecifications(specsToCopy);
        final ComputationResultsResponse reusableResultsQueryResponse = previousCycle.queryResults(reusableResultsQuery);
        final Map<ValueSpecification, ComputedValueResult> resultsToReuse = reusableResultsQueryResponse.getResults();
        final Collection<ComputedValue> newValues = new ArrayList<>(resultsToReuse.size());
        for (final ComputedValueResult computedValueResult : resultsToReuse.values()) {
          final ValueSpecification valueSpec = computedValueResult.getSpecification();
          if (depGraph.getTerminalOutputSpecifications().contains(valueSpec)
              && getViewDefinition().getResultModelDefinition().shouldOutputResult(valueSpec, depGraph)) {
            fragmentResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
            fullResultModel.addValue(depGraph.getCalculationConfigurationName(), computedValueResult);
          }
          final Object previousValue = computedValueResult.getValue() != null ? computedValueResult.getValue() : MissingOutput.EVALUATION_ERROR;
          newValues.add(new ComputedValue(valueSpec, previousValue));
          final DependencyNodeJobExecutionResult previousDependencyNodeJobExecutionResult = previousJobExecutionResultCache.get(valueSpec);
          if (previousDependencyNodeJobExecutionResult != null) {
View Full Code Here

    _state = ViewCycleState.DESTROYED;
  }

  public void dumpComputationCachesToDisk() {
    for (final String calcConfigurationName : getAllCalculationConfigurationNames()) {
      final DependencyGraph depGraph = getDependencyGraph(calcConfigurationName);
      final ViewComputationCache computationCache = getComputationCache(calcConfigurationName);

      final TreeMap<String, Object> key2Value = new TreeMap<>();
      for (final ValueSpecification outputSpec : depGraph.getOutputSpecifications()) {
        final Object value = computationCache.getValue(outputSpec);
        key2Value.put(outputSpec.toString(), value);
      }

      try {
View Full Code Here

      DependencyNode inputNode = nodes.get(from);
      DependencyNode dependentNode = nodes.get(to);
      dependentNode.addInputNode(inputNode);
    }
   
    DependencyGraph graph = new DependencyGraph(calcConfigName);
    for (DependencyNode node : nodes) {
      graph.addDependencyNode(node);
    }
    return graph;
  }
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.