Skip to content

Commit

Permalink
Simplify convergence strategies (#821)
Browse files Browse the repository at this point in the history
* Remove support for specific convergence strategy

* Update schema, remove specific convergence strategy

* Add stop_if_converged property

* Add support for stop_if_converged in simulation

* Reintroduce support for lock_t_inner_cycles

* Fix use of convergence_strategy.fraction

* Remove damping_constant and threshold from schema

* Update parsing of convergence strategy

* remove the addition of unused properties to t_rad, t_inner and w

* Fix issues in montecarlo schema

* Add custom convergence strategy, damped as default

* Add check for convergence_strategy type

* Update test files to work with new convergence
  • Loading branch information
unoebauer authored and wkerzendorf committed Jun 27, 2018
1 parent d546c95 commit ae09381
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 140 deletions.
18 changes: 12 additions & 6 deletions tardis/io/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def parse_convergence_section(convergence_section_dict):
dictionary
"""


convergence_parameters = ['damping_constant', 'threshold', 'fraction',
'hold_iterations']
convergence_parameters = ['damping_constant', 'threshold']

for convergence_variable in ['t_inner', 't_rad', 'w']:
if convergence_variable not in convergence_section_dict:
Expand Down Expand Up @@ -260,9 +258,17 @@ def from_config_dict(cls, config_dict, validate=True, config_dirname=''):
validated_config_dict['config_dirname'] = config_dirname

montecarlo_section = validated_config_dict['montecarlo']
montecarlo_section['convergence_strategy'] = (
parse_convergence_section(
montecarlo_section['convergence_strategy']))
if montecarlo_section['convergence_strategy']['type'] == "damped":
montecarlo_section['convergence_strategy'] = (
parse_convergence_section(
montecarlo_section['convergence_strategy']))
elif montecarlo_section['convergence_strategy']['type'] == "custom":
raise NotImplementedError(
'convergence_strategy is set to "custom"; '
'you need to implement your specific convergence treatment')
else:
raise ValueError('convergence_strategy is not "damped" '
'or "custom"')

return cls(validated_config_dict)

Expand Down
107 changes: 32 additions & 75 deletions tardis/io/schemas/montecarlo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ properties:
convergence_strategy:
oneOf:
- $ref: '#/definitions/convergence_strategy/damped'
- $ref: '#/definitions/convergence_strategy/specific'
- $ref: '#/definitions/convergence_strategy/custom'
default:
type: 'damped'
required:
Expand All @@ -88,75 +88,17 @@ definitions:
type: object
additionalProperties: false
properties:
type:
enum:
- damped
damping_constant:
type: number
default: 0.5
description: damping constant
t_inner:
type: object
additionalProperties: false
properties:
damping_constant:
type: number
default: 0.5
description: damping constant
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
t_rad:
type: object
additionalProperties: false
properties:
damping_constant:
type: number
default: 0.5
description: damping constant
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
required:
- threshold
w:
type: object
additionalProperties: false
properties:
damping_constant:
type: number
default: 0.5
description: damping constant
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
required:
- threshold
lock_t_inner_cycles:
type: number
multipleOf: 1.0
default: 1
description: The number of cycles to lock the update of the inner boundary
temperature. This process helps with convergence. The default is to switch
it off (1 cycle)
t_inner_update_exponent:
type: number
default: -0.5
description: L=4*pi*r**2*T^y
specific:
type: object
additionalProperties: false
properties:
type:
enum:
- specific
threshold:
type: number
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
- damped
default: damped
stop_if_converged:
type: boolean
default: false
description: stop plasma iterations before number of specified
iterations are reached if the simulation is plasma and inner
boundary state is converged
fraction:
type: number
default: 0.8
Expand All @@ -169,6 +111,15 @@ definitions:
default: 3
description: the number of iterations that the convergence criteria need
to be fulfilled before TARDIS accepts the simulation as converged
damping_constant:
type: number
default: 1.0
description: damping constant
threshold:
type: number
default: 0.05
description: specifies the threshold that is taken as convergence (i.e.
0.05 means that the value does not change more than 5%)
t_inner:
type: object
additionalProperties: false
Expand Down Expand Up @@ -216,15 +167,21 @@ definitions:
description: The number of cycles to lock the update of the inner boundary
temperature. This process helps with convergence. The default is to switch
it off (1 cycle)
damping_constant:
type: number
default: 0.5
description: damping constant
t_inner_update_exponent:
type: number
default: -0.5
description: L=4*pi*r**2*T^y
required:
- threshold
- fraction
- hold_iterations
custom:
type: object
additionalProperties: false
properties:
type:
enum:
- custom
description: Use this convergence_strategy for your specific needs. You
need to change the codebase accordingly
required:
- fraction
- damping_constant
- threshold
- hold_iterations
21 changes: 4 additions & 17 deletions tardis/io/tests/data/tardis_configv1_ascii_density_abund.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ supernova:
atom_data: kurucz_atom_pure_simple.h5

model:

structure:
type: file
filename: density.dat
Expand All @@ -35,7 +35,7 @@ montecarlo:
seed: 23111963
no_of_packets : 1.0e+5
iterations: 20

black_body_sampling:
start: 1 angstrom
stop: 1000000 angstrom
Expand All @@ -44,28 +44,15 @@ montecarlo:
no_of_virtual_packets: 5

convergence_strategy:
type: specific
type: damped
damping_constant: 1.0
threshold: 0.05
fraction: 0.8
hold_iterations: 3
t_inner:
damping_constant: 1.0

spectrum:
start : 500 angstrom
stop : 20000 angstrom
num: 10000













2 changes: 1 addition & 1 deletion tardis/io/tests/data/tardis_configv1_uniform_density.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ montecarlo:
no_of_virtual_packets: 10

convergence_strategy:
type: specific
type: damped
damping_constant: 1.0
threshold: 0.05
fraction: 0.8
Expand Down
6 changes: 6 additions & 0 deletions tardis/io/tests/data/tardis_configv1_verysimple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ montecarlo:
iterations: 5
last_no_of_packets: 5.0e+5
no_of_virtual_packets: 5
convergence_strategy:
type: damped
damping_constant: 0.5
threshold: 0.05
lock_t_inner_cycles: 1
t_inner_update_exponent: -0.5

spectrum:
start: 500 angstrom
Expand Down
6 changes: 6 additions & 0 deletions tardis/plasma/tests/data/plasma_test_config_lte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ montecarlo:
iterations: 10
last_no_of_packets: 1.0e+5
no_of_virtual_packets: 5
convergence_strategy:
type: damped
damping_constant: 0.5
threshold: 0.05
lock_t_inner_cycles: 1
t_inner_update_exponent: -0.5

spectrum:
start: 500 angstrom
Expand Down
6 changes: 6 additions & 0 deletions tardis/plasma/tests/data/plasma_test_config_nlte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ montecarlo:
iterations: 10
last_no_of_packets: 1.0e+5
no_of_virtual_packets: 5
convergence_strategy:
type: damped
damping_constant: 0.5
threshold: 0.05
lock_t_inner_cycles: 1
t_inner_update_exponent: -0.5

spectrum:
start: 500 angstrom
Expand Down
Loading

0 comments on commit ae09381

Please sign in to comment.