def _instruction_to_gate(self, instruction, layer):
current_cons = []<EOL>connection_label = None<EOL>def add_connected_gate(instruction, gates, layer, current_cons):<EOL><INDENT>for i, gate in enumerate(gates):<EOL><INDENT>layer.set_qubit(instruction.qargs[i], gate)<EOL>actual_index = self.qregs.index(instruction.qargs[i])<EOL>current_cons.append((actual_index, gate))<EOL><DEDENT><DEDENT>if instruction.name == '<STR_LIT>':<EOL><INDENT>gate = MeasureFrom()<EOL>layer.set_qubit(instruction.qargs[<NUM_LIT:0>], gate)<EOL>layer.set_clbit(instruction.cargs[<NUM_LIT:0>], MeasureTo())<EOL><DEDENT>elif instruction.name in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>']:<EOL><INDENT>if not self.plotbarriers:<EOL><INDENT>return layer, current_cons, connection_label<EOL><DEDENT>for qubit in instruction.qargs:<EOL><INDENT>layer.set_qubit(qubit, Barrier())<EOL><DEDENT><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>gates = [Ex() for _ in range(len(instruction.qargs))]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>gates = [Bullet(), Ex(), Ex()]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>layer.set_qubit(instruction.qargs[<NUM_LIT:0>], Reset())<EOL><DEDENT>elif instruction.condition is not None:<EOL><INDENT>cllabel = TextDrawing.label_for_conditional(instruction)<EOL>qulabel = TextDrawing.label_for_box(instruction)<EOL>layer.set_cl_multibox(instruction.condition[<NUM_LIT:0>], cllabel, top_connect='<STR_LIT>')<EOL>layer.set_qubit(instruction.qargs[<NUM_LIT:0>], BoxOnQuWire(qulabel, bot_connect='<STR_LIT>'))<EOL><DEDENT>elif instruction.name in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>gates = [Bullet() for _ in range(len(instruction.qargs) - <NUM_LIT:1>)]<EOL>gates.append(BoxOnQuWire('<STR_LIT:X>'))<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>gates = [Bullet(), BoxOnQuWire('<STR_LIT:Y>')]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>gates = [Bullet(), Bullet()]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>gates = [Bullet(), BoxOnQuWire('<STR_LIT:H>')]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>connection_label = TextDrawing.params_for_label(instruction)[<NUM_LIT:0>]<EOL>gates = [Bullet(), Bullet()]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>connection_label = "<STR_LIT>" % TextDrawing.params_for_label(instruction)[<NUM_LIT:0>]<EOL>gates = [Bullet(), Bullet()]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>params = TextDrawing.params_for_label(instruction)<EOL>gates = [Bullet(), BoxOnQuWire("<STR_LIT>" % '<STR_LIT:U+002C>'.join(params))]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif instruction.name == '<STR_LIT>':<EOL><INDENT>label = "<STR_LIT>" % TextDrawing.params_for_label(instruction)[<NUM_LIT:0>]<EOL>gates = [Bullet(), BoxOnQuWire(label)]<EOL>add_connected_gate(instruction, gates, layer, current_cons)<EOL><DEDENT>elif len(instruction.qargs) == <NUM_LIT:1> and not instruction.cargs:<EOL><INDENT>layer.set_qubit(instruction.qargs[<NUM_LIT:0>],<EOL>BoxOnQuWire(TextDrawing.label_for_box(instruction)))<EOL><DEDENT>elif len(instruction.qargs) >= <NUM_LIT:2> and not instruction.cargs:<EOL><INDENT>label = instruction.name<EOL>params = TextDrawing.params_for_label(instruction)<EOL>if params:<EOL><INDENT>label += "<STR_LIT>" % '<STR_LIT:U+002C>'.join(params)<EOL><DEDENT>layer.set_qu_multibox(instruction.qargs, label)<EOL><DEDENT>else:<EOL><INDENT>raise VisualizationError(<EOL>"<STR_LIT>", instruction)<EOL><DEDENT>current_cons.sort(key=lambda tup: tup[<NUM_LIT:0>])<EOL>current_cons = [g for q, g in current_cons]<EOL>return layer, current_cons, connection_label<EOL>
Convert an instruction into its corresponding Gate object, and establish
        any connections it introduces between qubits