Fix bugs in load_budget
Files
7To your broader comment @kevin.kuns, I think we should throw an error here if the ext is not in STRUCT_EXT.
I know, but without the line I added you get the error
line 158, in load_budget Budget = getattr(mod, bname) TypeError: getattr(): attribute name must be string
But with inheritance now, yaml files do specify which budget to use if there's a
+inherit
key. My point is that I don't like that loading a yaml file automatically loads it into the aLIGO budget if nothing is specified. Now that we can, I think it should be unambiguous what is being done.Not true, yet. If you look at the yaml files in the test/inherit directory, for example, Aplus_mod.yaml loads the ifo.yaml file associated with the Aplus budget into a struct, makes the changes specified, and then initializes the Aplus budget with the modified struct. Aplus_mod2.yaml just inherits the modifications specified by Aplus_mod.yaml. There will always be a budget at the end of the chain of inheritances.
The first bug that's fixed in this MR is that this chain of inheritances didn't work if the base budget was a custom budget not in
gwinc.IFOS
if the inheriting yaml file was in an arbitrary directory.The way things currently work is that if you call
load_budget
on a yaml file that does not have a+inherit
key, it initializes the aLIGO budget with the ifo struct specified by the yaml file. This kind of thing can lead to weird bugs and I would prefer that you have to specify which budget is being initialized. This is the functionality that is tested with the newtest_load_uninherited_yaml
in this MR, but my proposal is that this should raise an error instead.To be clear, I am not proposing any changes to
Struct.from_file
. Note also that trying to callStruct.from_file
on a yaml file with a+inherit
key will raise an error currently, though this is something we want to fix in the future.I don't see what the problem is with assuming the aLIGO budget if no budget is specified. It's currently possible to pass a yaml file on it's own to the CLI and have it do something sensible by assuming the aLIGO budget. I think we should retain that feature.
But I see now the problem you're highlighting, which is that the inheritance assumes you can specify a budget, not a yaml file, to inherit. I think that's the problem, and I think we should enforce that what you're inheriting is another yaml file.
I just don't like when things silently default to some option since I've been burned by this several times in the past. But regardless, this change is needed to get your desired behavior. Without it, in this use case,
bname
isNone
which is no good when callinggetattr(mod, bname)
a few lines down.