You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You 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.#fromtypingimportSet, Iterablefrompywy.core.executorimportExecutorfrompywy.core.platformimportPlatformfrompywy.core.mappingimportMappingfrompywy.graph.graphimportWayangGraphfrompywy.graph.typesimportWGraphOfVec, NodeOperator, NodeVecfrompywy.operatorsimportSinkOperatorclassTranslateContext:
"""TranslateContext contextual variables a parameters for the translation """passclassPlugin:
""" TODO: enrich this documentation A plugin contributes the following components to a :class:`Context` - mappings - channels - configurations In turn, it may require several :clas:`Platform`s for its operation. """platforms: Set[Platform]
mappings: Mappingtranslate_context: TranslateContextdef__init__(
self,
platforms: Set[Platform],
mappings: Mapping=Mapping(),
translate_context: TranslateContext=None):
self.platforms=platformsself.mappings=mappingsself.translate_context=translate_contextdefget_mappings(self) ->Mapping:
returnself.mappingsdefget_executor(self) ->Executor:
passdef__str__(self):
return"Platforms: {}, Mappings: {}".format(str(self.platforms), str(self.mappings))
def__repr__(self):
returnself.__str__()
classPywyPlan:
"""A PywyPlan consists of a set of :py:class:`pywy.operators.base.PywyOperator` the operator inside PywyPlan follow a Directed acyclic graph(DAG), and describe how the execution needs to be performed Attributes ---------- graph : :py:class:`pywy.graph.graph.WayangGraph` Graph that describe the DAG, and it provides the iterable properties to the PywyPlan plugins : :obj:`set` of :py:class:`pywy.core.plugin.Plugin` plugins is the set of possible platforms that can be uses to execute the PywyPlan sinks : :py:class:`typing.Iterable` of :py:class:`pywy.operators.sink.SinkOperator` The list of sink operators, this describe the end of the pipeline, and they are used to build the `graph` """graph: WayangGraphdef__init__(self, plugins: Set[Plugin], sinks: Iterable[SinkOperator]):
"""basic Constructor of PywyPlan this constructor set the plugins and sinks element, and it prepares everything for been executed Parameters ---------- plugins Description of `plugins`. sinks Description of `sinks`. """self.plugins=pluginsself.sinks=sinksself.set_graph()
defset_graph(self):
""" it builds the :py:class:`pywy.graph.graph.WayangGraph` of the current PywyPlan """self.graph=WGraphOfVec(self.sinks)
defexecute(self):
""" Execute the plan with the plugin provided at the moment of creation """plug=next(iter(self.plugins))
trs: Translator=Translator(plug, self)
new_plan=trs.translate()
plug.get_executor().execute(new_plan)
classTranslator:
"""Translator use the :py:class:`pywy.core.Mapping` to convert the :py:class:`pywy.operators.base.PywyOperator` Translator take a plan a produce the executable version of the plan using as tool the :py:class:`pywy.core.Mapping` of the :py:class:`pywy.core.core.Plugin` and convert the :py:class:`pywy.operators.base.PywyOperator` into an executable version inside the :py:class:`pywy.core.Platform` Attributes ---------- plugin : :py:class:`pywy.core.core.Plugin` plugin use in the translation plan : :py:class:`pywy.core.core.PywyPlan` Plan to be translated by the translator translate_context: :py:class:`pywy.core.core.TranslateContext` context used by the translates at runtime in some case is not needed """plugin: Pluginplan: PywyPlantranslate_context: TranslateContextdef__init__(self, plugin: Plugin, plan: PywyPlan):
self.plugin=pluginself.plan=planself.translate_context=plugin.translate_contextdeftranslate(self):
mappings: Mapping=self.plugin.get_mappings()
graph=WGraphOfVec(self.plan.sinks)
translate=self.translate_contextdeftranslate2plugin(current_op: NodeVec, next_op: NodeVec):
ifcurrent_opisNone:
returnifcurrent_op.current[1] isNone:
current_op.current[1] =mappings.get_instanceof(current_op.current[0], **{'translate_context': translate})
ifnext_opisNone:
returnifnext_op.current[1] isNone:
next_op.current[1] =mappings.get_instanceof(next_op.current[0], **{'translate_context': translate})
# TODO not necesary it it 0current_op.current[1].connect(0, next_op.current[1], 0)
graph.traversal(graph.starting_nodes, translate2plugin)
node= []
forelemingraph.starting_nodes:
node.append(elem.current[1])
returnPywyPlan({self.plugin}, node)
b6ebc8b05a9d10cde125dc26d12ecd81eece894f
The text was updated successfully, but these errors were encountered:
enrich this documentation
A plugin contributes the following components to a :class:
Context
mappings
channels
configurations
In turn, it may require several :clas:
Platform
s for its operation.incubator-wayang/python/old_code/src/pywy/core/core.py
Line 35 in 11682e6
b6ebc8b05a9d10cde125dc26d12ecd81eece894f
The text was updated successfully, but these errors were encountered: