-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AssertionError: Cannot compute a linearization with respect to 0 arguments #318
Comments
Mostly it would be useful to know the factors you're using, and the stack trace - it would be good to update that error message to be a ValueError instead of an assert, and include 1) the name of the factor, if present, and 2) probably |
My residual function takes in pose and 2 nodes as arguments (I am not sure how to use epsilon here) This is how I am building my factors:
And this is how I am adding the keys:
Stacktrace:
|
Hey Vineet. It looks like the reason you're getting an error is because none of the keys in your factors actually match the keys you constructed your If there is actually an def build_factors(num_nodes: int) -> T.Iterator[Factor]:
for i in range(num_nodes):
yield Factor(
residual=residual,
keys=[f"poses[{i}]",
f"nodes[{edges[i][0]}]", # <-- this line is different
f"nodes[{edges[i][1]}]", # <-- this line is different
# "epsilon"
],
) so that, if More generally, in order for, say, the 2nd argument of a residual to be optimized, the second key in the factor you construct from it (so Conceptually, if none of the keys match, then the factor wouldn't actually do anything. Incidentally, what happens is an |
Regarding Aaron's comment, I agree that the current error message is inadequate. I'd like to modify for factor in factors:
if isinstance(factor, Factor):
if optimized_keys is None:
raise ValueError(
"You must specify keys to optimize when passing symbolic factors."
)
# We compute the linearization in the same order as `optimized_keys`
# so that e.g. columns of the generated jacobians are in the same order
factor_opt_keys = [opt_key for opt_key in optimized_keys if opt_key in factor.keys]
# PROPOSED ADDITION vvv
if len(factor_opt_keys) == 0:
raise ValueError(
f"Factor {factor.name} has no arguments (keys: {factor.keys}) in "
+ f"optimized_keys ({optimized_keys})."
)
# END PROPOSED ADDITION ^^^
numeric_factors.append(factor.to_numeric_factor(factor_opt_keys)) |
Okay got it thanks - basically my error was a key mismatch error. |
I had a basic question - |
Sorry for the delay (didn't notice your last message). But it's the latter, your optimization keys would need to be |
I am trying to run the sf.optimizer:
here is how I create my optimizer:
But the above line throws the following assertion error:
AssertionError: Cannot compute a linearization with respect to 0 arguments
This is how create
_optimized_keys,
_optimized_keys = [f"nodes[{i}]" for i in range(_num_nodes)]
All my sub functions do have arguments. So I do not understand where exactly am I going wrong.
Please let me know if you need any more logs or sys info.
Thanks in advance!
The text was updated successfully, but these errors were encountered: