# Section: Optimizer
convergence_parameters = {}
{% if optimizer.convergence_parameters %}
    {% for key, value in optimizer.convergence_parameters.items() %}
convergence_parameters['{{ key }}'] = {{ value|render_python }}
    {% endfor %}
{% endif %}

optimizer_start = time.perf_counter()
optimizer = mean_field.Gradients().optimizer(solver='{{ optimizer.solver }}')

try:
    optimizer_run = optimizer.kernel(convergence_parameters)
except RuntimeError:
    results['optimizer'] = {
        'is_converged': False
    }
else:
    results['optimizer'] = {
        'is_converged': True,
        'optimized_coordinates': optimizer_run.atom_coords().tolist(),
    }

results['timings']['optimizer'] = time.perf_counter() - optimizer_start
