Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions qontrol/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ def step(
print(costs, cost_values[0])

# Save logic
save_period = opt_options['save_period']
if filepath is not None and epoch > 0 and epoch % save_period == 0:
if (
filepath is not None
and epoch > 0
and epoch % opt_options['save_period'] == 0
):
_save(
cost_values_over_epochs,
total_cost_over_epochs,
Expand All @@ -188,6 +191,7 @@ def step(
)
last_save_epoch = epoch
parameters_since_last_save = _init_saved_parameters(parameters)

# Plot the cost values as well as other desired quantities
if (
opt_options['plot']
Expand All @@ -212,6 +216,7 @@ def step(
)
if termination_key != -1:
break
previous_parameters = parameters

except KeyboardInterrupt:
pass
Expand Down Expand Up @@ -261,8 +266,7 @@ def loss(
) -> [float, Array]:
result, H = model(parameters, method, gradient, dq_options)
cost_values, terminate = zip(*costs(result, H, parameters), strict=True)
total_cost = jax.tree.reduce(jnp.add, cost_values)
total_cost = jnp.log(jnp.sum(jnp.asarray(total_cost)))
total_cost = jnp.log(jax.tree.reduce(jnp.add, cost_values))
expects = result.expects if hasattr(result, 'expects') else None
return total_cost, (total_cost, cost_values, terminate, expects)

Expand Down