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

denormals_are_zeros setting has unexpected side effects #666

Open
richrines1 opened this issue Jul 22, 2024 · 0 comments
Open

denormals_are_zeros setting has unexpected side effects #666

richrines1 opened this issue Jul 22, 2024 · 0 comments

Comments

@richrines1
Copy link

qsim updates global flush-to-zero and denormals-are-zero control flags, but never resets them to their original values. This can lead to unexpected changes in the behavior of downstream code, e.g.:

import cirq
import ctypes

from qsimcirq import QSimOptions, QSimSimulator


orig_value = ctypes.c_float(1e-40).value

_ = QSimSimulator(qsim_options=QSimOptions(denormals_are_zeros=False)).simulate(cirq.Circuit())

assert ctypes.c_float(1e-40).value == orig_value  # passes

_ = QSimSimulator(qsim_options=QSimOptions(denormals_are_zeros=True)).simulate(cirq.Circuit())

assert ctypes.c_float(1e-40).value == orig_value  # fails

_ = QSimSimulator().simulate(cirq.Circuit())

assert ctypes.c_float(1e-40).value == orig_value  # passes

it would be nice if these flags were reset after the simulation (ideally even if the simulation itself fails)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant