def run(self, dag):
diagonal_1q_gates = (RZGate, ZGate, TGate, SGate, TdgGate, SdgGate, U1Gate)<EOL>diagonal_2q_gates = (CzGate, CrzGate, Cu1Gate, RZZGate)<EOL>nodes_to_remove = set()<EOL>for measure in dag.op_nodes(Measure):<EOL><INDENT>predecessor = dag.quantum_predecessors(measure)[<NUM_LIT:0>]<EOL>if predecessor.type == '<STR_LIT>' and isinstance(predecessor.op, diagonal_1q_gates):<EOL><INDENT>nodes_to_remove.add(predecessor)<EOL><DEDENT>if predecessor.type == '<STR_LIT>' and isinstance(predecessor.op, diagonal_2q_gates):<EOL><INDENT>successors = dag.quantum_successors(predecessor)<EOL>if all([s.type == '<STR_LIT>' and isinstance(s.op, Measure) for s in successors]):<EOL><INDENT>nodes_to_remove.add(predecessor)<EOL><DEDENT><DEDENT><DEDENT>for node_to_remove in nodes_to_remove:<EOL><INDENT>dag.remove_op_node(node_to_remove)<EOL><DEDENT>return dag<EOL>
Return a new circuit that has been optimized.