From 0a040a5701be7e83f9057b57a2c889818628fdb2 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 1 Sep 2022 11:08:25 +0900 Subject: [PATCH 1/9] Update wheel build setting --- python/pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 283db0b7..f299a1fa 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -2,4 +2,6 @@ requires = ["setuptools", "wheel", "numpy"] [tool.cibuildwheel] -skip = ["pp*", "*-win32", "*-manylinux_i686"] +skip = ["pp*", "*-win32", "*-manylinux_i686", "*-musllinux*"] +manylinux-x86_64-image = "manylinux2014" +manylinux-aarch64-image = "manylinux2014" From b8517d02c318ab9edaea187465b1027e22bc81e7 Mon Sep 17 00:00:00 2001 From: Kohei Shinohara Date: Thu, 22 Sep 2022 13:25:19 +0900 Subject: [PATCH 2/9] Add issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 33 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 24 +++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..3e239e50 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +## Describe the bug + + + +## To Reproduce + + + +## Expected behavior + + + +## Environment + +- Python version: +- Spglib's version: + +## Additional context + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..a725315a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,24 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +## Is your feature request related to a problem? Please describe. + + + +## Describe the solution you'd like + + + +## Describe alternatives you've considered + + + +## Additional context + + From ec28d69df9416a77f225dd68985c04794550be02 Mon Sep 17 00:00:00 2001 From: steinmig Date: Tue, 27 Sep 2022 12:22:31 +0200 Subject: [PATCH 3/9] exclude sources from unity builds --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e75ef1a6..9c6287bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,11 @@ set(SOURCES ${PROJECT_SOURCE_DIR}/src/arithmetic.c ${PROJECT_SOURCE_DIR}/src/spin.c ${PROJECT_SOURCE_DIR}/src/symmetry.c) +# avoid One Definition Rule problems +set_source_files_properties( + ${SOURCES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON +) + # Shared library add_library(symspg SHARED ${SOURCES}) From dda25d32f5e93db4a14d07f5945ac24ebc75313f Mon Sep 17 00:00:00 2001 From: steinmig Date: Tue, 27 Sep 2022 15:36:00 +0200 Subject: [PATCH 4/9] ensure cmake compatibility --- CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6287bc..4cd00535 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,9 +81,15 @@ set(SOURCES ${PROJECT_SOURCE_DIR}/src/arithmetic.c ${PROJECT_SOURCE_DIR}/src/symmetry.c) # avoid One Definition Rule problems -set_source_files_properties( - ${SOURCES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON -) +# only available since 3.16.0 +# VERSION_GREATER_EQUAL only available since 3.7.0, so let's do it manually +if (NOT CMAKE_MAJOR_VERSION LESS "3") + if (CMAKE_MAJOR_VERSION GREATER "3" OR NOT CMAKE_MINOR_VERSION LESS "16") + set_source_files_properties( + ${SOURCES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON + ) + endif() +endif() # Shared library add_library(symspg SHARED ${SOURCES}) From feb1605414b29a99783fb06866f32d6f9a92f084 Mon Sep 17 00:00:00 2001 From: lan496 Date: Fri, 28 Oct 2022 08:44:55 +0000 Subject: [PATCH 5/9] Fix typo in flags --- doc/magnetic_symmetry_flags.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/magnetic_symmetry_flags.md b/doc/magnetic_symmetry_flags.md index 828024ba..6b14f5da 100644 --- a/doc/magnetic_symmetry_flags.md +++ b/doc/magnetic_symmetry_flags.md @@ -30,10 +30,10 @@ - `tensor_rank=1` - `with_time_reversal=true`: {math}`1' \circ \mathbf{m} = -\mathbf{m}` - `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = (\mathrm{det} \mathbf{R}) \mathbf{R} \mathbf{m}` - - `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}` + - `is_axial=false`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}` - `with_time_reversal=false`: {math}`1' \circ \mathbf{m} = \mathbf{m}` - `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = (\mathrm{det} \mathbf{R}) \mathbf{R} \mathbf{m}` - - `is_axial=true`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}` + - `is_axial=false`: {math}`(\mathbf{R}, \mathbf{v}) \circ \mathbf{m} = \mathbf{R} \mathbf{m}` ## Environment - -- Python version: -- Spglib's version: + +- Python version: +- Spglib's version: ## Additional context From 4dd11a6a61d316737d67af305230eb211e1351da Mon Sep 17 00:00:00 2001 From: lan496 Date: Fri, 28 Oct 2022 09:10:54 +0000 Subject: [PATCH 7/9] Skip to determine time-reversal part for non-overlapped operations Time-reversal parts are searched after determining linear and translation parts of symmetry operations by `get_dataset`. It is impossible in theory but we rarely fail to overlap atoms possibly due to too high symprec. In that case, skip the symmetry operation. --- src/overlap.c | 2 +- src/spin.c | 8 +++-- test/test_magnetic_symmetry.cpp | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/overlap.c b/src/overlap.c index 30a8f31b..b73ab367 100644 --- a/src/overlap.c +++ b/src/overlap.c @@ -641,7 +641,7 @@ static int check_total_overlap_for_sorted( search_start = 0; for (i_orig = 0; i_orig < num_pos; i_orig++) { /* Permanently skip positions filled near the beginning. */ - while (found[search_start]) { + while ((search_start < num_pos) && found[search_start]) { search_start++; } diff --git a/src/spin.c b/src/spin.c index 158c62eb..c19240b1 100644 --- a/src/spin.c +++ b/src/spin.c @@ -408,8 +408,12 @@ static MagneticSymmetry *get_operations( } } if (k == cell->size) { - /* Unreachable here! */ - return NULL; + // Unreachable here in theory, but we rarely fail to overlap + // atoms possibly due to too high symprec. In that case, skip + // the symmetry operation. + debug_print("Failed to overlap atom-%d by operation-%d\n", j, i); + found = 0; + break; } // Skip if relevant tensors are zeros because they have nothing to diff --git a/test/test_magnetic_symmetry.cpp b/test/test_magnetic_symmetry.cpp index 6973a913..2355a1d3 100644 --- a/test/test_magnetic_symmetry.cpp +++ b/test/test_magnetic_symmetry.cpp @@ -360,6 +360,66 @@ TEST( free(time_reversals); } +TEST( + test_magnetic_symmetry, + test_spg_get_symmetry_with_tensors_rough_mag_symprec) { + + // https://github.com/spglib/spglib/issues/194 + // Part of "mp-806965" in the Materials Project database + double lattice[][3] = { // column-wise! + {5.24191, -0.003459, -2.618402}, + {0, 5.600534, -1.87898}, + {0, 0, 11.148141}, + }; + double positions[][3] = { + {0.829407, 0.834674, 0.662821}, + {0.665078, 0.665214, 0.316142}, + {0.001174, 0.996383, 0.002809}, + {0.181127, 0.169218, 0.349259}, + }; + int types[] = {0, 0, 0, 0}; + double tensors[] = {1.927, 1.947, 1.928, 1.949}; + int num_atoms = 4; + int max_size = num_atoms * 96; + + double symprec = 0.1; // with very high symprec + double mag_symprec = symprec; + + int i, size; + int equivalent_atoms[4]; + double primitive_lattice[3][3]; + int(*rotations)[3][3]; + double(*translations)[3]; + int *spin_flips; + int *time_reversals; + + rotations = (int(*)[3][3])malloc(sizeof(int[3][3]) * max_size); + translations = (double(*)[3])malloc(sizeof(double[3]) * max_size); + spin_flips = (int *)malloc(sizeof(int *) * max_size); + time_reversals = (int *)malloc(sizeof(int *) * max_size); + + size = spg_get_symmetry(rotations, translations, max_size, lattice, positions, types, num_atoms, symprec); + show_symmetry_operations(rotations, translations, size); + + size = spgms_get_symmetry_with_site_tensors( + rotations, translations, equivalent_atoms, primitive_lattice, spin_flips, + max_size, lattice, positions, types, tensors, + 0 /* tensor_rank */ , num_atoms, + 1 /* with_time_reversal */, + 0 /* is_axial */, + symprec, -1 /* angle_tolerance */, mag_symprec); + + for (i = 0; i < size; i++) { + time_reversals[i] = (1 - spin_flips[i]) / 2; + } + show_magnetic_symmetry_operations(rotations, translations, time_reversals, size); + + free(rotations); + free(translations); + free(spin_flips); + free(time_reversals); +} + // TODO: test get_magnetic_dataset with distorted positions // **************************************************************************** From 4e8bf3872b4c2c113d687bf43ec93e25bccd629c Mon Sep 17 00:00:00 2001 From: lan496 Date: Mon, 31 Oct 2022 02:31:36 +0000 Subject: [PATCH 8/9] Fix possible segmentation fault in `get_magnetic_dataset` Because we cannot assume magnetic symmetry search is always successful, this commit fixes gracefully to return NULL for such a difficult situation with possibly too high symprec and mag_symprec. --- src/spglib.c | 13 ++++++++++--- src/spin.c | 11 ++++++----- test/test_magnetic_symmetry.cpp | 23 ++++++++++++++++++----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/spglib.c b/src/spglib.c index de3a78eb..208248d4 100644 --- a/src/spglib.c +++ b/src/spglib.c @@ -1316,6 +1316,7 @@ static SpglibMagneticDataset *get_magnetic_dataset( if (spglib_error_code == SPGLIB_SUCCESS) { return dataset; } else { + spg_free_magnetic_dataset(dataset); return NULL; } } @@ -1779,9 +1780,15 @@ static MagneticSymmetry *get_symmetry_with_site_tensors( spg_free_dataset(dataset); dataset = NULL; - magnetic_symmetry = spn_get_operations_with_site_tensors( - &equiv_atoms, permutations, primitive_lattice, sym_nonspin, cell, - with_time_reversal, is_axial, symprec, angle_tolerance, mag_symprec); + if ((magnetic_symmetry = spn_get_operations_with_site_tensors( + &equiv_atoms, permutations, primitive_lattice, sym_nonspin, cell, + with_time_reversal, is_axial, symprec, angle_tolerance, + mag_symprec)) == NULL) { + sym_free_symmetry(sym_nonspin); + sym_nonspin = NULL; + goto err; + } + /* Set equivalent_atoms */ for (i = 0; i < cell->size; i++) { equivalent_atoms[i] = equiv_atoms[i]; diff --git a/src/spin.c b/src/spin.c index c19240b1..0f54cd22 100644 --- a/src/spin.c +++ b/src/spin.c @@ -411,7 +411,8 @@ static MagneticSymmetry *get_operations( // Unreachable here in theory, but we rarely fail to overlap // atoms possibly due to too high symprec. In that case, skip // the symmetry operation. - debug_print("Failed to overlap atom-%d by operation-%d\n", j, i); + debug_print("Failed to overlap atom-%d by operation-%d\n", j, + i); found = 0; break; } @@ -562,9 +563,9 @@ static MagneticSymmetry *get_operations( return NULL; } -/* Return permutation tables `permutations` such that the p-th operation */ -/* in `magnetic_symmetry` maps site-`i` to site-`permutations[p * cell->size + - * i]`. */ +// Return permutation tables `permutations` such that the p-th operation +// in `magnetic_symmetry` maps site-`i` to site-`permutations[p * cell->size + +// * i]`. If failed, return NULL. static int *get_symmetry_permutations(const MagneticSymmetry *magnetic_symmetry, const Cell *cell, const int with_time_reversal, @@ -659,7 +660,7 @@ static int *get_symmetry_permutations(const MagneticSymmetry *magnetic_symmetry, return permutations; } -/* Return equivalent_atoms */ +// Return equivalent_atoms. If failed, return NULL. static int *get_orbits(const int *permutations, const int num_sym, const int num_atoms) { int s, i; diff --git a/test/test_magnetic_symmetry.cpp b/test/test_magnetic_symmetry.cpp index 2355a1d3..43db038e 100644 --- a/test/test_magnetic_symmetry.cpp +++ b/test/test_magnetic_symmetry.cpp @@ -362,8 +362,7 @@ TEST( TEST( test_magnetic_symmetry, - test_spg_get_symmetry_with_tensors_rough_mag_symprec) { - + test_with_broken_symmetry) { // https://github.com/spglib/spglib/issues/194 // Part of "mp-806965" in the Materials Project database double lattice[][3] = { // column-wise! @@ -398,9 +397,11 @@ TEST( spin_flips = (int *)malloc(sizeof(int *) * max_size); time_reversals = (int *)malloc(sizeof(int *) * max_size); - size = spg_get_symmetry(rotations, translations, max_size, lattice, positions, types, num_atoms, symprec); - show_symmetry_operations(rotations, translations, size); - + // Check magnetic symmetry search + // spg_get_symmetry returns four operations, but spgms_get_symmetry_with_site_tensors + // only returns three of them. This is due to too high symprec: detected operations + // in `sym_get_operation` follow `symprec`, but refined operations in + // `ref_get_exact_structure_and_symmetry` does not. size = spgms_get_symmetry_with_site_tensors( rotations, translations, equivalent_atoms, primitive_lattice, spin_flips, max_size, lattice, positions, types, tensors, @@ -413,11 +414,23 @@ TEST( time_reversals[i] = (1 - spin_flips[i]) / 2; } show_magnetic_symmetry_operations(rotations, translations, time_reversals, size); + ASSERT_TRUE(size >= 1); + + // Check magnetic dataset construction + // Since detected magnetic symmetry operations do not form a group due to high symprec, + // we fail to get magnetic dataset for now. + SpglibMagneticDataset *dataset; + dataset = spg_get_magnetic_dataset(lattice, positions, types, tensors, + 0 /* tensor_rank */, num_atoms, + 0 /* is_axial */, symprec); + ASSERT_TRUE(dataset == NULL); free(rotations); free(translations); free(spin_flips); free(time_reversals); + if (dataset != NULL) spg_free_magnetic_dataset(dataset); + free(dataset); } // TODO: test get_magnetic_dataset with distorted positions From ba3b7475eb784b18652cca41e5352d69d609177e Mon Sep 17 00:00:00 2001 From: lan496 Date: Sun, 6 Nov 2022 04:29:57 +0000 Subject: [PATCH 9/9] Prepare v2.0.2 --- admin.md | 6 ++++++ doc/releases.md | 5 +++++ src/version.h | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 admin.md diff --git a/admin.md b/admin.md new file mode 100644 index 00000000..bda4f474 --- /dev/null +++ b/admin.md @@ -0,0 +1,6 @@ +# Releasing a new Spglib version + +1. Update +2. Increment version at +3. Push the commit to `rc` branch (Github actions publishes the package to TestPyPI automatically) +4. Push the commit to `master` branch (Github actions publishes the package to PyPI automatically) diff --git a/doc/releases.md b/doc/releases.md index 286bb344..f42ffebd 100644 --- a/doc/releases.md +++ b/doc/releases.md @@ -1,6 +1,11 @@ # Summary of releases +## V2.0.2 (6 Nov. 2022) + +- Fix segmentation fault in `spgms_get_symmetry_with_site_tensors` with high symprec [[#195]](https://github.com/spglib/spglib/pull/195) +- Fix possible segmentation fault in `get_magnetic_dataset` with high symprec [[#196]](https://github.com/spglib/spglib/pull/196) + ## V2.0.1 (31 Aug. 2022) - Fix magnetic tolerance for judging type-II MSG (#187) diff --git a/src/version.h b/src/version.h index be19feb9..8fea6952 100644 --- a/src/version.h +++ b/src/version.h @@ -37,6 +37,6 @@ #define SPGLIB_MAJOR_VERSION 2 #define SPGLIB_MINOR_VERSION 0 -#define SPGLIB_MICRO_VERSION 1 +#define SPGLIB_MICRO_VERSION 2 #endif