From 72936ca34d191151a844dafb9945c12c2972e472 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 12 Aug 2024 17:11:47 +0200 Subject: [PATCH 01/22] add a linter workflow for changed files in a PR --- .github/workflows/lint.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..80e6b39 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Linting + +on: + pull_request: # only run on pull requests for now + branches: [ "master", "development" ] + +jobs: + lint: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./dgl_ptm + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install .[dev] + - name: Get changed files # for now, we only lint the changed files + id: files + run: | + echo "::set-output name=files::$(git diff --name-only origin/${{ github.base_ref }}...HEAD)" + - name: Check code style against standards + run: ruff check ${{ steps.files.outputs.files }} \ No newline at end of file From c75fcc77438a6d5b3230a3a291cf23186179b093 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 12 Aug 2024 17:20:33 +0200 Subject: [PATCH 02/22] lint the files in dgl_ptm and tests dirs --- .github/workflows/lint.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 80e6b39..6154431 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,9 +20,15 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install .[dev] - - name: Get changed files # for now, we only lint the changed files - id: files + - name: Get changed files in dgl_ptm folder # for now, we only lint the changed files + id: dgl_ptm run: | - echo "::set-output name=files::$(git diff --name-only origin/${{ github.base_ref }}...HEAD)" - - name: Check code style against standards - run: ruff check ${{ steps.files.outputs.files }} \ No newline at end of file + echo "::set-output name=dgl_ptm::$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^dgl_ptm/')" + - name: Check source code style against standards + run: ruff check ${{ steps.dgl_ptm.outputs.dgl_ptm }} + - name: Get changed files in tests folder # for now, we only lint the changed files + id: tests + run: | + echo "::set-output name=tests::$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^tests/')" + - name: Check tests code style against standards + run: ruff check ${{ steps.tests.outputs.tests }} \ No newline at end of file From d85b89165a74aa93b340ac555787ff4d5863940a Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 12 Aug 2024 17:46:45 +0200 Subject: [PATCH 03/22] fix base_ref and warning message --- .github/workflows/lint.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6154431..ec59608 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,6 +12,8 @@ jobs: working-directory: ./dgl_ptm steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python 3.11 uses: actions/setup-python@v3 with: @@ -23,12 +25,14 @@ jobs: - name: Get changed files in dgl_ptm folder # for now, we only lint the changed files id: dgl_ptm run: | - echo "::set-output name=dgl_ptm::$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^dgl_ptm/')" + git diff --name-only ${{ github.base_ref }}...HEAD | grep '^dgl_ptm/' > $GITHUB_ENV + echo "dgl_ptm=$(cat $GITHUB_ENV)" >> $GITHUB_ENV - name: Check source code style against standards run: ruff check ${{ steps.dgl_ptm.outputs.dgl_ptm }} - name: Get changed files in tests folder # for now, we only lint the changed files id: tests run: | - echo "::set-output name=tests::$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^tests/')" + git diff --name-only ${{ github.base_ref }}...HEAD | grep '^dgl_ptm/' > $GITHUB_ENV + echo "tests=$(cat $GITHUB_ENV)" >> $GITHUB_ENV - name: Check tests code style against standards run: ruff check ${{ steps.tests.outputs.tests }} \ No newline at end of file From 4a5c64ed76fc880a4314f30ec4ceb921a67106e4 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 12 Aug 2024 17:48:37 +0200 Subject: [PATCH 04/22] remove fetch --- .github/workflows/lint.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ec59608..2cc53f3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,8 +12,6 @@ jobs: working-directory: ./dgl_ptm steps: - uses: actions/checkout@v3 - with: - fetch-depth: 0 - name: Set up Python 3.11 uses: actions/setup-python@v3 with: From caa8986c599d0fbbdaad47a69f4a90f39095395d Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 12:13:01 +0200 Subject: [PATCH 05/22] fix linter workflow --- .github/workflows/lint.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2cc53f3..97d1b92 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,6 +12,8 @@ jobs: working-directory: ./dgl_ptm steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python 3.11 uses: actions/setup-python@v3 with: @@ -20,17 +22,9 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install .[dev] - - name: Get changed files in dgl_ptm folder # for now, we only lint the changed files - id: dgl_ptm + - name: Get changed files folder # for now, we only lint the changed files + id: files run: | - git diff --name-only ${{ github.base_ref }}...HEAD | grep '^dgl_ptm/' > $GITHUB_ENV - echo "dgl_ptm=$(cat $GITHUB_ENV)" >> $GITHUB_ENV + echo "files=$(git diff --name-only --diff-filter=d $GITHUB_BASE_REF...HEAD)" >> $GITHUB_ENV - name: Check source code style against standards - run: ruff check ${{ steps.dgl_ptm.outputs.dgl_ptm }} - - name: Get changed files in tests folder # for now, we only lint the changed files - id: tests - run: | - git diff --name-only ${{ github.base_ref }}...HEAD | grep '^dgl_ptm/' > $GITHUB_ENV - echo "tests=$(cat $GITHUB_ENV)" >> $GITHUB_ENV - - name: Check tests code style against standards - run: ruff check ${{ steps.tests.outputs.tests }} \ No newline at end of file + run: ruff check $(echo ${{ env.files }} | tr ' ' '\n') From 62bb9f894db9c9aa65d52756422b86cdd564389b Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 13:40:06 +0200 Subject: [PATCH 06/22] fix diff command --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 97d1b92..8073ddc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,6 +25,6 @@ jobs: - name: Get changed files folder # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --diff-filter=d $GITHUB_BASE_REF...HEAD)" >> $GITHUB_ENV + echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV - name: Check source code style against standards run: ruff check $(echo ${{ env.files }} | tr ' ' '\n') From 53ecf2b1f2d08d764ae9e68d8d9b54853fca523d Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 14:10:54 +0200 Subject: [PATCH 07/22] set working dir for git diff --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8073ddc..ddd7114 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,9 +22,9 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install .[dev] - - name: Get changed files folder # for now, we only lint the changed files + - name: Get changed files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV + echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- ./dgl_ptm)" >> $GITHUB_ENV - name: Check source code style against standards run: ruff check $(echo ${{ env.files }} | tr ' ' '\n') From 4471511e082603adc745ae2a305bc5e49f22712d Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 14:38:00 +0200 Subject: [PATCH 08/22] ruff check only if files are changed in dgl_ptm dir --- .github/workflows/lint.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ddd7114..1df64e8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,13 +18,13 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install .[dev] - name: Get changed files in dgl_ptm # for now, we only lint the changed files id: files run: | echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- ./dgl_ptm)" >> $GITHUB_ENV - - name: Check source code style against standards - run: ruff check $(echo ${{ env.files }} | tr ' ' '\n') + - name: Check code style against standards + if: env.files != '' + run: | + python -m pip install --upgrade pip + python -m pip install .[dev] + ruff check $(echo ${{ env.files }} | tr ' ' '\n') From 317f1bf5492c7ecacfc845b077dd1c2d02e313b3 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 14:46:48 +0200 Subject: [PATCH 09/22] fix linter errors on test_config --- dgl_ptm/tests/test_config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dgl_ptm/tests/test_config.py b/dgl_ptm/tests/test_config.py index 5799fb6..073e40b 100644 --- a/dgl_ptm/tests/test_config.py +++ b/dgl_ptm/tests/test_config.py @@ -4,6 +4,7 @@ from dgl_ptm.config import Config + @pytest.fixture def config_parameters(): return { @@ -43,7 +44,7 @@ def test_to_yaml(tmp_path): cfg = Config() cfg.to_yaml(tmp_path / "config.yaml") - with open(tmp_path / "config.yaml", "r") as f: + with open(tmp_path / "config.yaml") as f: cfg_dict = yaml.safe_load(f) assert cfg_dict["_model_identifier"] == "test" assert cfg_dict["number_agents"] == 100 From 5cfb6a4746cf68eb88e9d1be5f49055124625e1e Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 15:47:21 +0200 Subject: [PATCH 10/22] add a debug step --- .github/workflows/lint.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1df64e8..63b7743 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,3 +28,6 @@ jobs: python -m pip install --upgrade pip python -m pip install .[dev] ruff check $(echo ${{ env.files }} | tr ' ' '\n') + - name: Print message when files is empty + if: env.files == '' + run: echo "No files were changed." From 0623d9873dbbc2d8f23eb8e3eacedcc939ed397e Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 15:51:57 +0200 Subject: [PATCH 11/22] a minor edit to test_config --- dgl_ptm/tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgl_ptm/tests/test_config.py b/dgl_ptm/tests/test_config.py index 073e40b..d4b6d74 100644 --- a/dgl_ptm/tests/test_config.py +++ b/dgl_ptm/tests/test_config.py @@ -59,7 +59,7 @@ def test_invalid_fields(config_parameters): _ = Config.from_dict(config_parameters) def test_invalid_values(config_parameters): - """Test that invalid values are not accepted.""" + """Test invalid values.""" config_parameters["number_agents"] = -100 with pytest.raises(ValueError): _ = Config.from_dict(config_parameters) From ddb01cda8213bcea4b1049855060df17412a2ef9 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 16:00:19 +0200 Subject: [PATCH 12/22] fix email address in init --- dgl_ptm/dgl_ptm/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgl_ptm/dgl_ptm/__init__.py b/dgl_ptm/dgl_ptm/__init__.py index d629b89..a21976b 100644 --- a/dgl_ptm/dgl_ptm/__init__.py +++ b/dgl_ptm/dgl_ptm/__init__.py @@ -13,5 +13,5 @@ logging.getLogger(__name__).addHandler(logging.NullHandler()) __author__ = "Team Atlas" -__email__ = "p.chandramouli@esciencecenter.nl" +__email__ = "m.grootes@esciencecenter.nl" __version__ = "0.1.0" From 31ec4f43cdf40d4a119450e1c7a8f628e4a7caa1 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 16:23:00 +0200 Subject: [PATCH 13/22] remove install dependencies --- .github/workflows/lint.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 63b7743..dd4fe53 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,9 +7,6 @@ on: jobs: lint: runs-on: ubuntu-latest - defaults: - run: - working-directory: ./dgl_ptm steps: - uses: actions/checkout@v3 with: @@ -18,15 +15,15 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" - - name: Get changed files in dgl_ptm # for now, we only lint the changed files + - name: Get changed python files # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- ./dgl_ptm)" >> $GITHUB_ENV + echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- '*.py')" >> $GITHUB_ENV - name: Check code style against standards if: env.files != '' run: | python -m pip install --upgrade pip - python -m pip install .[dev] + python -m pip install ruff ruff check $(echo ${{ env.files }} | tr ' ' '\n') - name: Print message when files is empty if: env.files == '' From b164bac314944c53e37cf862a795d2dece062784 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 16:48:05 +0200 Subject: [PATCH 14/22] bring back install dependencies, set relative for git diff --- .github/workflows/lint.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dd4fe53..7e3eac6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,6 +7,9 @@ on: jobs: lint: runs-on: ubuntu-latest + defaults: + run: + working-directory: ./dgl_ptm steps: - uses: actions/checkout@v3 with: @@ -15,15 +18,16 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" - - name: Get changed python files # for now, we only lint the changed files + - name: Get changed files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- '*.py')" >> $GITHUB_ENV + echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV + echo ${{ env.files }} - name: Check code style against standards if: env.files != '' run: | python -m pip install --upgrade pip - python -m pip install ruff + python -m pip install .[dev] ruff check $(echo ${{ env.files }} | tr ' ' '\n') - name: Print message when files is empty if: env.files == '' From 46938ed163b30a9364cecead4a6ed5faa28db3cd Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 17:12:39 +0200 Subject: [PATCH 15/22] fix the format of env --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7e3eac6..1542af7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: - name: Get changed files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV + echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV echo ${{ env.files }} - name: Check code style against standards if: env.files != '' From 1f9e1a241c8237082be923332ad88e5078992141 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 17:24:40 +0200 Subject: [PATCH 16/22] fix linter errors of init --- dgl_ptm/dgl_ptm/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dgl_ptm/dgl_ptm/__init__.py b/dgl_ptm/dgl_ptm/__init__.py index a21976b..7bd8b0d 100644 --- a/dgl_ptm/dgl_ptm/__init__.py +++ b/dgl_ptm/dgl_ptm/__init__.py @@ -1,8 +1,6 @@ -"""Documentation about dgl_ptm""" +"""Documentation about dgl_ptm.""" import logging -#from dgl_ptm.model import initialize_model, step -from dgl_ptm.model.initialize_model import PovertyTrapModel # from dgl_ptm.agent import agent_update # from dgl_ptm.agentInteraction import trade_money # from dgl_ptm.network import global_attachment, link_deletion @@ -10,6 +8,11 @@ # from dgl_ptm.util import * from dgl_ptm import config +#from dgl_ptm.model import initialize_model, step +from dgl_ptm.model.initialize_model import PovertyTrapModel + +__all__ = ['config', 'PovertyTrapModel'] + logging.getLogger(__name__).addHandler(logging.NullHandler()) __author__ = "Team Atlas" From 80bd7375192488b32f5dd9731a08339bfca30afa Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Thu, 15 Aug 2024 17:25:35 +0200 Subject: [PATCH 17/22] remove debuging from the lint workflow --- .github/workflows/lint.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1542af7..b3ab554 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,12 +22,14 @@ jobs: id: files run: | echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV - echo ${{ env.files }} - - name: Check code style against standards + - name: Install dependencies # ruff tools are installed in the dev dependencies if: env.files != '' run: | python -m pip install --upgrade pip python -m pip install .[dev] + - name: Check code style against standards + if: env.files != '' + run: | ruff check $(echo ${{ env.files }} | tr ' ' '\n') - name: Print message when files is empty if: env.files == '' From 0fbb8c28b3febebe3af7f4b31d4127c9d0d203ed Mon Sep 17 00:00:00 2001 From: Victoria Date: Fri, 16 Aug 2024 13:48:50 +0200 Subject: [PATCH 18/22] minor cleaning of unused comments and print statements --- dgl_ptm/dgl_ptm/agent/wealth_consumption.py | 10 ++--- dgl_ptm/dgl_ptm/model/initialize_model.py | 42 --------------------- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/dgl_ptm/dgl_ptm/agent/wealth_consumption.py b/dgl_ptm/dgl_ptm/agent/wealth_consumption.py index 094cc84..287dec8 100644 --- a/dgl_ptm/dgl_ptm/agent/wealth_consumption.py +++ b/dgl_ptm/dgl_ptm/agent/wealth_consumption.py @@ -188,7 +188,7 @@ def _nn_bellman_past_shock_consumption(model_graph,model_params, timestep, devi if model_params['nn_path']==None: print("No consumption model path provided!") - #load model + # Load model estimator,scale = load_consumption_model(model_params['nn_path'],device) @@ -197,21 +197,17 @@ def _nn_bellman_past_shock_consumption(model_graph,model_params, timestep, devi input = torch.cat((model_graph.ndata['alpha'].unsqueeze(1), model_graph.ndata['wealth'].unsqueeze(1), model_graph.ndata['sigma'].unsqueeze(1), model_graph.ndata['theta'].unsqueeze(1)), dim=1) - #forward pass to get predictions + # Forward pass to get predictions with torch.no_grad(): pred=estimator(input) - - #print(" went forward, writing values") - model_graph.ndata['m'],model_graph.ndata['i_a']=model_graph.ndata['a_table'][torch.arange(model_graph.ndata['a_table'].size(0)),:,torch.argmin(torch.abs(pred[:, 0].unsqueeze(1) - model_graph.ndata['a_table'][:,1,:]), dim=1)].unbind(dim=1) #print("Cleaning output and checking for violations") - #Clean Consumption + # Clean Consumption model_graph.ndata['wealth_consumption']=(pred[:,1]*scale).clamp_(min=0) - #print(" violation check") # Check for violations # An equation violation occurs when personally shocked, depreciated k + income - consumption - i_a is less than or equal to 0 diff --git a/dgl_ptm/dgl_ptm/model/initialize_model.py b/dgl_ptm/dgl_ptm/model/initialize_model.py index 4ada728..cde91ff 100644 --- a/dgl_ptm/dgl_ptm/model/initialize_model.py +++ b/dgl_ptm/dgl_ptm/model/initialize_model.py @@ -90,48 +90,6 @@ class PovertyTrapModel(Model): """ Poverty Trap model as derived model class - default_model_parameters = {'number_agents': 100 , - 'seed':0, - 'gamma_vals':torch.tensor([0.3,0.45]) , #for pseudo income - 'sigma_dist': {'type':'uniform','parameters':[0.05,1.94],'round':True,'decimals':1}, - 'cost_vals': torch.tensor([0.,0.45]), #for pseudo income - 'tec_levels': torch.tensor([0,1]), #check if deletable - 'a_theta_dist': {'type':'uniform','parameters':[0.1,1],'round':False,'decimals':None}, - 'sensitivity_dist':{'type':'uniform','parameters':[0.0,1],'round':False,'decimals':None}, - 'tec_dist': {'type':'bernoulli','parameters':[0.5,None],'round':False,'decimals':None}, - 'capital_dist': {'type':'uniform','parameters':[0.1,10.],'round':False,'decimals':None}, - 'alpha_dist': {'type':'normal','parameters':[1.08,0.074],'round':False,'decimals':None}, - 'lam_dist': {'type':'uniform','parameters':[0.05,0.94],'round':True,'decimals':1}, - 'initial_graph_type': 'barabasi-albert', - 'initial_graph_args': {'seed': 0, 'new_node_edges':1}, - 'device': 'cpu', - 'step_count':0, - 'step_target':20, - 'steering_parameters':{'npath':'./agent_data.zarr', - 'epath':'./edge_data', - 'ndata':['all_except',['a_table']], - 'edata':['all'], - 'mode':'xarray', - 'wealth_method':'singular_transfer', - 'income_method':'pseudo_income_generation', - 'tech_gamma': torch.tensor([0.3,0.35,0.45]), - 'tech_cost': torch.tensor([0,0.15,0.65]), - 'consume_method':'pseudo_consumption', - 'nn_path': None, - 'adapt_m':torch.tensor([0,0.5,0.9]), - 'adapt_cost':torch.tensor([0,0.25,0.45]), - 'depreciation': 0.6, - 'discount': 0.95, - 'm_theta_dist': {'type':'multinomial','parameters':[[0.02 ,0.03, 0.05, 0.9],[0.7, 0.8, 0.9, 1]],'round':False,'decimals':None}, - 'm_attach_dist': {'type':'uniform','parameters':[0.001,1],'round':False,'decimals':None}, - 'del_method':'probability', - 'del_threshold':0.05, - 'ratio':0.1, - 'weight_a':0.69, - 'weight_b':35, - 'truncation_weight':1.0e-10, - 'step_type':'default'}} - """ def __init__(self,*, model_identifier): From 533f350ffb24c4af9cc19b12ba27e72bee2f2394 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 19 Aug 2024 14:38:17 +0200 Subject: [PATCH 19/22] set some linter parameters in pyproject.toml --- dgl_ptm/pyproject.toml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/dgl_ptm/pyproject.toml b/dgl_ptm/pyproject.toml index 48a7322..a833142 100644 --- a/dgl_ptm/pyproject.toml +++ b/dgl_ptm/pyproject.toml @@ -36,8 +36,6 @@ classifiers=[ 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Natural Language :: English', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', ] @@ -89,16 +87,32 @@ select = [ "N", # PEP8-naming "UP", # pyupgrade (upgrade syntax to current syntax) "PLE", # Pylint error https://github.com/charliermarsh/ruff#error-ple + "PLR", # Pylint refactor (e.g. too-many-arguments) + "PLW", # Pylint warning (useless-else-on-loop) +] +extend-select = [ + "D401", # First line should be in imperative mood + "D400", # First line should end in a period. + "TID252", # No relative imports (not pep8 compliant) ] ignore = [ -"D100", "D101", "D104", "D105", "D106", "D107", "D203", "D213" -] # docstring style + "PLR2004", # magic value used in comparsion. + "PLR0913", # too many arguments +] line-length = 88 + exclude = ["docs", "build"] + # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -target-version = "py39" +target-version = "py311" [tool.ruff.per-file-ignores] "tests/**" = ["D"] + +[tool.ruff.lint.pydocstyle] +convention = "google" + +[tool.ruff.lint.mccabe] +max-complexity = 10 From 97b2ba3c7d41ba93ded79819d11bbfd262f2d67f Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 19 Aug 2024 14:39:00 +0200 Subject: [PATCH 20/22] lint only python files, add a comment about pyproject.toml and ruff settings --- .github/workflows/lint.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b3ab554..9d4eb83 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Linting +name: Linting with ruff # settings are in pyproject.toml on: pull_request: # only run on pull requests for now @@ -18,10 +18,10 @@ jobs: uses: actions/setup-python@v3 with: python-version: "3.11" - - name: Get changed files in dgl_ptm # for now, we only lint the changed files + - name: Get changed python files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV + echo "files=$(git diff --name-only --relative --diff-filter=d "*.py" origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV - name: Install dependencies # ruff tools are installed in the dev dependencies if: env.files != '' run: | @@ -33,4 +33,4 @@ jobs: ruff check $(echo ${{ env.files }} | tr ' ' '\n') - name: Print message when files is empty if: env.files == '' - run: echo "No files were changed." + run: echo "No python files were changed." From 7cd8443d40f6b1f0ed4d93f6a631be34f4d2feb1 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 19 Aug 2024 15:07:03 +0200 Subject: [PATCH 21/22] fix git diff command in lint workflow --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9d4eb83..ba72927 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: - name: Get changed python files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --relative --diff-filter=d "*.py" origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV + echo "files=$(git diff --name-only --relative --diff-filter=d -- "*.py" origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV - name: Install dependencies # ruff tools are installed in the dev dependencies if: env.files != '' run: | From 6b7e6d45b27d1c61b8a5dfb6f8c6a15a28f632c7 Mon Sep 17 00:00:00 2001 From: SarahAlidoost Date: Mon, 19 Aug 2024 15:25:32 +0200 Subject: [PATCH 22/22] fix git diff command --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ba72927..73ba4bb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: - name: Get changed python files in dgl_ptm # for now, we only lint the changed files id: files run: | - echo "files=$(git diff --name-only --relative --diff-filter=d -- "*.py" origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF | tr '\n' ' ')" >> $GITHUB_ENV + echo "files=$(git diff --name-only --relative --diff-filter=d origin/$GITHUB_BASE_REF...origin/$GITHUB_HEAD_REF -- "*.py" | tr '\n' ' ')" >> $GITHUB_ENV - name: Install dependencies # ruff tools are installed in the dev dependencies if: env.files != '' run: |