Skip to content

Improved response argument support #30

@aatmdelissen

Description

@aatmdelissen

Basically there are two issues remaining with response arguments:

  1. Modules don't support keyword arguments in the response(), but only positional arguments. This is due to the inconvenience of constructing a dictionary when returning the sensitivities. If a dict would be returned, this should be possible.

  2. It is a bit cumbersome to obtain the values passed to the response function, especially for optional arguments not passed by the user. No signal exists for these inputs and when using get_input_states, only the inputs defined by sig_in are returned. Workaround for now:

class MyModule(pym.Module):
    default_b: float = 1.0
    default_c: float = 1/np.sqrt(2)

    def __call__(self, a, b=None, c=None):
        if b is None:
            b = self.default_b
        if cis None:
            c = self.default_c
       ...

    def _sensitivity(self, dy):
        b, c = self.default_b, self.default_c
        if self.n_in == 1:
            a= self.get_input_states()
        elif self.n_in == 2:
            a, b = self.get_input_states()
        elif self.n_in == 3:
            a, b, c = self.get_input_states()
        else:
            raise ValueError("Wrong number of inputs")
        ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions