diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..9498df7 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,59 @@ +name: Build Docker Image + +on: + push: + branches: [main, dev, ci] + tags: + - 'v*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository_owner }}/demos + +jobs: + publish: + name: Build and publish Docker image + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta (tags) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=ref,event=branch + type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + + - run: echo "${{ steps.meta.outputs.tags }}" + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/demos/models/income_adjustment.py b/demos/models/income_adjustment.py index a1fc331..d42b1a3 100644 --- a/demos/models/income_adjustment.py +++ b/demos/models/income_adjustment.py @@ -43,7 +43,9 @@ def income_adjustment(persons, households, income_rates, year): start_time = time.time() # TODO: CountyID is not being updated by default # Update income according to county rate - income_rates['lcm_county_id'] = income_rates['lcm_county_id'].map(lambda x: f'{x:0>5}') + income_rates["lcm_county_id"] = income_rates["lcm_county_id"].map( + lambda x: f"{x:0>5}" + ) persons.local.earning *= ( 1 diff --git a/demos/models/kids_moving.py b/demos/models/kids_moving.py index 5abd73b..c0800d8 100644 --- a/demos/models/kids_moving.py +++ b/demos/models/kids_moving.py @@ -138,7 +138,14 @@ def run_and_calibrate_model(persons): demos_config: DEMOSConfig = get_config() module_config: KidsMovingModuleConfig = demos_config.kids_moving_module_config - child_relate = [2, 3, 4, 7, 9, 14] # This is more `dependent` because `child` is determined by age + child_relate = [ + 2, + 3, + 4, + 7, + 9, + 14, + ] # This is more `dependent` because `child` is determined by age target_share = module_config.calibration_target_share # Get model data @@ -149,25 +156,29 @@ def run_and_calibrate_model(persons): kids_moving = model.predict(model_data).astype(int) # NOTE: This could be much easier if we set the age at 18 because we could use model_filters - adult_filter = (persons.age >= 18) + adult_filter = persons.age >= 18 age_moved = persons.age.loc[kids_moving[kids_moving == 1].index] - adult_stay = (adult_filter & persons.relate.isin(child_relate)).sum() - (age_moved >=18).sum() + adult_stay = (adult_filter & persons.relate.isin(child_relate)).sum() - ( + age_moved >= 18 + ).sum() observed_share = adult_stay / adult_filter.sum() - error = (observed_share - target_share) + error = observed_share - target_share print("Calibrating Kids moving model") calibrate_iteration = 0 - while abs(error) > module_config.calibration_tolerance: + while abs(error) > module_config.calibration_tolerance: print(f"{calibrate_iteration} iteration error: {error}") - model.fitted_parameters[0] += np.log(observed_share/target_share) + model.fitted_parameters[0] += np.log(observed_share / target_share) kids_moving = model.predict(model_data).astype(int) age_moved = persons.age.loc[kids_moving[kids_moving == 1].index] - adult_stay = (adult_filter & persons.relate.isin(child_relate)).sum() - (age_moved >=18).sum() + adult_stay = (adult_filter & persons.relate.isin(child_relate)).sum() - ( + age_moved >= 18 + ).sum() observed_share = adult_stay / adult_filter.sum() - error = (observed_share - target_share) + error = observed_share - target_share calibrate_iteration += 1 print(f"{calibrate_iteration} iteration error: {error}") - return kids_moving \ No newline at end of file + return kids_moving diff --git a/demos/models/marriage.py b/demos/models/marriage.py index c8027eb..ef02e6d 100644 --- a/demos/models/marriage.py +++ b/demos/models/marriage.py @@ -201,8 +201,9 @@ def update_married_households_random( module_config.geoid_col, ].values households.local.loc[new_hh_ids, module_config.geoid_col] = new_hh_geoid - county_assignment = households.local.loc[all_df.loc[first_index & neither_head_index, "household_id"], - "lcm_county_id"].values + county_assignment = households.local.loc[ + all_df.loc[first_index & neither_head_index, "household_id"], "lcm_county_id" + ].values households.local.loc[new_hh_ids, "lcm_county_id"] = county_assignment ## Decide who is household head in the households where the head left head_left_index = (all_df.relate == 0) & (all_df.household_id != all_df.new_hh_id) @@ -279,9 +280,7 @@ def update_divorce(persons, households, divorce_list, get_new_households): geoid_assignment = households.local.loc[ old_household_id, module_config.geoid_col ].values - households.local.loc[new_households, module_config.geoid_col] = ( - geoid_assignment - ) + households.local.loc[new_households, module_config.geoid_col] = geoid_assignment county_assignment = households.local.loc[old_household_id, "lcm_county_id"].values households.local.loc[new_households, "lcm_county_id"] = county_assignment diff --git a/demos/variables.py b/demos/variables.py index aa6fe72..daa4dda 100644 --- a/demos/variables.py +++ b/demos/variables.py @@ -632,6 +632,7 @@ def marital34(persons): p = persons.to_frame(columns=["MAR"]) return p.isin([3, 4]).astype(int) + ######## NOTE: Not needed for now # # PERSON VARIABLES # # ----------------------------------------------------------------------------------------- diff --git a/docker-compose.yml b/docker-compose.yml index 1c6c340..c4c51a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: build: context: . dockerfile: Dockerfile - image: demos:0.0.1 + image: ghcr.io/${GITHUB_REPOSITORY_OWNER:-nrel}/demos tty: true platform: linux/amd64 environment: