Skip to content

New method to add parameters#1965

Merged
abhisrkckl merged 11 commits intonanograv:masterfrom
dlakaplan:addparams
Mar 6, 2026
Merged

New method to add parameters#1965
abhisrkckl merged 11 commits intonanograv:masterfrom
dlakaplan:addparams

Conversation

@dlakaplan
Copy link
Contributor

Normally adding new parameters is a pain. new Parameter instances have to be created with the correct class and arguments, new components may be needed, etc.

When reading a model from a file, though, you can use overrides like:

m=get_model(filename, F2=1)

This implements a similar ability for adding to an existing model. e.g.,

m=get_model(filename)
...
m.add_params(F2=1, JUMP="FREQ  1400.0 2000.0 0.1 0")

will add F2 and JUMP1, even if no JUMP component exists. Note that this will not override existing values since there are already plenty of ways to do that (and will raise an exception in those cases).

Copy link
Contributor

@abhisrkckl abhisrkckl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what happens in the following scenarios?

  1. A binary parameter is added this way, but there is no binary component in the TimingModel?
  2. A binary parameter is added this way, but it is not supported by the binary component in the TimingModel (e.g., EPS1 into DD)?
  3. F3 is added, but there is no F2 in the model?
  4. "EFAC -f abc " is added, but the same EFAC is already present.
  5. Can non-numerical parameters (e.g. EPHEM, CLOCK etc) be added like this?

Copy link
Contributor

@abhisrkckl abhisrkckl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test with FDJUMPDM. It is a weird parameter implementation-wise and may lead to pathological cases.

Copy link
Contributor

@abhisrkckl abhisrkckl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also call TimingModel.validate_toas() after adding the parameters.

@dlakaplan
Copy link
Contributor Author

Can you clarify what happens in the following scenarios?

  1. A binary parameter is added this way, but there is no binary component in the TimingModel?

This fails. I think that makes sense, but let me know if not. I can also make that explicit in the docs.

  1. A binary parameter is added this way, but it is not supported by the binary component in the TimingModel (e.g., EPS1 into DD)?

That fails. I think that is sensible.

  1. F3 is added, but there is no F2 in the model?
    This fails because of standard PINT checking (need to add prefix parameters sequentially). This is tested in tests/test_modeloverride.py::test_paradd_fails[F3--2e-14]
  1. "EFAC -f abc " is added, but the same EFAC is already present.
    It is only added once. Not sure what the expected behavior should be here.
  1. Can non-numerical parameters (e.g. EPHEM, CLOCK etc) be added like this?

Yes, although not those examples since they are already present. But for the examples like EFAC and JUMP this works OK.

@dlakaplan
Copy link
Contributor Author

Please add a test with FDJUMPDM. It is a weird parameter implementation-wise and may lead to pathological cases.

Added

@dlakaplan
Copy link
Contributor Author

Also call TimingModel.validate_toas() after adding the parameters.

How would that work? Doesn't that need TOAs to be defined? This can be done with just a model.

@abhisrkckl
Copy link
Contributor

I think this is ready to go. Shall I merge this?

@dlakaplan
Copy link
Contributor Author

I think it's fine, unless you think it would help to explain some of those other scenarios in the docs

@dlakaplan dlakaplan added enhancement awaiting review This PR needs someone to review it so it can be merged minor A minor PR that doesn't need a lot of thought labels Mar 2, 2026
Copy link
Contributor

@abhisrkckl abhisrkckl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to check if adding a binary parameter without a binary component fails as expected.

from functools import wraps
from typing import Callable, Dict, List, Literal, Optional, Set, Tuple, Union
from warnings import warn
from xml.dom.minidom import Attr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, that was some stupid autocomplete insertion. removed.

@abhisrkckl
Copy link
Contributor

I think it's fine, unless you think it would help to explain some of those other scenarios in the docs

I think it will be helpful to explain what scenarios are invalid in the dosctrings.

@dlakaplan
Copy link
Contributor Author

Please add a test to check if adding a binary parameter without a binary component fails as expected.

Added.

@abhisrkckl
Copy link
Contributor

I will merge this if it is ready.

@dlakaplan
Copy link
Contributor Author

I will merge this if it is ready.

Had to push new updates.

@abhisrkckl
Copy link
Contributor

Ok I will merge once the tests pass.

@dlakaplan
Copy link
Contributor Author

Can you merge?

@abhisrkckl abhisrkckl merged commit 6d7ed08 into nanograv:master Mar 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review This PR needs someone to review it so it can be merged enhancement minor A minor PR that doesn't need a lot of thought

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants