# Buggy code
def _experiments_to_circuits(qobj):
    """Return a list of QuantumCircuit object(s) from a qobj.

    Args:
        qobj (Qobj): The Qobj object to convert to QuantumCircuits

    Returns:
        list: A list of QuantumCircuit objects from the qobj
    """
    if qobj.experiments:
        circuits = []
        for x in qobj.experiments:
            quantum_registers = [
                QuantumRegister(i[1], name=i[0]) for i in x.header.qreg_sizes
            ]
            classical_registers = [
                ClassicalRegister(i[1], name=i[0]) for i in x.header.creg_sizes
            ]
            circuit = QuantumCircuit(
                *quantum_registers, *classical_registers, name=x.header.name
            )
            qreg_dict = collections.OrderedDict()
            creg_dict = collections.OrderedDict()
            for reg in quantum_registers:
                qreg_dict[reg.name] = reg
            for reg in classical_registers:
                creg_dict[reg.name] = reg
            conditional = {}
            for i in x.instructions:
                name = i.name
                qubits = []
                params = getattr(i, "params", [])
                try:
                    for qubit in i.qubits:
                        qubit_label = x.header.qubit_labels[qubit]
                        qubits.append(qreg_dict[qubit_label[0]][qubit_label[1]])
                except Exception:  # pylint: disable=broad-except
                    pass
                clbits = []
                try:
                    for clbit in i.memory:
                        clbit_label = x.header.clbit_labels[clbit]
                        clbits.append(creg_dict[clbit_label[0]][clbit_label[1]])
                except Exception:  # pylint: disable=broad-except
                    pass
                if hasattr(circuit, name):
                    instr_method = getattr(circuit, name)
                    if i.name in ["snapshot"]:
                        _inst = instr_method(
                            i.label,
                            snapshot_type=i.snapshot_type,
                            qubits=qubits,
                            params=params,
                        )
                    elif i.name == "initialize":
                        _inst = instr_method(params, qubits)
                    else:
                        _inst = instr_method(*params, *qubits, *clbits)
                elif name == "bfunc":
                    conditional["value"] = int(i.val, 16)
                    full_bit_size = sum([creg_dict[x].size for x in creg_dict])
                    mask_map = {}
                    raw_map = {}
                    raw = []

                    for creg in creg_dict:
                        size = creg_dict[creg].size
                        reg_raw = [1] * size
                        if not raw:
                            raw = reg_raw
                        else:
                            for pos, val in enumerate(raw):
                                if val == 1:
                                    raw[pos] = 0
                            raw = reg_raw + raw
                        mask = [0] * (full_bit_size - len(raw)) + raw
                        raw_map[creg] = mask
                        mask_map[int("".join(str(x) for x in mask), 2)] = creg
                    creg = mask_map[int(i.mask, 16)]
                    conditional["register"] = creg_dict[creg]
                    val = int(i.val, 16)
                    mask = raw_map[creg]
                    for j in reversed(mask):
                        if j == 0:
                            val = val >> 1
                        else:
                            conditional["value"] = val
                            break
                else:
                    _inst = temp_opaque_instruction = Instruction(
                        name=name,
                        num_qubits=len(qubits),
                        num_clbits=len(clbits),
                        params=params,
                    )
                    circuit.append(temp_opaque_instruction, qubits, clbits)
                if conditional and name != "bfunc":
                    _inst.c_if(conditional["register"], conditional["value"])
                    conditional = {}
            circuits.append(circuit)
        return circuits
    return None


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-e812edeeb1eb> in <module>
5 qc.iso(qi.random_unitary(16).data, qc.qubits, [])
6 d = assemble(qc)
----> 7 c = disassemble(d)

~/workspace/may4-challenge/.venv/lib/python3.7/site-packages/qiskit/assembler/disassemble.py in disassemble(qobj)
137     run_config = qobj.config.to_dict()
138     user_qobj_header = qobj.header.to_dict()
--> 139     circuits = _experiments_to_circuits(qobj)
140
141     return circuits, run_config, user_qobj_header

~/workspace/may4-challenge/.venv/lib/python3.7/site-packages/qiskit/assembler/disassemble.py in _experiments_to_circuits(qobj)
79                         _inst = instr_method(params, qubits)
80                     else:
---> 81                         _inst = instr_method(*params, *qubits, *clbits)
82                 elif name == 'bfunc':
83                     conditional['value'] = int(i.val, 16)

~/workspace/may4-challenge/.venv/lib/python3.7/site-packages/qiskit/extensions/quantum_initializer/isometry.py in iso(self, isometry, q_input, q_ancillas_for_output, q_ancillas_zero, q_ancillas_dirty)
542         q_ancillas_dirty = q_ancillas_dirty[:]
543
--> 544     return self.append(Isometry(isometry, len(q_ancillas_zero), len(q_ancillas_dirty)),
545                        q_input + q_ancillas_for_output + q_ancillas_zero + q_ancillas_dirty)
546

TypeError: object of type 'Qubit' has no len()

# Fixed code
def _experiments_to_circuits(qobj):
    """Return a list of QuantumCircuit object(s) from a qobj.

    Args:
        qobj (Qobj): The Qobj object to convert to QuantumCircuits

    Returns:
        list: A list of QuantumCircuit objects from the qobj
    """
    if qobj.experiments:
        circuits = []
        for x in qobj.experiments:
            quantum_registers = [
                QuantumRegister(i[1], name=i[0]) for i in x.header.qreg_sizes
            ]
            classical_registers = [
                ClassicalRegister(i[1], name=i[0]) for i in x.header.creg_sizes
            ]
            circuit = QuantumCircuit(
                *quantum_registers, *classical_registers, name=x.header.name
            )
            qreg_dict = collections.OrderedDict()
            creg_dict = collections.OrderedDict()
            for reg in quantum_registers:
                qreg_dict[reg.name] = reg
            for reg in classical_registers:
                creg_dict[reg.name] = reg
            conditional = {}
            for i in x.instructions:
                name = i.name
                qubits = []
                params = getattr(i, "params", [])
                try:
                    for qubit in i.qubits:
                        qubit_label = x.header.qubit_labels[qubit]
                        qubits.append(qreg_dict[qubit_label[0]][qubit_label[1]])
                except Exception:  # pylint: disable=broad-except
                    pass
                clbits = []
                try:
                    for clbit in i.memory:
                        clbit_label = x.header.clbit_labels[clbit]
                        clbits.append(creg_dict[clbit_label[0]][clbit_label[1]])
                except Exception:  # pylint: disable=broad-except
                    pass
                if hasattr(circuit, name):
                    instr_method = getattr(circuit, name)
                    if i.name in ["snapshot"]:
                        _inst = instr_method(
                            i.label,
                            snapshot_type=i.snapshot_type,
                            qubits=qubits,
                            params=params,
                        )
                    elif i.name == "initialize":
                        _inst = instr_method(params, qubits)
                    elif i.name == "isometry":
                        _inst = instr_method(*params, qubits, clbits)
                    else:
                        _inst = instr_method(*params, *qubits, *clbits)
                elif name == "bfunc":
                    conditional["value"] = int(i.val, 16)
                    full_bit_size = sum([creg_dict[x].size for x in creg_dict])
                    mask_map = {}
                    raw_map = {}
                    raw = []

                    for creg in creg_dict:
                        size = creg_dict[creg].size
                        reg_raw = [1] * size
                        if not raw:
                            raw = reg_raw
                        else:
                            for pos, val in enumerate(raw):
                                if val == 1:
                                    raw[pos] = 0
                            raw = reg_raw + raw
                        mask = [0] * (full_bit_size - len(raw)) + raw
                        raw_map[creg] = mask
                        mask_map[int("".join(str(x) for x in mask), 2)] = creg
                    creg = mask_map[int(i.mask, 16)]
                    conditional["register"] = creg_dict[creg]
                    val = int(i.val, 16)
                    mask = raw_map[creg]
                    for j in reversed(mask):
                        if j == 0:
                            val = val >> 1
                        else:
                            conditional["value"] = val
                            break
                else:
                    _inst = temp_opaque_instruction = Instruction(
                        name=name,
                        num_qubits=len(qubits),
                        num_clbits=len(clbits),
                        params=params,
                    )
                    circuit.append(temp_opaque_instruction, qubits, clbits)
                if conditional and name != "bfunc":
                    _inst.c_if(conditional["register"], conditional["value"])
                    conditional = {}
            circuits.append(circuit)
        return circuits
    return None