question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: downcasting from complex in `apply_unitary`

See original GitHub issue

The following code to multiply PauliY by the identity incorrectly casts the matrix representation of PauliY into the type of the input state (float):

import cirq
import numpy as np
from cirq import protocols

y0 = cirq.PauliString({cirq.LineQubit(0): cirq.Y})
state = 0.5 * np.eye(2)
args = protocols.ApplyUnitaryArgs(target_tensor=state,
                                  available_buffer=np.zeros_like(state),
                                  axes=(0,))
result = protocols.apply_unitary(y0, args)

gives

>>> print(result)
[[0. 0.] 
[0. 0.]]

numpy correctly throws a warning about this casting, but this should really throw an error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
dabaconcommented, May 6, 2020

This feels like a case where the code should use the larger type.

0reactions
tanujkhattarcommented, Jun 22, 2022

From cirq sync: We should throw an error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found