_dagcircuit.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:qiskit-sdk-py 作者: QISKit 项目源码 文件源码
def serial_layers(self):
        """Return a list of layers for all gates of this circuit.

        A serial layer is a circuit with one gate. The layers have the
        same structure as in layers().
        """
        layers_list = []
        ts = nx.topological_sort(self.multi_graph)
        for n in ts:
            nxt_nd = self.multi_graph.node[n]
            if nxt_nd["type"] == "op":
                new_layer = DAGCircuit()
                for k, v in self.qregs.items():
                    new_layer.add_qreg(k, v)
                for k, v in self.cregs.items():
                    new_layer.add_creg(k, v)
                new_layer.basis = copy.deepcopy(self.basis)
                new_layer.gates = copy.deepcopy(self.gates)
                # Save the support of the operation we add to the layer
                support_list = []
                # Operation data
                qa = copy.copy(nxt_nd["qargs"])
                ca = copy.copy(nxt_nd["cargs"])
                pa = copy.copy(nxt_nd["params"])
                co = copy.copy(nxt_nd["condition"])
                cob = self._bits_in_condition(co)
                # Add node to new_layer
                new_layer.apply_operation_back(nxt_nd["name"],
                                               qa, ca, pa, co)
                # Add operation to partition
                if nxt_nd["name"] != "barrier":
                    # support_list.append(list(set(qa) | set(ca) | set(cob)))
                    support_list.append(list(set(qa)))
                l_dict = {"graph": new_layer, "partition": support_list}
                layers_list.append(l_dict)
        return layers_list
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号