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

The default dtype of np.complex64 for the DensityMatrixSimulator is not precise enough for relatively small circuits. #6551

Open
bramathon opened this issue Apr 5, 2024 · 1 comment
Labels
kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@bramathon
Copy link
Contributor

Description of the issue

How to reproduce the issue

Use the example circuit:
example-circuit.json

import cirq

with open("example-circuit.json", "r") as f:
    circuit = cirq.read_json(f)

simulator = cirq.DensityMatrixSimulator(dtype=np.complex64, noise=None, seed=None, split_untangled_states=True)
obs = cirq.PauliString(cirq.X(cirq.LineQubit(28)), cirq.X(cirq.LineQubit(29)))
simulator.simulate_expectation_values(program=circuit, observables=obs)

Now, if we change the dtype to np.complex128, the error goes away.

Suggested solution: set the default value of dtype to np.complex128 or np.complex256

1018 raise ValueError(f'Density matrix does not have trace 1. Instead, it has trace {trace}.')
1019 if not np.all(np.linalg.eigvalsh(density_matrix) > -atol):
-> 1020 raise ValueError('The density matrix is not positive semidefinite.')

ValueError: The density matrix is not positive semidefinite.

Cirq version
1.3.0

@bramathon bramathon added the kind/bug-report Something doesn't seem to work. label Apr 5, 2024
@bramathon bramathon changed the title The default dtype of np.complex64 for the DensityMatrixSimulator fails for relatively small circuits. The default dtype of np.complex64 for the DensityMatrixSimulator is not precise enough for relatively small circuits. Apr 5, 2024
@verult verult added the triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add label Apr 10, 2024
@pavoljuhas
Copy link
Collaborator

csynkque meeting - this works as intended, but the error message can be improved to suggest using a higher precision complex128 type. Another consideration is to expose a tolerance atol argument which would allow higher round-offs for complex64 data type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

No branches or pull requests

3 participants