本文整理汇总了Python中titus.genpy.PFAEngine.fromAst方法的典型用法代码示例。如果您正苦于以下问题:Python PFAEngine.fromAst方法的具体用法?Python PFAEngine.fromAst怎么用?Python PFAEngine.fromAst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类titus.genpy.PFAEngine
的用法示例。
在下文中一共展示了PFAEngine.fromAst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: engine
# 需要导入模块: from titus.genpy import PFAEngine [as 别名]
# 或者: from titus.genpy.PFAEngine import fromAst [as 别名]
def engine(pfas, name=None, randseed=None, doc=None, version=None, metadata={}, options={}, tryYaml=False, verbose=False, sharedState=None, multiplicity=1, style="pure", debug=False):
"""Create a single PFA from a chained workflow, returning the result as an executable scoring engine.
:type pfas: list of titus.pfaast.EngineConfig, Pythonized JSON, or JSON strings
:param pfas: PFA documents for which the output of document *i* is the input to document *i + 1*
:type check: bool
:param check: test the chained PFA for validity
:type name: string or ``None``
:param name: optional name for the chained PFA
:type randseed: integer or ``None``
:param randseed: optional random number seed for the chained PFA
:type doc: string or ``None``
:param doc: optional documentation string for the chained PFA
:type version: integer or ``None``
:param version: optional version number for the chained PFA
:type metadata: dict of strings
:param metadata: metadata for the chained PFA (default is ``{}``)
:type options: dict of Pythonized JSON
:param options: implementation options for the chained PFA (default is ``{}``)
:type tryYaml: bool
:param tryYaml: if ``True``, attempt to interpret ``pfas`` as YAML (assuming they fail as JSON)
:type verbose: bool
:param verbose: if ``True``, write status messages to standard output
:type sharedState: titus.genpy.SharedState
:param sharedState: external state for shared cells and pools to initialize from and modify; pass ``None`` to limit sharing to instances of a single PFA file
:type multiplicity: positive integer
:param multiplicity: number of instances to return (default is 1; a single-item collection)
:type style: string
:param style: style of scoring engine; only one currently supported: "pure" for pure-Python
:type debug: bool
:param debug: if ``True``, print the Python code generated by this PFA document before evaluating
:rtype: titus.genpy.EngineConfig
:return: a PFA document representing the chained workflow
"""
return PFAEngine.fromAst(ast(pfas, False, name, randseed, doc, version, metadata, options, tryYaml, verbose), options, sharedState, multiplicity, style, debug)
示例2: engine
# 需要导入模块: from titus.genpy import PFAEngine [as 别名]
# 或者: from titus.genpy.PFAEngine import fromAst [as 别名]
def engine(self):
if self._engine is None:
try:
self._engine, = PFAEngine.fromAst(self.engineConfig)
except (AvroException, SchemaParseException, PFAException) as err:
raise InspectorError(str(err))
return self._engine
示例3: ast
# 需要导入模块: from titus.genpy import PFAEngine [as 别名]
# 或者: from titus.genpy.PFAEngine import fromAst [as 别名]
#.........这里部分代码省略.........
action.append(Call("u." + thisActionFcnName, [Ref("input")]))
else:
action[-1] = Call("u." + thisActionFcnName, [action[-1]])
elif method == Method.EMIT:
# if the overall method is EMIT, then some individual engines might be MAP or might be EMIT
# the overall action calls the first engine-as-a-function and the engines-as-functions call each other (body is modified)
if pfa.method == Method.MAP and i + 1 < len(pfas):
body = [Call("u." + nextActionFcnName, [Do(body)]), LiteralNull()]
elif pfa.method == Method.MAP:
body = [Call("emit", [Do(body)])]
elif pfa.method == Method.EMIT:
body.append(LiteralNull())
fcns[thisActionFcnName] = FcnDef([{"input": newPlaceholder(i, pfa.input)}], newPlaceholder(i, AvroNull()), body)
if i == 0:
action.append(Call("u." + thisActionFcnName, [Ref("input")]))
# convert all of the user functions into user functions
for fcnName, fcnDef in pfa.fcns.items():
# note: some of these user-defined functions may call emit; if so, they'll call the right emit
fcns[prefixFcnDef(i, pfa, fcnName)] = FcnDef([{t.keys()[0]: newPlaceholder(i, t.values()[0])} for t in fcnDef.paramsPlaceholder],
newPlaceholder(i, fcnDef.ret),
[x.replace(fcnReplacer) for x in fcnDef.body],
fcnDef.pos)
if verbose: sys.stderr.write(time.asctime() + " Create types for model parameters\n")
for i, pfa in enumerate(pfas):
if verbose and len(pfa.cells) > 0: sys.stderr.write(time.asctime() + " step {0}:\n".format(i + 1))
for cellName, cell in pfa.cells.items():
if verbose: sys.stderr.write(time.asctime() + " cell {0}\n".format(cellName))
newCell = Cell(newPlaceholder(i, cell.avroType), cell.init, cell.shared, cell.rollback, cell.source, cell.pos)
cells[prefixCell(i, pfa, cellName)] = newCell
if cell.source == "embedded":
def converter(avroType):
original = jsonDecoder(cell.avroType, jsonlib.loads(cell.init))
return jsonlib.dumps(jsonEncoder(avroType, original))
newCell.converter = converter
for i, pfa in enumerate(pfas):
if verbose and len(pfa.pools) > 0: sys.stderr.write(time.asctime() + " step {0}:\n".format(i + 1))
for poolName, pool in pfa.pools.items():
if verbose: sys.stderr.write(time.asctime() + " pool {0}\n".format(poolName))
newPool = Pool(newPlaceholder(i, pool.avroType), pool.init, pool.shared, pool.rollback, pool.source, pool.pos)
pools[prefixPool(i, pfa, poolName)] = newPool
if pool.source == "embedded":
def converter(avroType):
original = jsonDecoder(pool.avroType, jsonlib.loads(pool.init))
return jsonlib.dumps(jsonEncoder(avroType, original))
newPool.converter = converter
# make sure all the types work together
if verbose: sys.stderr.write(time.asctime() + " Resolving all types\n")
avroTypeBuilder.resolveTypes()
if verbose: sys.stderr.write(time.asctime() + " Converting the model parameters themselves\n")
for i, pfa in enumerate(pfas):
if verbose and len(pfa.cells) > 0: sys.stderr.write(time.asctime() + " step {0}:\n".format(i + 1))
for cellName, cell in pfa.cells.items():
if verbose: sys.stderr.write(time.asctime() + " cell {0}\n".format(cellName))
if cell.source == "embedded":
newCell = cells[prefixCell(i, pfa, cellName)]
newCell.init = newCell.converter(newCell.avroType)
for i, pfa in enumerate(pfas):
if verbose and len(pfa.pools) > 0: sys.stderr.write(time.asctime() + " step {0}:\n".format(i + 1))
for poolName, pool in pfa.pools.items():
if verbose: sys.stderr.write(time.asctime() + " pool {0}\n".format(poolName))
if pool.source == "embedded":
newPool = pools[prefixPool(i, pfa, poolName)]
newPool.init = newPool.converter(newPool.avroType)
# randseed, doc, version, metadata, and options need to be explicitly set
# return a (possibly checked) AST
out = EngineConfig(name,
method,
inputPlaceholder,
outputPlaceholder,
begin,
action,
end,
fcns,
zero,
merge,
cells,
pools,
randseed,
doc,
version,
metadata,
options)
if check:
if verbose: sys.stderr.write(time.asctime() + " Verifying PFA validity\n")
PFAEngine.fromAst(out)
if verbose: sys.stderr.write(time.asctime() + " Done\n")
return out