# Buggy code
def collect_1q_runs(self):
    """Return a set of non-conditional runs of 1q "op" nodes."""

    def filter_fn(node):
        return (
            node.type == "op"
            and len(node.qargs) == 1
            and len(node.cargs) == 0
            and node.condition is None
            and not node.op.is_parameterized()
        )

    group_list = rx.collect_runs(self._multi_graph, filter_fn)
    return set(tuple(x) for x in group_list)


# Traceback (qiskit.exceptions.QiskitError)
(YaelEnv) yaelbh@iris-quantum2:~/work/not_qiskit$ python snapshot_invalid.py
/home/yaelbh/work/terra/System/qiskit/__init__.py:69: RuntimeWarning: Could not import the IBMQ provider from the qiskit-ibmq-provider package. Install qiskit-ibmq-provider or check your installation.
warnings.warn('Could not import the IBMQ provider from the '
/opt/anaconda3/envs/YaelEnv/lib/python3.8/site-packages/qiskit/aqua/operators/operator_globals.py:48: DeprecationWarning: `from_label` is deprecated and will be removed no earlier than 3 months after the release date. Use Pauli(label) instead.
X = make_immutable(PrimitiveOp(Pauli.from_label('X')))
Transpilation with ['u3', 'cx'] is fine
Traceback (most recent call last):
File "snapshot_invalid.py", line 14, in <module>
transpile(circ, backend, basis_gates=['u', 'cx'])
File "/home/yaelbh/work/terra/System/qiskit/compiler/transpile.py", line 241, in transpile
circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
File "/home/yaelbh/work/terra/System/qiskit/tools/parallel.py", line 112, in parallel_map
return [task(values[0], *task_args, **task_kwargs)]
File "/home/yaelbh/work/terra/System/qiskit/compiler/transpile.py", line 324, in _transpile_circuit
result = pass_manager.run(circuit, callback=transpile_config['callback'],
File "/home/yaelbh/work/terra/System/qiskit/transpiler/passmanager.py", line 225, in run
return self._run_single_circuit(circuits, output_name, callback)
File "/home/yaelbh/work/terra/System/qiskit/transpiler/passmanager.py", line 288, in _run_single_circuit
result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
File "/home/yaelbh/work/terra/System/qiskit/transpiler/runningpassmanager.py", line 113, in run
dag = self._do_pass(pass_, dag, passset.options)
File "/home/yaelbh/work/terra/System/qiskit/transpiler/runningpassmanager.py", line 144, in _do_pass
dag = self._run_this_pass(pass_, dag)
File "/home/yaelbh/work/terra/System/qiskit/transpiler/runningpassmanager.py", line 156, in _run_this_pass
new_dag = pass_.run(dag)
File "/home/yaelbh/work/terra/System/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py", line 87, in run
operator = Operator(qc)
File "/home/yaelbh/work/terra/System/qiskit/quantum_info/operators/operator.py", line 85, in __init__
self._data = self._init_instruction(data).data
File "/home/yaelbh/work/terra/System/qiskit/quantum_info/operators/operator.py", line 496, in _init_instruction
op._append_instruction(instruction)
File "/home/yaelbh/work/terra/System/qiskit/quantum_info/operators/operator.py", line 554, in _append_instruction
self._append_instruction(instr, qargs=new_qargs)
File "/home/yaelbh/work/terra/System/qiskit/quantum_info/operators/operator.py", line 532, in _append_instruction
raise QiskitError('Cannot apply Instruction: {}'.format(obj.name))
qiskit.exceptions.QiskitError: 'Cannot apply Instruction: snapshot'

# Fixed code
def collect_1q_runs(self):
    """Return a set of non-conditional runs of 1q "op" nodes."""

    def filter_fn(node):
        return (
            node.type == "op"
            and len(node.qargs) == 1
            and len(node.cargs) == 0
            and node.condition is None
            and not node.op.is_parameterized()
            and isinstance(node.op, Gate)
            and hasattr(node.op, "__array__")
        )

    group_list = rx.collect_runs(self._multi_graph, filter_fn)
    return set(tuple(x) for x in group_list)