Skip to content
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

[WIP] Abstract Variables/Symbols #1308

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

alanlujan91
Copy link
Member

Please ensure your pull request adheres to the following guidelines:

  • Tests for new functionality/models or Tests to reproduce the bug-fix in code.
  • Updated documentation of features that add new functionality.
  • Update CHANGELOG.md with major/minor changes.

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.40% ⚠️

Comparison is base (37134b9) 72.55% compared to head (f41c944) 72.16%.
Report is 30 commits behind head on master.

❗ Current head f41c944 differs from pull request most recent head e4d2850. Consider uploading reports for the commit e4d2850 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1308      +/-   ##
==========================================
- Coverage   72.55%   72.16%   -0.40%     
==========================================
  Files          78       79       +1     
  Lines       13009    13080      +71     
==========================================
  Hits         9439     9439              
- Misses       3570     3641      +71     
Files Changed Coverage Δ
HARK/variables.py 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alanlujan91
Copy link
Member Author

Having trouble setting tests up but this works locally.

@alanlujan91
Copy link
Member Author

@ingydotnet here I am starting the work of building the abstract objects

@sbenthall
Copy link
Contributor

Test failures may be due to Python versions (3.8, 3.9, etc.). A lot of these more advanced language features are relatively recent.

name: m
short_name: money
long_name: market resources
latex_repr: \mNrm
Copy link
Contributor

Choose a reason for hiding this comment

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

I know how you're imagining using the Latex representation.
But my preference would be to not include it in the PR unless you have some demonstration of how it works ready.
4 different ways to name something for a quick demo seems like a lot....

Copy link
Member Author

Choose a reason for hiding this comment

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

For now these are filler, I want to throw any non-required keys into an attributes dictionary.

- !Action
name: c
short_name: consumption
long_name: consumption
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these fields optional? Can one spill over to the others as a default?
Basically, how can we make these config files lighter weight?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are optional, only required is name.

long_name: market resources
latex_repr: \mNrm
- !State
name: &name stigma
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what the ampersands are doing here.
Maybe document that?

Copy link
Member Author

Choose a reason for hiding this comment

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

ampersands are aliases, since one of the states is also a control and a post-state. I will document this more as I make more progress.

post_states: !PostStateSpace
variables:
- !PostState
name: a
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you've repeated the post_states block twice in this file?

Not sure how @mnwhite feels, but maybe we don't need to draw a firm distinction between states and post states like this.

Or the labels could be inside the variable, not part of the document structure.

Compare:

var_type_1:
   variables:
       - !VarTypeClass1
           details

var_type_2:
   variables:
       - !VarTypeClass2
           details

with

variables:
    - !VarTypeClass1
       details
    - !VarTypeClass2   
       details

The latter is same information, but fewer lines.

self.shocks = self.variables


def make_state_array(
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 method duplicated?

import yaml

import HARK.abstract.variables

Copy link
Contributor

Choose a reason for hiding this comment

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

A test case showing how this data structure could be used in practice would go a long way.

@sbenthall
Copy link
Contributor

I think this is a cool demonstration of how PyYAML can be leveraged to make model configuration files in YAML without a custom parser.

The tricky part, as we know, is function definitions.

@alanlujan91
Copy link
Member Author

Test failures may be due to Python versions (3.8, 3.9, etc.). A lot of these more advanced language features are relatively recent.

yep, this might have to be a feature for the future, just getting some initial work done on it

@alanlujan91
Copy link
Member Author

I think this is a cool demonstration of how PyYAML can be leveraged to make model configuration files in YAML without a custom parser.

The tricky part, as we know, is function definitions.

Yes! I was just talking to one of the creators of YAML who was telling me about this https://github.com/yaml/yamlscript

@sbenthall
Copy link
Contributor

Mind blown emoji.

One more thing: I'd be keen to see how you would initialize a distribution for a shock directly from YAML.



@dataclass
class Auxiliary(Variable):
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Chris that 'auxiliary' is more like a macro.
I wouldn't use 'auxiliary' here, though it makes sense to have this sort of object.



@dataclass
class Variable(YAMLObject):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to initialize Variables without parsing them from a YAML file?
I.e., a pure python way to create variables?

I'm a little wary of tying the model objects too tightly to the serial format because it can make it tricky to interoperate with other python libraries.

@alanlujan91
Copy link
Member Author

@MridulS thank you for fixing the checks!

Might you be able to help me with the failing test? I'm not sure why !Parameters is not being recognized.

HARK/abstract/variables.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants