add ability to specify custom instruction generator function#183
add ability to specify custom instruction generator function#183
Conversation
robfitzgerald
left a comment
There was a problem hiding this comment.
thanks nick, this is the idea. i think making these APIs callables vs requiring them to derive a base class is a little more pythonic for people who want to easily add new control logic in hive.
i think there's a complication that may require a little more thought around identifying the unique AnonGenerators, along with another small request to finish the test.
| rp = load_simulation(conf, custom_instruction_generators=[custom_instruction_function]) | ||
|
|
||
| result = crank(rp, 1) | ||
|
|
There was a problem hiding this comment.
this test should include an assertion, like, perhaps the custom function creates a fixed set of instructions that can be confirmed at the end
There was a problem hiding this comment.
yeah that's a good call, I updated the test to make sure the instructions are getting applied and using two different functions to make sure the name property is working
| self.instruction_function = instruction_function | ||
|
|
||
| @property | ||
| def name(self) -> str: |
There was a problem hiding this comment.
i think you set up instruction generators to be stored in a Map[str, InstructionGenerator] where the key comes from this name. if that's the case, this design fails if there are more than one anonymous InstructionGenerators added to the system.
two ideas:
- while looping through
instruction_generator_from_functionbelow, enumerate the iterable and append the index number when creating the name in the init of AnonGenerator - make users responsible for providing a name, which is probably the right move, though it means they have to pass along a Tuple[str, Callable[etc]] instead of just the callable
There was a problem hiding this comment.
aha yes, good catch; how about if we use the incoming function name?
There was a problem hiding this comment.
that's going to be something generated by the interpreter like "lambda$a2354h8-aggahds" or something like that, right? is that helpful for the user? again, if there is a runtime error in their code, it might not be clear which of multiple IGs is the one that's responsible.
There was a problem hiding this comment.
it's a good start though. maybe i should back off and let that through and we worry about fixing it if people have issues later.
There was a problem hiding this comment.
it's a good start though. maybe i should back off and let that through and we worry about fixing it if people have issues later. what do you think?
There was a problem hiding this comment.
that looks good enough to me, as it should likely correspond to something the user can make sense of. thanks for confirming!

Closes #129 by adding the ability to specify custom control logic as either a
InstructionGeneratoror anInstructionFunctionwhich is any callable that has the signatureCallable[[SimulationState, Environment], Tuple[Instruction, ...]]@robfitzgerald I'm interested to hear if this satisfies what you had in mind with #129