# Buggy code
def dagger(self, inv_dict=None, suffix="-INV"):
    """
    Creates the conjugate transpose of the Quil program. The program must not
    contain any irreversible actions (measurement, control flow, qubit allocation).

    :return: The Quil program's inverse
    :rtype: Program

    """
    if not self.is_protoquil():
        raise ValueError("Program must be valid Protoquil")

    daggered = Program()

    for gate in self._defined_gates:
        if inv_dict is None or gate.name not in inv_dict:
            daggered.defgate(gate.name + suffix, gate.matrix.T.conj())

    for gate in reversed(self._instructions):
        if gate.name in STANDARD_GATES:
            if gate.name == "S":
                daggered.inst(STANDARD_GATES["PHASE"](-pi / 2, *gate.qubits))
            elif gate.name == "T":
                daggered.inst(STANDARD_GATES["RZ"](pi / 4, *gate.qubits))
            elif gate.name == "ISWAP":
                daggered.inst(STANDARD_GATES["PSWAP"](pi / 2, *gate.qubits))
            else:
                negated_params = list(map(lambda x: -1 * x, gate.params))
                daggered.inst(
                    STANDARD_GATES[gate.name](*(negated_params + gate.qubits))
                )
        else:
            if inv_dict is None or gate.name not in inv_dict:
                gate_inv_name = gate.name + suffix
            else:
                gate_inv_name = inv_dict[gate.name]

            daggered.inst(tuple([gate_inv_name] + gate.qubits))

    return daggered


# Traceback (QVMError)
DEFGATE CRY(%theta):
1, 0, 0, 0
0, 1, 0, 0
0, 0, cos(%theta/2), -1*sin(%theta/2)
0, 0, sin(%theta/2), cos(%theta/2)

CRY(0) 0 1
CRY-INV 0 1

---------------------------------------------------------------------------
QVMError                                  Traceback (most recent call last)
<ipython-input-2-83481f00619d> in <module>()
24 )
25 print(prog)
---> 26 qvm.run(prog, [0])

~/code/pyquil/pyquil/api/qvm.py in run(self, quil_program, classical_addresses, trials)
101         else:
102             payload = self._run_payload(quil_program, classical_addresses, trials)
--> 103             response = post_json(self.session, self.sync_endpoint + "/qvm", payload)
104             return response.json()
105

~/code/pyquil/pyquil/api/_base_connection.py in post_json(session, url, json)
79     res = session.post(url, json=json)
80     if res.status_code >= 400:
---> 81         raise parse_error(res)
82     return res
83

QVMError: There is no primary method for the generic function
#<STANDARD-GENERIC-FUNCTION QVM:TRANSITION (27)>
when called with arguments
(#<QVM-APP::PROFILED-PURE-STATE-QVM {1008732163}>
#<CL-QUIL:UNRESOLVED-APPLICATION {1008730AD3}>).
See also:
The ANSI Standard, Section 7.6.6.2

The QVM returned the above error. This could be due to a bug in the server or a
bug in your code. If you suspect this to be a bug in pyQuil or Rigetti Forest,
then please describe the problem in a GitHub issue at:
https://github.com/rigetticomputing/pyquil/issues

# Fixed code
def dagger(self, inv_dict=None, suffix="-INV"):
    """
    Creates the conjugate transpose of the Quil program. The program must not
    contain any irreversible actions (measurement, control flow, qubit allocation).

    :return: The Quil program's inverse
    :rtype: Program

    """
    if not self.is_protoquil():
        raise ValueError("Program must be valid Protoquil")

    daggered = Program()

    for gate in self._defined_gates:
        if inv_dict is None or gate.name not in inv_dict:
            if gate.parameters:
                raise TypeError(
                    "Cannot auto define daggered version of parameterized gates"
                )
            daggered.defgate(gate.name + suffix, gate.matrix.T.conj())

    for gate in reversed(self._instructions):
        if gate.name in STANDARD_GATES:
            if gate.name == "S":
                daggered.inst(STANDARD_GATES["PHASE"](-pi / 2, *gate.qubits))
            elif gate.name == "T":
                daggered.inst(STANDARD_GATES["RZ"](pi / 4, *gate.qubits))
            elif gate.name == "ISWAP":
                daggered.inst(STANDARD_GATES["PSWAP"](pi / 2, *gate.qubits))
            else:
                negated_params = list(map(lambda x: -1 * x, gate.params))
                daggered.inst(
                    STANDARD_GATES[gate.name](*(negated_params + gate.qubits))
                )
        else:
            if inv_dict is None or gate.name not in inv_dict:
                gate_inv_name = gate.name + suffix
            else:
                gate_inv_name = inv_dict[gate.name]

            daggered.inst(Gate(gate_inv_name, gate.params, gate.qubits))

    return daggered