def METHOD_NAME(self, params):
    """Convert the parameters of a gate into a hashable format for lookup in a dictionary.
    This aims to be fast in common cases, and is not intended to work outside of the lifetime of a
    single commutation pass; it does not handle mutable state correctly if the state is actually
    changed."""
    try:
        hash(params)
        return params
    except TypeError:
        pass
    if isinstance(params, (list, tuple)):
        return tuple(self.METHOD_NAME(x) for x in params)
    if isinstance(params, np.ndarray):
        # We trust that the arrays will not be mutated during the commutation pass, since nothing
        # would work if they were anyway. Using the id can potentially cause some additional cache
        # misses if two UnitaryGate instances are being compared that have been separately
        # constructed to have the same underlying matrix, but in practice the cost of string-ifying
        # the matrix to get a cache key is far more expensive than just doing a small matmul.
        return (np.ndarray, id(params))
    # Catch anything else with a slow conversion.
    return ("fallback", str(params))