def compute(self): name_output = self.get_input('OutputPort') # or 'self' name_input = self.force_get_input('InputPort') # or None lower_bound = self.get_input('LowerBound') # or 0 higher_bound = self.get_input('HigherBound') # required connectors = self.inputPorts.get('FunctionPort') if len(connectors) != 1: raise ModuleError(self, "Multiple modules connected on FunctionPort") outputs = [] suspended = [] loop = self.logging.begin_loop_execution(self, higher_bound - lower_bound) for i in xrange(lower_bound, higher_bound): module = copy.copy(connectors[0].obj) if not self.upToDate: module.upToDate = False module.computed = False # Pass iteration number on input port if name_input is not None: if name_input in module.inputPorts: del module.inputPorts[name_input] new_connector = ModuleConnector(create_constant(i), 'value') module.set_input_port(name_input, new_connector) # Affix a fake signature on the module inputPort_hash = sha1_hash() inputPort_hash.update(name_input) module.signature = b16encode(xor( b16decode(self.signature.upper()), long2bytes(i, 20), inputPort_hash.digest())) loop.begin_iteration(module, i) try: module.update() except ModuleSuspended, e: suspended.append(e) loop.end_iteration(module) continue loop.end_iteration(module) if name_output not in module.outputPorts: raise ModuleError(module, "Invalid output port: %s" % name_output) outputs.append(module.get_output(name_output))
def compute(self): name_output = self.get_input('OutputPort') # or 'self' name_input = self.force_get_input('InputPort') # or None lower_bound = self.get_input('LowerBound') # or 0 higher_bound = self.get_input('HigherBound') # required connectors = self.inputPorts.get('FunctionPort') if len(connectors) != 1: raise ModuleError(self, "Multiple modules connected on FunctionPort") outputs = [] suspended = [] loop = self.logging.begin_loop_execution(self, higher_bound - lower_bound) for i in xrange(lower_bound, higher_bound): module = copy.copy(connectors[0].obj) if not self.upToDate: module.upToDate = False module.computed = False # Pass iteration number on input port if name_input is not None: if name_input in module.inputPorts: del module.inputPorts[name_input] new_connector = ModuleConnector(create_constant(i), 'value') module.set_input_port(name_input, new_connector) # Affix a fake signature on the module inputPort_hash = sha1_hash() inputPort_hash.update(name_input) module.signature = b16encode( xor(b16decode(self.signature.upper()), long2bytes(i, 20), inputPort_hash.digest())) loop.begin_iteration(module, i) try: module.update() except ModuleSuspended, e: suspended.append(e) loop.end_iteration(module) continue loop.end_iteration(module) if name_output not in module.outputPorts: raise ModuleError(module, "Invalid output port: %s" % name_output) outputs.append(module.get_output(name_output))
def compute(self): # Check required attributes if not hasattr(self, 'pipeline') or self.pipeline is None: raise VistrailsInternalError( "%s cannot execute -- pipeline doesn't exist" % self.__class__.__name__) elif (not hasattr(self, 'output_remap') or self.output_remap is None or not hasattr(self, 'input_remap') or self.input_remap is None): raise VistrailsInternalError( "%s cannot execute -- remap dictionaries don't exist" % self.__class__.__name__) # Setup pipeline for execution res = self.interpreter.setup_pipeline(self.pipeline) self.persistent_modules = res[0].values() if len(res[5]) > 0: raise ModuleError(self, "Error(s) inside group:\n" + "\n".join(me.msg for me in res[5].itervalues())) tmp_id_to_module_map = res[0] # Connect Group's external input ports to internal InputPort modules for iport_name, conn in self.inputPorts.iteritems(): from vistrails.core.modules.basic_modules import create_constant # The type information is lost when passing as Variant, # so we need to use the the final normalized value value = self.get_input(iport_name) temp_conn = ModuleConnector(create_constant(value), 'value', self.input_specs[iport_name]) iport_module = self.input_remap[iport_name] iport_obj = tmp_id_to_module_map[iport_module.id] iport_obj.set_input_port('ExternalPipe', temp_conn) # Execute pipeline kwargs = {'logger': self.logging.log.recursing(self), 'clean_pipeline': True, 'current_version': self.moduleInfo['version']} module_info_args = set(['locator', 'reason', 'extra_info', 'actions', 'job_monitor']) for arg in module_info_args: if arg in self.moduleInfo: kwargs[arg] = self.moduleInfo[arg] res = self.interpreter.execute_pipeline(self.pipeline, *res[:2], **kwargs) # Check and propagate errors if len(res[2]) > 0: raise ModuleError(self, "Error(s) inside group:\n" + "\n".join("%s: %s" % ( me.module.__class__.__name__, me.msg) for me in res[2].itervalues())) # Check and propagate ModuleSuspended exceptions if res[4]: message = "\n".join([ms.msg for ms in res[4].itervalues()]) children = list(res[4].values()) raise ModuleSuspended(self, message, children=children) # Connect internal OutputPort modules to Group's external output ports for oport_name, oport_module in self.output_remap.iteritems(): if oport_name is not 'self': oport_obj = tmp_id_to_module_map[oport_module.id] self.set_output(oport_name, oport_obj.get_output('ExternalPipe')) self.interpreter.finalize_pipeline(self.pipeline, *res[:-1], reset_computed=False)
def compute(self): name_output = self.get_input('OutputPort') name_condition = self.force_get_input('ConditionPort') name_state_input = self.force_get_input('StateInputPorts') name_state_output = self.force_get_input('StateOutputPorts') max_iterations = self.get_input('MaxIterations') delay = self.force_get_input('Delay') if (name_condition is None and not self.has_input('MaxIterations')): raise ModuleError(self, "Please set MaxIterations or use ConditionPort") if name_state_input or name_state_output: if not name_state_input or not name_state_output: raise ModuleError(self, "Passing state between iterations requires " "BOTH StateInputPorts and StateOutputPorts " "to be set") if len(name_state_input) != len(name_state_output): raise ModuleError(self, "StateInputPorts and StateOutputPorts need " "to have the same number of ports " "(got %d and %d)" % (len(name_state_input), len(name_state_output))) connectors = self.inputPorts.get('FunctionPort') if len(connectors) != 1: raise ModuleError(self, "Multiple modules connected on FunctionPort") module = copy.copy(connectors[0].obj) state = None loop = self.logging.begin_loop_execution(self, max_iterations) for i in xrange(max_iterations): if not self.upToDate: module.upToDate = False module.computed = False # Set state on input ports if i > 0 and name_state_input: for value, input_port, output_port \ in izip(state, name_state_input, name_state_output): if input_port in module.inputPorts: del module.inputPorts[input_port] new_connector = ModuleConnector( create_constant(value), 'value', module.output_specs.get(output_port, None)) module.set_input_port(input_port, new_connector) # Affix a fake signature on the module inputPort_hash = sha1_hash() inputPort_hash.update(input_port) module.signature = b16encode(xor( b16decode(self.signature.upper()), inputPort_hash.digest())) loop.begin_iteration(module, i) module.update() # might raise ModuleError, ModuleSuspended, # ModuleHadError, ModuleWasSuspended loop.end_iteration(module) if name_condition is not None: if name_condition not in module.outputPorts: raise ModuleError( module, "Invalid output port: %s" % name_condition) if not module.get_output(name_condition): break if delay and i+1 != max_iterations: time.sleep(delay) # Get state on output ports if name_state_output: state = [module.get_output(port) for port in name_state_output] self.logging.update_progress(self, i * 1.0 / max_iterations) loop.end_loop_execution() if name_output not in module.outputPorts: raise ModuleError(module, "Invalid output port: %s" % name_output) result = module.get_output(name_output) self.set_output('Result', result)
def compute(self): # Check required attributes if not hasattr(self, 'pipeline') or self.pipeline is None: raise VistrailsInternalError( "%s cannot execute -- pipeline doesn't exist" % self.__class__.__name__) elif (not hasattr(self, 'output_remap') or self.output_remap is None or not hasattr(self, 'input_remap') or self.input_remap is None): raise VistrailsInternalError( "%s cannot execute -- remap dictionaries don't exist" % self.__class__.__name__) # Setup pipeline for execution res = self.interpreter.setup_pipeline(self.pipeline) self.persistent_modules = res[0].values() if len(res[5]) > 0: raise ModuleError( self, "Error(s) inside group:\n" + "\n".join(me.msg for me in res[5].itervalues())) tmp_id_to_module_map = res[0] # Connect Group's external input ports to internal InputPort modules for iport_name, conn in self.inputPorts.iteritems(): from vistrails.core.modules.basic_modules import create_constant # The type information is lost when passing as Variant, # so we need to use the the final normalized value value = self.get_input(iport_name) temp_conn = ModuleConnector(create_constant(value), 'value', conn[0].spec) iport_module = self.input_remap[iport_name] iport_obj = tmp_id_to_module_map[iport_module.id] iport_obj.set_input_port('ExternalPipe', temp_conn) # Execute pipeline kwargs = { 'logger': self.logging.log.recursing(self), 'clean_pipeline': True, 'current_version': self.moduleInfo['version'] } module_info_args = set( ['locator', 'reason', 'extra_info', 'actions', 'job_monitor']) for arg in module_info_args: if arg in self.moduleInfo: kwargs[arg] = self.moduleInfo[arg] res = self.interpreter.execute_pipeline(self.pipeline, *res[:2], **kwargs) # Check and propagate errors if len(res[2]) > 0: raise ModuleError( self, "Error(s) inside group:\n" + "\n".join("%s: %s" % (me.module.__class__.__name__, me.msg) for me in res[2].itervalues())) # Check and propagate ModuleSuspended exceptions if res[4]: message = "\n".join([ms.msg for ms in res[4].itervalues()]) children = list(res[4].values()) raise ModuleSuspended(self, message, children=children) # Connect internal OutputPort modules to Group's external output ports for oport_name, oport_module in self.output_remap.iteritems(): if oport_name is not 'self': oport_obj = tmp_id_to_module_map[oport_module.id] self.set_output(oport_name, oport_obj.get_output('ExternalPipe')) self.interpreter.finalize_pipeline(self.pipeline, *res[:-1], reset_computed=False)
def compute(self): name_output = self.get_input('OutputPort') name_condition = self.force_get_input('ConditionPort') name_state_input = self.force_get_input('StateInputPorts') name_state_output = self.force_get_input('StateOutputPorts') max_iterations = self.get_input('MaxIterations') delay = self.force_get_input('Delay') if (name_condition is None and not self.has_input('MaxIterations')): raise ModuleError(self, "Please set MaxIterations or use ConditionPort") if name_state_input or name_state_output: if not name_state_input or not name_state_output: raise ModuleError( self, "Passing state between iterations requires " "BOTH StateInputPorts and StateOutputPorts " "to be set") if len(name_state_input) != len(name_state_output): raise ModuleError( self, "StateInputPorts and StateOutputPorts need " "to have the same number of ports " "(got %d and %d)" % (len(name_state_input), len(name_state_output))) connectors = self.inputPorts.get('FunctionPort') if len(connectors) != 1: raise ModuleError(self, "Multiple modules connected on FunctionPort") module = copy.copy(connectors[0].obj) state = None loop = self.logging.begin_loop_execution(self, max_iterations) for i in xrange(max_iterations): if not self.upToDate: module.upToDate = False module.computed = False # Set state on input ports if i > 0 and name_state_input: for value, input_port, output_port \ in izip(state, name_state_input, name_state_output): if input_port in module.inputPorts: del module.inputPorts[input_port] new_connector = ModuleConnector( create_constant(value), 'value', module.output_specs.get(output_port, None)) module.set_input_port(input_port, new_connector) # Affix a fake signature on the module inputPort_hash = sha1_hash() inputPort_hash.update(input_port) module.signature = b16encode( xor(b16decode(self.signature.upper()), inputPort_hash.digest())) loop.begin_iteration(module, i) module.update() # might raise ModuleError, ModuleSuspended, # ModuleHadError, ModuleWasSuspended loop.end_iteration(module) if name_condition is not None: if name_condition not in module.outputPorts: raise ModuleError( module, "Invalid output port: %s" % name_condition) if not module.get_output(name_condition): break if delay and i + 1 != max_iterations: time.sleep(delay) # Get state on output ports if name_state_output: state = [module.get_output(port) for port in name_state_output] self.logging.update_progress(self, i * 1.0 / max_iterations) loop.end_loop_execution() if name_output not in module.outputPorts: raise ModuleError(module, "Invalid output port: %s" % name_output) result = module.get_output(name_output) self.set_output('Result', result)