rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.4k stars 342 forks source link

Defgate matrices should be type np.complex_ #1737

Open bramathon opened 7 months ago

bramathon commented 7 months ago

Pre-Report Checklist

Issue Description

Matrices in DefGates contain complex numbers, but they are stored as objects rather than np.complex128 (or better yet np.complex256). This causes some common numpy operations such as np.real to fail.

How to Reproduce

image

import numpy as np
from pyquil.quilbase import DefGate

theta, phi = rng.random(2)*2*np.pi
defgate = DefGate(f"FSIM_{theta_deg}_{phi_deg}", matrix=matrices.FSIM(theta, phi))
defgate.matrix