code: def _defgate(self, program, gate_name, gate_matrix):
          
          new_program = pq.Program()
          new_program += program
          if gate_name not in self.defined_gates:
              new_program.defgate(gate_name, gate_matrix)
              self.defined_gates.add(gate_name)
          return new_program
docs: Defines a gate named gate_name with matrix gate_matrix in program. In addition, updates
           self.defined_gates to track what has been defined.
  
          :param Program program: Pyquil Program to add the defgate and gate to.
          :param str gate_name: The name of the gate to add to program.
          :param numpy.ndarray gate_matrix: The array corresponding to the gate to define.
          :return: the modified Program.
          :retype: Program