def register_core_by_stack(self, include_stacks: Set[str], *, exclude_stacks: Set[str] = None): """Register all instructions that make use of the given type name. Parameters ---------- include_stacks List of PushType names. exclude_stacks List of PushType names. Returns ------- InstructionSet A reference to the InstructionSet. """ for i in core_instructions(self.type_library): req_stacks = i.required_stacks() if req_stacks <= include_stacks: if exclude_stacks is None or len(req_stacks & exclude_stacks) == 0: self.register(i) return self
def register_core_by_stack( self, include_stacks: Set[str], *, exclude_stacks: Set[str] = None ): """Register all instructions that make use of the given type name. Parameters ---------- type_names List of PushType names. Returns ------- InstructionSet A reference to the InstructionSet. """ for i in core_instructions(self.type_library): req_stacks = i.required_stacks() if req_stacks <= include_stacks: if exclude_stacks is not None and len(req_stacks & exclude_stacks) > 0: break self.register(i) return self
def register_core(self): """Register all core instructions defined in pyshgp. Returns ------- InstructionSet A reference to the InstructionSet. """ self.register_list(core_instructions(self.type_library)) return self
def register_core(self): """Register all core instructions defined in pyshgp. Returns ------- InstructionSet A reference to the InstructionSet. """ self.register_list(core_instructions(self.type_library)) return self
def register_core_by_name(self, name_pattern: str): """Register all instructions whose name match the given pattern. Parameters ---------- name_pattern A regex string. Returns ------- InstructionSet A reference to the InstructionSet. """ re_pat = re.compile(name_pattern) for i in core_instructions(self.type_library): if re.match(re_pat, i.name) is not None: self.register(i) return self
def register_core_by_name(self, name_pattern: str): """Register all instructions whose name match the given pattern. Parameters ---------- name_pattern A regex string. Returns ------- InstructionSet A reference to the InstructionSet. """ re_pat = re.compile(name_pattern) for i in core_instructions(self.type_library): if re.match(re_pat, i.name) is not None: self.register(i) return self
import pyshgp from pyshgp.push.atoms import Instruction from pyshgp.push.instruction import ( SimpleInstruction, StateToStateInstruction, TakesStateInstruction, ProducesManyOfTypeInstruction, ) from pyshgp.push.instructions import core_instructions from pyshgp.push.type_library import PushTypeLibrary # @TODO: Create a way to prepare a release from pyshgp_cli.py CORE_INSTRUCTIONS = core_instructions(PushTypeLibrary()) DOC_DIR = "build/doc/" def _generate_instruction_rst(instr: Instruction) -> str: lines = [] lines.append(instr.name) lines.append("=" * len(instr.name)) signature_template = "*Takes: {i} - Produces: {o}*" if isinstance(instr, SimpleInstruction): signature_line = signature_line = signature_template.format( i="[" + ", ".join(instr.input_stacks) + "]", o="[" + ", ".join(instr.output_stacks) + "]" ) elif isinstance(instr, StateToStateInstruction):
import pyshgp from pyshgp.push.atoms import Instruction from pyshgp.push.instruction import ( SimpleInstruction, StateToStateInstruction, TakesStateInstruction, ProducesManyOfTypeInstruction, ) from pyshgp.push.instructions import core_instructions from pyshgp.push.type_library import PushTypeLibrary # @TODO: CLI - Create a way to prepare a release from pyshgp_cli.py CORE_INSTRUCTIONS = core_instructions(PushTypeLibrary()) DOC_DIR = "build/doc/" def _generate_instruction_rst(instr: Instruction) -> str: lines = [instr.name, "=" * len(instr.name)] signature_line = None signature_template = "*Takes: {i} - Produces: {o}*" if isinstance(instr, SimpleInstruction): signature_line = signature_line = signature_template.format( i="[" + ", ".join(instr.input_stacks) + "]", o="[" + ", ".join(instr.output_stacks) + "]") elif isinstance(instr, StateToStateInstruction): signature_line = signature_template.format(i="PushState", o="PushState")