Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Extend flattened_tup_chain capability for diagnostics, update VariableTemplates #1929

Merged
merged 1 commit into from
Jan 16, 2021

Conversation

charleskawczynski
Copy link
Member

@charleskawczynski charleskawczynski commented Jan 15, 2021

Description

This PR:

  • Removes the CPU getindex(x, i::Int) fallback (# Somehow needed for GPU... was basically a TODO), so our CPU/GPU failures should be more nicely in sync. Interestingly, the getindex(x, i::Int) was hit on the GPU but worked in certain situations and not others. I've accordingly wrapped indexes with Val (in EDMF-related files)
  • Simplifies the nested intertwined getproperty/getindex flow control, which previously used if-else and now only uses dispatch
  • Split some methods to avoid isa calls in getindex

And the new feature:

  • flattened_tup_chain now has two modes of operation: one that retains arrays (RetainArr) and flatten arrays (FlattenArr).
  • flattened_named_tuple also has this option. Here is a demo (where v::Vars and vars_state(...) = @vars(x::SVector{3, FT})):
    fnt = flattened_named_tuple(v, RetainArr())
    @test fnt.x == Float32[1.0, 2.0, 3.0]

    fnt = flattened_named_tuple(v, FlattenArr())
    @test fnt.x_1 == 1.0
    @test fnt.x_2 == 2.0
    @test fnt.x_3 == 3.0

I've kept the old functionality (with RetainArr), as this may be useful if we want to automate traversing variables (e.g., #1921, in which case we'll need to work with the vectors)

This also flattens the single stack diagnostics, which will allow us to more easily automate the conversion between dons_arr and diag_arr cc @ilopezgp.

This also cleans up some of the edmf QA script. ⏳

  • Code follows the style guidelines OR N/A.
  • Unit tests are included OR N/A.
  • Code is exercised in an integration test OR N/A.
  • Documentation has been added/updated OR N/A.

@charleskawczynski
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jan 15, 2021
1929: Extend `flattened_tup_chain` capability for diagnostics, update VariableTemplates r=charleskawczynski a=charleskawczynski

### Description

This PR:
 - Removes the CPU `getindex(x, i::Int)` fallback (`# Somehow needed for GPU...` was basically a TODO), so our CPU/GPU failures should be more nicely in sync. Interestingly, the `getindex(x, i::Int)` was hit on the GPU but worked in certain situations and not others. I've accordingly wrapped indexes with `Val` (in EDMF-related files)
 - Simplifies the nested intertwined `getproperty`/`getindex` flow control, which previously used `if-else` and now only uses dispatch
 - Split some methods to avoid `isa` calls in `getindex`

And the new feature:
 - `flattened_tup_chain` now has two modes of operation: one that retains arrays (`RetainArr`) and flatten arrays (`FlattenArr`).
 - `flattened_named_tuple` also has this option. Here is a demo (where `v::Vars` and `vars_state(...) = @vars(x::SVector{3, FT})`):

```julia
    fnt = flattened_named_tuple(v, RetainArr())
    @test fnt.x == Float32[1.0, 2.0, 3.0]

    fnt = flattened_named_tuple(v, FlattenArr())
    @test fnt.x_1 == 1.0
    @test fnt.x_2 == 2.0
    @test fnt.x_3 == 3.0
```

I've kept the old functionality (with `RetainArr`), as this may be useful if we want to automate traversing variables (e.g., #1921, in which case we'll need to work with the vectors)

This also flattens the single stack diagnostics, which will allow us to more easily automate the conversion between `dons_arr` and `diag_arr` cc @ilopezgp.

This also cleans up some of the edmf QA script. ⏳ 



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 15, 2021

Build failed:

@charleskawczynski
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 16, 2021

@bors bors bot merged commit 8c57fb5 into master Jan 16, 2021
@bors bors bot deleted the ck/variable_templates branch January 16, 2021 02:51
bors bot added a commit that referenced this pull request Jan 17, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 18, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 18, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 18, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 19, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 19, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
bors bot added a commit that referenced this pull request Jan 25, 2021
1931: Fix NamedTuple keys, add error handling r=charleskawczynski a=charleskawczynski

### Description

After #1929, there is some mismatch with the keys and values returned from `flattened_named_tuple` and thus `single_stack_diagnostics` (e.g., IIRC, mixing length). cc @yairchn @ilopezgp. This PR should fix this mismatch. Specifically, adding

```julia
    length(keys_) == length(vals) || error("key-value mismatch")
```

to `flattened_named_tuple` errors on master due to improper handling of `SHermitianCompact` and `Diagonal` arrays. This required some changes / additions to `flattened_nt_vals`.



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants