Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge "TRHEPD_manybeam_with_limitation" into "develop". #56

Merged
merged 68 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
874bc21
<WIP> add lib_make_convolution.py and sim_trhepd_rheed_mb_connect.py
H-Iwamoto-research Jul 20, 2023
f0cb3ee
add: solver="sim-trhepd-rheed-mb_connect" is available.
H-Iwamoto-research Jul 27, 2023
46c3880
normalization = "MS_NORM_SET_WGT" and Rfactor_type = "A" is aveilable.
H-Iwamoto-research Aug 2, 2023
fc9322f
mod : Keep the rocking curve data as "self.calc_rocking_curve".
H-Iwamoto-research Aug 13, 2023
109a33c
Only MPIrank=0 process executes _check_template.
H-Iwamoto-research Aug 26, 2023
b8cb487
Update sim-trhepd-rheed.rst
H-Iwamoto-research Sep 7, 2023
91c031b
fix : iset and LogXXX_XXX directory
H-Iwamoto-research Sep 7, 2023
29a5e27
fix errors in sim-trhepd-rheed.rst
H-Iwamoto-research Sep 8, 2023
e376f02
Removed redundant comments and debugging code.
H-Iwamoto-research Sep 10, 2023
ad1c34c
Add test data of sim_trepd_rheed_mb_connect.
H-Iwamoto-research Sep 13, 2023
655ba3b
Edited about "detail_timer"
H-Iwamoto-research Sep 13, 2023
c2c6255
Added comment of "surf_tempalte_width_for_fortran" and "bulk_out_widt…
H-Iwamoto-research Sep 13, 2023
add625a
Added comment about "emp_str".
H-Iwamoto-research Sep 13, 2023
4724feb
Get "generate_rocking_curve" in "Class Input" and "Class Output".
H-Iwamoto-research Sep 14, 2023
499b10a
Rename the file from RockingCurve.txt to RockingCurve_calculated.txt
H-Iwamoto-research Sep 18, 2023
976feb1
Change in operation to remove headers in computed data files.
H-Iwamoto-research Sep 20, 2023
3755365
delete 'RC_data_cnv' in sim_trhepd_rheed_mb_connect.py
H-Iwamoto-research Sep 20, 2023
5e1a921
Modification of the reference data (= experiment data) reading section.
H-Iwamoto-research Sep 26, 2023
168da7d
"limitation" is available.
H-Iwamoto-research Sep 28, 2023
8ef6af7
Merge branch 'limitation' into TRHEPD_manybeam_with_limitation
H-Iwamoto-research Sep 28, 2023
db51b93
Modification of the calculate data reading section.
H-Iwamoto-research Oct 3, 2023
4147260
delete row_number
H-Iwamoto-research Oct 4, 2023
2a55492
delete degree_max and degree_list
H-Iwamoto-research Oct 4, 2023
fd8fcc5
Rename the variable "self.log_mode" to "self.isLogmode".
H-Iwamoto-research Oct 4, 2023
dc462c1
Calculate "angle_interval" in the "for" loop of the convolution calcu…
H-Iwamoto-research Oct 4, 2023
8c4a416
normalization == "MAX" is disabled.
H-Iwamoto-research Oct 4, 2023
6b95b24
Changes to R-factor calculation and normalization.
H-Iwamoto-research Oct 12, 2023
21d9643
Changes related to RockingCurve_calculated.txt.
H-Iwamoto-research Oct 12, 2023
8f3a9e0
Renewal of normalization options
H-Iwamoto-research Oct 12, 2023
5e13d6f
Merge branch 'TRHEPD_manybeam' into TRHEPD_manybeam_with_limitation
H-Iwamoto-research Oct 13, 2023
d368b93
change solver name
H-Iwamoto-research Oct 14, 2023
d827956
Merge branch 'TRHEPD_manybeam' into TRHEPD_manybeam_with_limitation
H-Iwamoto-research Oct 14, 2023
1f91598
delete sim_trhepd_rheed_mb_connect.py
H-Iwamoto-research Oct 14, 2023
3d85410
delete sim_trhepd_rheed_mb_connect.py
H-Iwamoto-research Oct 14, 2023
4e7c966
Edited about self.Rfactor_type="B".
H-Iwamoto-research Oct 14, 2023
771511e
Minor changes to RockingCurve_calculated.txt
H-Iwamoto-research Oct 14, 2023
85f47ad
Delete unused function "_g"
H-Iwamoto-research Oct 14, 2023
f65713c
Removed redundant comments.
H-Iwamoto-research Oct 14, 2023
2dc0040
Merge branch 'TRHEPD_manybeam' into TRHEPD_manybeam_with_limitation
H-Iwamoto-research Oct 15, 2023
b59a903
Change of limitation on montecarlo
H-Iwamoto-research Oct 17, 2023
1d268cf
Change of limitation on minsearch.
H-Iwamoto-research Oct 17, 2023
830b7ec
Merge branch 'limitation' into TRHEPD_manybeam_with_limitation
H-Iwamoto-research Oct 17, 2023
96d2708
Add limitation section
H-Iwamoto-research Oct 30, 2023
a7019bb
bug fix
H-Iwamoto-research Oct 30, 2023
605f16b
Added sample of limitaiton
H-Iwamoto-research Oct 31, 2023
656c2e8
Rename best_result.txt -> ref.txt (in sample/analytical/limitation)
H-Iwamoto-research Oct 31, 2023
d8373e7
fix input.toml
H-Iwamoto-research Oct 31, 2023
980e7a3
Add file
H-Iwamoto-research Nov 1, 2023
9982dd0
Add tutorial of limitation
H-Iwamoto-research Nov 1, 2023
0afb0e6
normalization = "MULTI_SPOT" -> normalization = "MANY_BEAM"
H-Iwamoto-research Nov 3, 2023
d4a2650
Merge remote-tracking branch 'TRHEPD_manybeam' into TRHEPD_manybeam_w…
H-Iwamoto-research Nov 3, 2023
e092320
update document
H-Iwamoto-research Nov 11, 2023
63980bc
add comment
H-Iwamoto-research Nov 11, 2023
9e5ac83
add TypeHint
H-Iwamoto-research Nov 11, 2023
5c34d84
Adjustment of variable types
H-Iwamoto-research Nov 12, 2023
70c842b
Adjustment of variable types
H-Iwamoto-research Nov 12, 2023
b149b23
Slight adjustments to the document
H-Iwamoto-research Nov 13, 2023
da11583
Merge remote-tracking branch 'origin/TRHEPD_manybeam' into TRHEPD_man…
H-Iwamoto-research Nov 13, 2023
d2675f1
Merge remote-tracking branch 'origin/limitation' into TRHEPD_manybeam…
H-Iwamoto-research Nov 13, 2023
d2c927b
reformat
yomichi Feb 22, 2024
14846c5
update docs
yomichi Feb 22, 2024
3366b6b
update samples
yomichi Feb 28, 2024
3aecea4
update error messages
yomichi Feb 28, 2024
0fbcf9c
set run_scheme=subprocess as default for sim-trhepd-rheed
yomichi Mar 13, 2024
0b2014e
move STR manybeam samples
yomichi Mar 13, 2024
3c36082
fix script
yomichi Mar 13, 2024
b17831d
update tutorials (fix file paths)
yomichi Mar 13, 2024
d65ba59
update samples
yomichi Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/common/img/limitation_beta_max.pdf
Binary file not shown.
Binary file added doc/common/img/limitation_beta_max.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/common/img/limitation_beta_min.pdf
Binary file not shown.
Binary file added doc/common/img/limitation_beta_min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions doc/en/source/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ The input file consists of the following six sections.

- Define the mapping from a parameter searched by ``Algorithm`` .

- ``limitation``

- Define the limitation (constration) of parameter searched by ``Algorithm`` .

- ``log``

- Specify parameters related to logging of solver calls.
Expand Down Expand Up @@ -157,6 +161,52 @@ mean
\end{matrix}
\right).


[``limitation``] section
*************************

This section defines the limitation (constraint) in an :math:`N` dimensional parameter searched by ``Algorithm``, :math:`x`, in addition of ``min_list`` and ``max_list``.

In the current version, a linear inequation with the form :math:`Ax+b>0` is available.

- ``co_a``

Format: List of list of float, or a string (default: ``[]``)

Description: :math:`N \times M` matrix :math:`A`. An empty list ``[]`` is a shorthand of an identity matrix.
If you want to set it by a string, arrange the elements of the matrix separated with spaces and newlines (see the example).


- ``co_b``

Format: List of float, or a string (default: ``[]``)

Description: :math:`M` dimensional vector :math:`b`. An empty list ``[]`` is a shorthand of a zero vector.
If you want to set it by a string, arrange the elements of the vector separated with spaces.

For example, both ::

A = [[1,1], [0,1]]

and ::

A = """
1 1
0 1
"""

mean

.. math::

A = \left(
\begin{matrix}
1 & 1 \\
0 & 1
\end{matrix}
\right).


[``log``] section
************************

Expand Down
205 changes: 155 additions & 50 deletions doc/en/source/solver/sim-trhepd-rheed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ The ``surf.exe`` is called from ``py2dmat``.
Input parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Input parameters can be specified in subcsections ``config``, ``post``, ``param``, ``reference`` in ``solver`` section.
Input parameters can be specified in subsections ``config``, ``post``, ``param``, ``reference`` in ``solver`` section.

[``config``] section
[``solver``] section
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- ``generate_rocking_curve``

Format: boolean (default: false)

Description: Whether to generate ``RockingCurve_calculated.txt``.
If ``true``, ``RockingCurve_calculated.txt`` will be generated in the working directory ``Log%%%_###``.
Note that if ``remove_work_dir`` (in [``post``] subsection) is ``true``, ``Log%%%_###`` will be removed.

[``solver.config``] subsection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``surface_exec_file``

Expand Down Expand Up @@ -60,30 +70,94 @@ Input parameters can be specified in subcsections ``config``, ``post``, ``param`

Description: One of the parameters that specifies the range of output files to be read, calculated by the solver. This parameter specifies the last line to be read.

- ``row_number``
- ``calculated_info_line``

Format: integer (default: 8)
Format: integer (default: 2)

Description: One of the parameters that specifies the range of output files to be read, calculated by the solver. This parameter specifies the column to be read.
Description: One of the parameters that specifies the range of output files to be read, calculated by the solver.
This parameter specifies the line to be read, which contains the number of glancing angles (second column) and the number of beams (third column).

- ``cal_number``

[``post``] section
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Format: List of integers

- ``normalization``
Description: Columns of dataset to be read. Multiple columns can be specified (many-beam condition).

Format: string ("TOTAL" or "MAX", default: "TOTAL")

Description: This parameter specifies whether the experimental and computational data vectors are normalized by the sum of the whole values or by the maximum value.
[``solver.post``] subsection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This subsection is used to the postprocess -- to specify how to calculate the objective function, that is, the deviation between the experimental and computational data, and to draw the rocking curve.

- ``Rfactor_type``

Format: string ("A" or "B", default: "A")

Description: This parameter specifies how to calculate the R-factor.
The experimental and computational data vectors are denoted as :math:`u = (u_{1}, u_{2},...,u_{m})`,
:math:`v = (v_{1}, v_{2},...,v_{m})`, respectively.
When "A" type is chosen, R-factor is defined as :math:`R = (\sum_i^m (u_{i}-v_{i})^{2})^{1/2}`.
When "B" type is chosen, R-factor is defined as :math:`R = (\sum_i^m (u_{i}-v_{i})^{2})^{1/2}/( \sum_i^m u_{i}^2 + \sum_i^m v_{i}^2)`.
Description: This parameter specifies how to calculate the R-factor to be minimized.
Let :math:`n` be the number of dataset, :math:`m` be the number of glancing angles, and :math:`v^{(n)} = (v^{(n)}_{1}, v^{(n)}_{2}, \dots ,v^{(n)}_{m})` be the calculated data.
With the weights of the beams, :math:`w^{(j)}`, R-factors is defined as follows:

- "A" type:

.. math::

R = \sqrt{ \sum_{j}^{n} w^{(j)} \sum_{i}^{m} \left(u^{(j)}_{i}-v^{(j)}_{i}\right)^{2} }

- "A2" type:

.. math::

R^{2} = \sum_{j}^{n} w^{(j)} \sum_{i}^{m} \left(u^{(j)}_{i}-v^{(j)}_{i}\right)^{2}

- "B" type:

.. math::

R = \frac{\sum_{i}^{m} \left(u^{(1)}_{i}-v^{(1)}_{i}\right)^{2}}{\sum_{i}^{m} \left(u^{(1)}_{i}\right)^{2} + \sum_{i}^{m} (v^{(1)}_{i})^2}

- "B" type is available only for the single dataset (:math:`n=1`).


- ``normalization``

Format: string ("TOTAL" or "MANY_BEAM")

Description: This parameter specifies how to normalize the experimental and computational data vectors.

- "TOTAL"

- To normalize the data as the summation is 1.
- The number of dataset should be one (the number of ``cal_number`` should be one).

- "MANY_BEAM"

- To normalize with weights as specified by ``weight_type``.

**NOTE: "MAX" is no longer available**

- ``weight_type``

Format: string or ``None``. "calc" or "manual" (default: ``None``)

Description: The weights of the datasets for the "MANY_BEAM" normalization.

- "calc"

.. math::

w^{(n)} = \left(\frac{\sum_i^m v^{(n)}_{i}}{\sum_j^n \sum_i^m v^{(j)}_i} \right)^2

- "manual"

:math:`w^{(n)}` is specified by ``spot_weight``.

- ``spot_weight``

Format: list of float (mandatory when ``weight_type`` is "manual")

Description: The weights of the beams in the calculation of R-factor.
The weights are automatically normalized as the sum be 1.
For example, [3,2,1] means :math:`w^{(1)}=1/2, w^{(2)}=1/3, w^{(3)}=1/6`.

- ``omega``

Expand All @@ -95,9 +169,9 @@ Input parameters can be specified in subcsections ``config``, ``post``, ``param`

Format: boolean (default: false)

Description: Whether to remove working directories after reading R-factor or not
Description: Whether to remove working directories ``Log%%%_###`` after reading R-factor or not

[``param``] section
[``solver.param``] subsection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``string_list``
Expand All @@ -106,33 +180,34 @@ Input parameters can be specified in subcsections ``config``, ``post``, ``param`

Description: List of placeholders to be used in the reference template file to create the input file for the solver. These strings will be replaced with the values of the parameters being searched for.

- ``degree_max``

Format: float (default: 6.0)

Description: Maximum angle (in degrees)

[``reference``] section
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[``solver.reference``] subsection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``path``

Format: string (default: ``experiment.txt``)

Description: Path to the experimental data file.

- ``first``
- ``reference_first_line``

Format: integer (default: 1)

Description: One of the parameters that specify the range of experimental data files to be read. This parameter specifies the first line of the experimental file to be read.

- ``last``
- ``reference_last_line``

Format: integer (default: 56)

Description: One of the parameters that specify the range of experimental data files to be read. This parameter specifies the last line of the experimental file to be read.

- ``exp_number``

Format: List of integers

Description: Columns of dataset to be read. Multiple columns can be specified (many-beam condition).


Reference file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -169,21 +244,22 @@ In this case, ``value_01``, ``value_02``, and ``value_03`` are the parameters to
Target file
^^^^^^^^^^^^^^
This file (``experiment.txt``) contains the data to be targeted.
The first column contains the angle, and the second column contains the calculated value of the reflection intensity multiplied by the weight.
The first column contains the angle, and the second and following columns contain the calculated value of the reflection intensity multiplied by the weight.
An example of the file is shown below.

.. code-block::

0.100000 0.002374995
0.200000 0.003614789
0.300000 0.005023215
0.400000 0.006504978
0.500000 0.007990674
0.600000 0.009441623
0.700000 0.010839445
0.800000 0.012174578
0.900000 0.013439485
1.000000 0.014625579
3.00000e-01 8.17149e-03 1.03057e-05 8.88164e-15 ...
4.00000e-01 1.13871e-02 4.01611e-05 2.23952e-13 ...
5.00000e-01 1.44044e-02 1.29668e-04 4.53633e-12 ...
6.00000e-01 1.68659e-02 3.49471e-04 7.38656e-11 ...
7.00000e-01 1.85375e-02 7.93037e-04 9.67719e-10 ...
8.00000e-01 1.93113e-02 1.52987e-03 1.02117e-08 ...
9.00000e-01 1.92590e-02 2.53448e-03 8.69136e-08 ...
1.00000e+00 1.86780e-02 3.64176e-03 5.97661e-07 ...
1.10000e+00 1.80255e-02 4.57932e-03 3.32760e-06 ...
1.20000e+00 1.77339e-02 5.07634e-03 1.50410e-05 ...
1.30000e+00 1.80264e-02 4.99008e-03 5.53791e-05 ...
...


Expand All @@ -210,20 +286,49 @@ An example is shown below.
output-filename :
surf-bulkP.s

``RockingCurve.txt``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``RockingCurve_calculated.txt``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This file is located in the ``Log%%%%%_#####`` folder.
The first line is the header, and the second and subsequent lines are the angle, convoluted calculated/experimental values, normalized calculated/experimental values, and raw calculated values in that order.
An example is shown below.
At the beginning of the file, the lines beginning with ``#`` are headers.
The header contains the values of the input variables, the objective function value ``f(x)``, the parameters ``Rfactor_type``, ``normalization``, ``weight_type``, ``cal_number``, ``spot_weight``, and what is marked in the data portion columns (e.g. ``# #0 glancing_angle``).

The header is followed by the data.
The first column shows the glancing angle, and the second and subsequent columns show the intensity of each data column.
You can see which data columns are marked in the header. For example,

.. code-block::

#degree convolution_I_calculated I_experiment convolution_I_calculated(normalized) I_experiment(normalized) I_calculated
0.1 0.0023816127859192407 0.002374995 0.004354402952499057 0.005364578226620574 0.001722
0.2 0.003626530149456865 0.003614789 0.006630537795012198 0.008164993342397588 0.003397
0.3 0.00504226607469267 0.005023215 0.009218987407498791 0.011346310125551366 0.005026
0.4 0.006533558304296079 0.006504978 0.011945579793136154 0.01469327865677437 0.006607
0.5 0.00803056955158873 0.007990674 0.014682628499657693 0.018049130948243314 0.008139
0.6 0.009493271317558538 0.009441623 0.017356947736613827 0.021326497600946535 0.00962
0.7 0.010899633015118851 0.010839445 0.019928258053867838 0.024483862338931763 0.01105
...
# #0 glancing_angle
# #1 cal_number=1
# #2 cal_number=2
# #3 cal_number=4

shows that the first column is the glancing angle, and the second, third, and fourth columns are the calculated data corresponding to the first, second, and fourth columns of the calculated data file, respectively.

Intencities in each column are normalized so that the sum of the intensity is 1.
To calculate the objective function value (R-factor and R-factor squared), the data columns are weighted by ``spot_weight`` and normalized by ``normalization``.

.. code-block::

#value_01 = 0.00000 value_02 = 0.00000
#Rfactor_type = A
#normalization = MANY_BEAM
#weight_type = manual
#fx(x) = 0.03686180462340505
#cal_number = [1, 2, 4, 6, 8]
#spot_weight = [0.933 0.026 0.036 0.003 0.002]
#NOTICE : Intensities are NOT multiplied by spot_weight.
#The intensity I_(spot) for each spot is normalized as in the following equation.
#sum( I_(spot) ) = 1
#
# #0 glancing_angle
# #1 cal_number=1
# #2 cal_number=2
# #3 cal_number=4
# #4 cal_number=6
# #5 cal_number=8
0.30000 1.278160358686800e-02 1.378767858296659e-04 8.396046839668212e-14 1.342648818357391e-30 6.697979700048016e-53
0.40000 1.778953628930054e-02 5.281839702773564e-04 2.108814173486245e-12 2.467220122612354e-28 7.252675318478533e-50
0.50000 2.247181148723425e-02 1.671115124520428e-03 4.250758278908295e-11 3.632860054842994e-26 6.291667506376419e-47
...

12 changes: 6 additions & 6 deletions doc/en/source/tutorial/bayes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This tutorial subscribes how to estimate atomic positions from the experimental
Sample files
~~~~~~~~~~~~~~~~~~~~~~~~

Sample files are available from ``sample/sim-trhepd-rheed/bayes`` .
Sample files are available from ``sample/sim-trhepd-rheed/single_beam/bayes`` .
This directory includes the following files:

- ``bulk.txt``
Expand Down Expand Up @@ -123,14 +123,14 @@ First, move to the folder where the sample file is located (hereinafter, it is a

.. code-block::

cd sample/sim-trhepd-rheed/bayes
cd sample/sim-trhepd-rheed/single_beam/bayes

Copy ``bulk.exe`` and ``surf.exe`` as the tutorial for the direct problem.

.. code-block::

cp ../../../../sim-trhepd-rheed/src/TRHEPD/bulk.exe .
cp ../../../../sim-trhepd-rheed/src/TRHEPD/surf.exe .
cp ../../../../../sim-trhepd-rheed/src/TRHEPD/bulk.exe .
cp ../../../../../sim-trhepd-rheed/src/TRHEPD/surf.exe .

Execute ``bulk.exe`` to generate ``bulkP.b`` .

Expand All @@ -142,7 +142,7 @@ Then, run the main program (it takes a few secondes)

.. code-block::

python3 ../../../src/py2dmat_main.py input.toml | tee log.txt
python3 ../../../../src/py2dmat_main.py input.toml | tee log.txt

This makes a directory with the name of ``0`` .
The following standard output will be shown:
Expand Down Expand Up @@ -216,7 +216,7 @@ I will omit the explanation below, but I will post the contents.

./bulk.exe

time python3 ../../../src/py2dmat_main.py input.toml
time python3 ../../../../src/py2dmat_main.py input.toml

echo diff BayesData.txt ref_BayesData.txt
res=0
Expand Down
Loading
Loading