XanaduAI / strawberryfields

Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
https://strawberryfields.ai
Apache License 2.0
747 stars 186 forks source link

Fixes the QNN example to use a safe absolute value function for multiple modes #589

Closed antalszava closed 3 years ago

antalszava commented 3 years ago

Context

When increasing the number of modes in the examples/quantum_neural_network.py file containing the QNN tutorial (e.g., having modes=2), the gradient containsnanvalues and the optimization will continue using tensors filled withnan` values.

Changes

For computing the fidelity of the difference between the measured ket and the target state, a safe absolute value function is being used. This function allows ensuring that the gradient for getting the absolute value at the 0.0 point will return 0.0.

Related issues

Closes #588

codecov[bot] commented 3 years ago

Codecov Report

Merging #589 (f416ea0) into master (df29b08) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #589   +/-   ##
=======================================
  Coverage   98.42%   98.42%           
=======================================
  Files          75       75           
  Lines        8608     8608           
=======================================
  Hits         8472     8472           
  Misses        136      136           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update df29b08...f416ea0. Read the comment docs.