Repository navigation
Conversation
# Conflicts: # CHANGELOG.md # sympde/topology/tests/test_topology.py
yguclu
left a comment
There was a problem hiding this comment.
Thanks for this contribution!
I have posted a couple of suggestions below.
If you are comfortable with adding your full name to the bottom of the AUTHORS file, please feel free to do so. We do not list contributors under their GitHub username or other aliases
| dim = str(self.dim) | ||
| ldim = str(self.dim) | ||
| mappings = [m for m in self.mappings.values() if m is not None] | ||
| pdim = str(mappings[0].pdim) if mappings else ldim |
There was a problem hiding this comment.
If todict takes pdim from the first mapping, a domain whose patches have different physical dimensions is exported with a wrong pdim for some patches (this is currently possible because Domain.join does not check pdim, see #140, which will be fixed in #188). I recommend that we raise an error in that case:
| pdim = str(mappings[0].pdim) if mappings else ldim | |
| pdim = {m.pdim for m in self.mappings.values() if m is not None} | |
| if len(pdims) > 1: | |
| raise ValueError(f'all mappings must have the same physical dimension, got {sorted(pdims)}') | |
| pdim = str(pdims.pop()) if pdims else ldim |
|
|
||
| with pytest.raises(ValueError, match="older version of SymPDE"): | ||
| Domain.from_file(filename) | ||
|
|
There was a problem hiding this comment.
Please see my comment to Domain.todict(). Here we should add a test which joins a patch mapped with pdim=3 and a patch mapped with pdim=2, and checks that exporting the result raises a ValueError:
#==============================================================================
def test_export_mappings_with_different_pdim(tmp_path):
A = Mapping('FA', ldim=2, pdim=3)(Square('A'))
B = Mapping('FB', ldim=2, pdim=2)(Square('B'))
with pytest.raises(ValueError):
domain = Domain.join([A, B], [((0, 0, 1), (1, 0, -1), 1)], name='Omega')
domain.export(str(tmp_path / 'omega.h5'))Both Domain.join and export are inside the pytest.raises block on purpose: today the error is raised by export, and once #140 is fixed it will be raised earlier by Domain.join, so the test keeps passing in both cases.
|
|
||
| ### Fixed | ||
|
|
||
| - #200: Keep the physical dimension of the mappings in `Domain.export` and `Domain.from_file`. The `topology.yml` metadata now stores `ldim` and `pdim` instead of `dim`, and `Domain.from_file` raises an error for files with the old `dim` key. |
There was a problem hiding this comment.
I would split this into two separate points. A new one should go under "Changed" (see my other comment to this file) and this one should become much shorter:
| - #200: Keep the physical dimension of the mappings in `Domain.export` and `Domain.from_file`. The `topology.yml` metadata now stores `ldim` and `pdim` instead of `dim`, and `Domain.from_file` raises an error for files with the old `dim` key. | |
| - #200: Keep the physical dimension of the mappings in `Domain.export()` and `Domain.from_file()`. |
| - [DEVELOPER] #106: Add the public helpers `new_basic()` and `restore_*_argument()` in `sympde.core.basic` for storing non-expression arguments in SymPy objects. | ||
|
|
||
| ### Changed | ||
|
|
There was a problem hiding this comment.
Here we should add a point:
| - #200: Store `ldim` and `pdim` instead of `dim` in the topology of domain files. This is a breaking change: `Domain.from_file()` rejects files with `dim`. |
Fixes #200, following the proposal in the issue:
Domain.todict(and soDomain.export) writesldimandpdiminstead ofdim.pdimcomes from the domain's mappings, or equalsldimfor an unmapped domain.Domain.from_filecreates each mapping withldimandpdim.dimkey raises aValueErrorsaying it was written by an older version of SymPDE and thatdimmust be replaced byldimandpdim.# TODO add pdimcomment is removed and a CHANGELOG entry is added under Fixed.Tests in
test_topology.py:test_export_surface_mapping: a round trip ofMapping('F', ldim=2, pdim=3)(Square('Omega'))keepspdim == 3.test_from_file_with_old_dim_key: a file withdimraises the error.sympde/topologytests pass locally (72 passed).This changes the same
from_fileline as #196 (Mapping→SymbolicMapping), so whichever PR lands second needs a one-line rebase.