Source code for qiskit_qec.geometry.tiles.tilefactory
# This code is part of Qiskit.## (C) Copyright IBM 2017, 2022## This code is licensed under the Apache License, Version 2.0. You may# obtain a copy of this license in the LICENSE.txt file in the root directory# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.## Any modifications or derivative works of this code must retain this# copyright notice, and modified files need to carry a notice indicating# that they have been altered from the originals."""Module for Tile Factory"""fromtypingimportList,Optionalimportnumpyasnpfromqiskit_qec.geometry.model.edgeimportEdgefromqiskit_qec.geometry.model.faceimportFacefromqiskit_qec.geometry.model.shellimportShellfromqiskit_qec.geometry.model.verteximportVertexfromqiskit_qec.geometry.model.wireframeimportWireFramefromqiskit_qec.geometry.model.qubit_countimportQubitCountfromqiskit_qec.geometry.model.qubit_dataimportQubitData
[docs]classTileFactory:"""Base class for all geometric tiles"""def__new__(cls,*,origin:np.ndarray,wf_coordinates:List,wf_q_indices:List,wf_loop_indicator:List[bool],faces_wf_components:List[List],num_qubits:int,face_colors:List,qubit_count:Optional[QubitCount]=None,qubit_data:Optional[QubitData]=None,operators:Optional[List]=None,**kwargs,)->Shell:"""Create tile"""# Qubitsifqubit_countisnotNoneandqubit_dataisnotNone:qubits=[qubit_count.new_qubit()foriinrange(num_qubits)]# Create Shellwf_id_to_index={}faces=[]# print(f"faces_wf_components={faces_wf_components}")forwf_listinfaces_wf_components:# print(f"wf_list={wf_list}")wfs=[]forwf_indexinwf_list:# print(f"wf_index={wf_index}")# print(f"operators[wf_index]={operators[wf_index]}")ifoperators[wf_index]isnotNone:# print(f"Making wf for index = {wf_index}")wf=cls._make_wireframe(vertices=wf_coordinates[wf_index],origin=origin,loop_indicator=wf_loop_indicator[wf_index],)wfs.append(wf)wf_id_to_index[wf.id]=wf_indexiflen(wfs)!=0:faces.append(Face(wfs))shell=Shell(faces)# Set the date for the shell# Vertex Dataforfaceinshell.faces:forwfinface.wireframes:q_indices=wf_q_indices[wf_id_to_index[wf.id]]op_list=operators[wf_id_to_index[wf.id]]forindex,vertexinenumerate(wf.vertices):# Assign a qubit id to verticesqubit_data.qubit[vertex.id]=qubits[q_indices[index]]# Update the qubit count for the qubitqubit_count.increment_qubit(qubits[q_indices[index]])# Assign a Pauli operator(s) to verticesqubit_data.operator[vertex.id]=[op[index]foropinop_list]# TODO: Add code to add extra vertex data# Edge Data# TODO: Add code to add edge data# Wireframe Dataprefix="wf_"object_arrays={key:arrayforkey,arrayinkwargs.items()ifkey.startswith(prefix)}fornameinobject_arrays.keys():qubit_data.add_data_array(data_array={},name=name)forwfinshell.wireframes:forname,arrayinobject_arrays.items():qubit_data.data_arrays[name][wf.id]=array[wf_id_to_index[wf.id]]# Face Dataforindex,faceinenumerate(shell.faces):qubit_data.face_colors[face.id]=face_colors[index]# TODO: Add code to add extra face data (if exists)# Shell Data# TODO: Add code to add shell datareturnshell@staticmethoddef_make_wireframe(vertices,origin,loop_indicator):# Verticesv=[Vertex(np.asarray(vertex)+origin)forvertexinvertices]# Edgesnum_vertices=len(vertices)ifloop_indicator:edges=[Edge([v[i],v[(i+1)%num_vertices]])foriinrange(num_vertices)]else:edges=[Edge([v[i],v[(i+1)]])foriinrange(num_vertices-1)]# WireframereturnWireFrame(edges)