You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are good reasons for the removal of secondary parameters in this iteration of Ops
Lambda Ops cannot support secondary parameters
The current state of OpService.run() cannot currently support secondary parameters and would be slowed down if we were to provide support through that method
Removing secondary parameters will result in fewer lines of code
For these reasons it would be best to push towards the exclusive use of primary parameters. However this has one main drawback in that secondary parameters are associated with optional parameters: in the previous iteration of Ops primary parameters were never optional and should never be optional. The current strategy in solving this has been to:
Port the Op and make the optional parameter required.
Make a second lambda Op that just calls the main Op with a reasonable default for the optional parameter.
In many cases however this severely bloats the code base. In many cases, especially when the Ops are lambdas, this is not a big deal, however it can be problematic when there are multiple optional parameters and/or the Ops must be classes. For this reason it would be nice to allow primary optional parameters in such situations.
As of now the @Parameter annotation can be designated as required = false, however it is currently really only a placeholder. A current strategy is to designate optional parameters as required = false under the contract that the user will pass null for that parameter if they want the reasonable default. Then in the body of the op the developer would check that param:
if(param == null) param = reasonable_default;
This, however, feels lacking. It would be nice if the Op matcher was intelligent enough to be able to read those required = false annotations and be able to match a smaller-order function when the user so desires (i.e. if the user wants to match a Function3 with one optional parameter they can do so by asking the matcher for a BiFunction with the same name and same typing as the required params of that function). This could possibly be done with an OpTransformer.
@Treiblesschorle If you have time: do you have thoughts on the matching of optional parameters with the SciJava Ops matcher? Do you remember if you attempted it? Just punted on it completely? Do you think the OpTransformer mechanism is flexible enough to support matching smaller-order functions? Or would this feature need to be baked into the matcher's core? Or is there already, and we are somehow missing it?
@ctrueden I just found this which suggests that optional secondary parameters are supported. I don't have the time left today to dig into this but will attempt to do so on Friday to figure out where this happens / if we can use this as a base for the work that we want to do (maybe @Treiblesschorle will have the time to provide more info in the meantime).
Unfortunately, the example mentioned by @gselzer is about not having to specify secondary args that are not required when calling ops().findOp(). These will be set null and the op needs to check for that. However, the types still have to be specified for matching (all primary and secondary ones). At the moment you can't ask for a smaller-order function if one of the params is optional.
I think it could be done with an OpTransformer if we add these smaller-oder functions as meta ops to the system.
Maybe we should have a discussion about that in general.
We realized that OpTransformers are not a good fit to implement this feature. That's because such transformers would need to know about the optional parameters of their source Ops. This information can only be provided by the OpInfos of actual existing Ops, not by already transformed Ops. This conflicts with the idea of OpTransformers being able to transform any suitable Op only given the source Op object itself and the target OpRef.
instead, we could extend the Op discovery mechanism a bit, such that Ops that have optional parameters are added multiple times to the index: once in their "full form", and once per omitted set of optional parameters (right-to-left elimination only), as smaller-order functions. They will then get matched as any other "regular" Op.
@ctrueden proposed the following tentative scheme:
When an op declares a parameter as optional, register another OpInfo with that parameter missing (dropping them from right to left in the case of multiple optional parameters)
Which we then realized is what @MarcelWiedenmann said 😁
Just add additional OpInfo objects at discovery, which delegate to the original with null padding, from right to left.
How do we want to determine what functional type the Op without the optional parameter will be? Is there a way to avoid hardcoding the types and preserve extensibility?
(possibly more, depending on the complexity of the solution to this)
How do we want to determine what functional type the Op without the optional parameter will be? Is there a way to avoid hardcoding the types and preserve extensibility?
Activity
ctrueden commentedon May 15, 2019
@Treiblesschorle If you have time: do you have thoughts on the matching of optional parameters with the SciJava Ops matcher? Do you remember if you attempted it? Just punted on it completely? Do you think the
OpTransformermechanism is flexible enough to support matching smaller-order functions? Or would this feature need to be baked into the matcher's core? Or is there already, and we are somehow missing it?gselzer commentedon May 15, 2019
@ctrueden I just found this which suggests that optional secondary parameters are supported. I don't have the time left today to dig into this but will attempt to do so on Friday to figure out where this happens / if we can use this as a base for the work that we want to do (maybe @Treiblesschorle will have the time to provide more info in the meantime).
Treiblesschorle commentedon May 16, 2019
Unfortunately, the example mentioned by @gselzer is about not having to specify secondary args that are not required when calling
ops().findOp(). These will be setnulland theopneeds to check for that. However, the types still have to be specified for matching (all primary and secondary ones). At the moment you can't ask for a smaller-order function if one of the params is optional.I think it could be done with an
OpTransformerif we add these smaller-oder functions as meta ops to the system.Maybe we should have a discussion about that in general.
wiedenm commentedon Jun 28, 2019
We realized that
OpTransformersare not a good fit to implement this feature. That's because such transformers would need to know about the optional parameters of their source Ops. This information can only be provided by theOpInfos of actual existing Ops, not by already transformed Ops. This conflicts with the idea ofOpTransformers being able to transform any suitable Op only given the source Op object itself and the targetOpRef.instead, we could extend the Op discovery mechanism a bit, such that Ops that have optional parameters are added multiple times to the index: once in their "full form", and once per omitted set of optional parameters (right-to-left elimination only), as smaller-order functions. They will then get matched as any other "regular" Op.
gselzer commentedon Aug 20, 2019
@ctrueden proposed the following tentative scheme:
Which we then realized is what @MarcelWiedenmann said 😁
wiedenm commentedon Aug 26, 2019
I like that we agree on this 😄.
ctrueden commentedon Jul 7, 2020
How we can support succinct declaration of optional primary parameters
How we can support matching them
Just add additional
OpInfoobjects at discovery, which delegate to the original with null padding, from right to left.Should we support adapting or any fanciness?
No. The op implementor is responsible for handling
nullinput for each@Optionalparameter they have declared.gselzer commentedon Jul 20, 2020
How do we want to determine what functional type the Op without the optional parameter will be? Is there a way to avoid hardcoding the types and preserve extensibility?
gselzer commentedon May 13, 2021
Time commitment: 1 week
(possibly more, depending on the complexity of the solution to this)
Enable optional parameters using reduction
Enable optional parameters using reduction
Enable optional parameters using reduction
Merge pull request #14 from scijava/scijava/scijava-ops-demo/init