Skip to content
Snippets Groups Projects

Fix bugs in load_budget

Merged Kevin Kuns requested to merge kevin.kuns/pygwinc:load_budget-bugfix into master
3 unresolved threads

Fixes two bugs in load_budget

  1. Inheritance now works when inheriting a custom budget that is not one of the canonical budgets if the yaml file inheriting it is not in the same directory as the custom budget.
  2. According to the help and readme, a yaml file which does not specify a budget to inherit should be loaded into the aLIGO budget. A bug in the logic was causing this to raise an error but is now working again. However, now that inheritance is working I propose that it no longer be possible to load a yaml file which doesn't specify which budget to use.

Merge request reports

Merge request pipeline #320975 passed

Merge request pipeline passed for 5c5c5a96

Approved by

Merged by Christopher WipfChristopher Wipf 2 years ago (Jul 8, 2022 10:12pm UTC)

Merge details

  • Changes merged into master with 4bd943ee.
  • Did not delete the source branch.

Pipeline #423155 passed

Pipeline passed for 4bd943ee on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
137 138 return inherit_budget
138 139 else:
139 140 modname = 'gwinc.ifo.aLIGO'
141 bname = bname or 'aLIGO'
142
  • Author Maintainer

    I propose that it no longer be possible to load a yaml file which doesn't specify which budget to use. This case should then raise an error instead.

  • The yaml files have never specified which model to use. It's always been the other way around: the budget specifies the yaml (or more precisely, the yaml is usually a part of the budget).

  • Author Maintainer

    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.

  • The inherit key specifies a different yaml file to load, not which budget it should be associated with.

  • Author Maintainer

    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 new test_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 call Struct.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.

  • Author Maintainer

    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 is None which is no good when calling getattr(mod, bname) a few lines down.

  • Please register or sign in to reply
  • Jameson Rollins
  • Jameson Rollins
  • 125 125 if inherit_ifo is not None:
    126 126 del ifo['+inherit']
    127 127 # make the inherited path relative to the loaded path
    128 # if it is a yml file
    129 if os.path.splitext(inherit_ifo)[1] in Struct.STRUCT_EXT:
    130 base = os.path.split(path)[0]
    131 inherit_ifo = os.path.join(base, inherit_ifo)
    128 # if it is a yml file or a directory
    129 head = os.path.split(path)[0]
    130 rel_path = os.path.join(head, inherit_ifo)
    131 if os.path.splitext(inherit_ifo)[1] in Struct.STRUCT_EXT or os.path.exists(rel_path):
  • 125 125 if inherit_ifo is not None:
    126 126 del ifo['+inherit']
    127 127 # make the inherited path relative to the loaded path
    128 # if it is a yml file
    129 if os.path.splitext(inherit_ifo)[1] in Struct.STRUCT_EXT:
    130 base = os.path.split(path)[0]
    131 inherit_ifo = os.path.join(base, inherit_ifo)
    128 # if it is a yml file or a directory
    129 head = os.path.split(path)[0]
    130 rel_path = os.path.join(head, inherit_ifo)
    131 if os.path.splitext(inherit_ifo)[1] in Struct.STRUCT_EXT or os.path.exists(rel_path):
    132 inherit_ifo = rel_path
    132 133
    133 134 inherit_budget = load_budget(inherit_ifo, freq=freq, bname=bname)
    • In fact, I think we should not be using load_budget for handling the inheritance, and in fact not be handling any of this here at all but should instead be handling it in the struct load class methods.

    • Author Maintainer

      Well that is a discussion that we should have, but this MR is fixing a bug in how it is currently supposed to work.

    • Please register or sign in to reply
  • Kevin Kuns added 1 commit

    added 1 commit

    • 5c5c5a96 - check that file types are supported by Struct in load_budget

    Compare with previous version

  • Author Maintainer

    @christopher.wipf This is an actual bug. You can ignore my suggestion about loading into the aLIGO budget. But the MR as is only fixes the bugs.

  • I agree with Jamie's point that the design of the inheritance feature could benefit from more thought. I also agree with Kevin that inheritance design discussion is separable from this MR. Are there are objections to how this MR fixes the problems it sets out to fix? If not, let's plan to merge it later this week.

  • Christopher Wipf approved this merge request

    approved this merge request

  • mentioned in commit 4bd943ee

  • Please register or sign in to reply
    Loading