In pyquil 3, the unitary of a defined gate is determined by it's DefGate. However, in pyquil 4, in some cases the unitary is determined by it's Defcal. I believe this is a bug - the DefGate should take precedence.
Code Snippet
import numpy as np
import pyquil
from pyquil.quil import Program
from pyquil.gates import RX
from pyquil.api import WavefunctionSimulator
from pyquil.quilbase import DefCalibration, DefGate
from pyquil.quilatom import Qubit, Parameter, quil_cos, quil_sin
print(f"Pyquil version: {pyquil.__version__}")
phi = Parameter("phi")
mat = np.array(
[
[0.0, 1.0],
[1.0, 0.0],
]
)
defgate = DefGate("J", mat, parameters=[])
defcal = DefCalibration("J", parameters=[], qubits=[Qubit(0)], instrs=[RX(np.pi/2, 0)])
program = Program()
program += defgate
program += defcal # comment out this line to see the correct wavefunction
program += defgate.get_constructor()(0)
wf_sim = WavefunctionSimulator()
wavefunction = wf_sim.wavefunction(program)
np.round(wavefunction.amplitudes, 5)
In pyquil 3, the unitary of a defined gate is determined by it's
DefGate
. However, in pyquil 4, in some cases the unitary is determined by it'sDefcal
. I believe this is a bug - theDefGate
should take precedence.Code Snippet
Error Output
Pyquil 3.5.4
Pyquil 4.1.1