Source code for qiskit_qec.codes.stabsubsystemcodes
# This code is part of Qiskit.## (C) Copyright IBM 2017, 2020## 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.""" This is the main module that defines a StabSubsystem Code. """fromtypingimportOptionalfromqiskitimportQiskitErrorfromqiskit_qec.codes.codeimportCodefromqiskit_qec.geometry.model.qubit_countimportQubitCountfromqiskit_qec.geometry.model.qubit_dataimportQubitDatafromqiskit_qec.geometry.model.shellimportShellfromqiskit_qec.structures.gaugeimportGaugeGroupfromqiskit_qec.operators.pauli_listimportPauliList
[docs]classStabSubSystemCode(Code):"""The "StabSubSystemCode" inherits the "Code" class"""def__init__(self,gauge_group:Optional[GaugeGroup]=None,*,shell:Optional[Shell]=None,qubit_data:Optional[QubitData]=None,qubit_count:Optional[QubitCount]=None,)->None:"""Stabilizer Subsystem System Code Class A stabilizer subsystem code can be initialized by providing either a gauge group of a shell and associated data but not both. Args: gauge_group (optional): Gauge group defining the subsystem. Defaults to None. shell (optional): Shell definging the subsystem. Defaults to None. qubit_data (optional): Qubit data associated with defining shell. Defaults to None. qubit_count (optional): Qubit count data associated with defining shell. Defaults to None. Examples: >>> generators = PauliList(['X1X2','Z3Z4', 'X3Z9']) >>> gauge_group = GaugeGroup(generators) >>> code = StabSubSystemCode(gauge_group) >>> qubit_data = QubitData() >>> qubit_count = QubitCount() >>> origin = numpy.array([0,0]) >>> shell = CheckerBoardTile(origin=origin, qubit_data=qubit_data, qubit_count=qubit_count) >>> code = StabSubSystemCode(shell) """ifgauge_groupisNoneandshellisNone:raiseQiskitError("A Gauge group or Shell and associated data is required")ifgauge_groupisnotNone:self.gauge_group=gauge_groupself._n=self.gauge_group.generators.num_qubits# pylint: disable=invalid-nameifgauge_groupisnotNoneandshellisnotNone:raiseQiskitError("Only one of gauge_group or shell should be provided")ifshellisnotNone:ifqubit_dataisNoneorqubit_countisNone:raiseQiskitError("Both qubit_data and qubit_count inputs are needed for a shell")self.shell=shellself.qubit_data=qubit_dataself.qubit_count=qubit_countgenerators,self.qubit_data=Shell.shell2symplectic(self.shell,self.qubit_data,self.qubit_count)gauge_group=GaugeGroup(generators)self.gauge_group=gauge_groupself._n=self.gauge_group.generators.num_qubits# pylint: disable=invalid-namesuper().__init__()@propertydefn(self)->int:"""_summary_ Returns: int: _description_ """returnself._n@propertydefgenerators(self)->PauliList:"""Returns the Pauli generators for the subsystem"""returnself.gauge_group.generators
[docs]defdraw(self,**kwargs)->None:"""Draws the subsytem code if a shell exists"""ifself.shellisnotNone:self.shell.draw(qubit_data=self.qubit_data,qubit_count=self.qubit_count,**kwargs)