def __init__(self, name: str, probs: typing.List[float], level: int): """ Parameters ---------- name: str what the name of the noise is. Determines how many probabilites are needed additionally. probs: list: a list of probabilities with which to apply the requested noise level: int: the number of qubits in the gates this noise acts upon. """ probs = list_assignement(probs) if name not in noises_available: raise TequilaException( 'The name you asked for, {}, is not recognized'.format(name)) self._name = name self._level = int(level) if len(probs) != self.prob_length[name]: raise TequilaException( '{} noise requires {} probabilities; recieved {}'.format( name, self.prob_length[name], len(probs))) if name in krausses: assert sum(probs) <= 1. self.probs = list_assignement(probs)
def __init__(self, name, target: UnionList, control: UnionList = None): self._name = name self._target = tuple(list_assignement(target)) self._control = tuple(list_assignement(control)) self.finalize() # Set the active qubits if self.control: self._qubits = self.target + self.control else: self._qubits = self.target self._qubits = sorted(tuple(set(self._qubits))) self._max_qubit = self.compute_max_qubit()
def __init__(self, name: str, probs: typing.List[float], level: int, form: str = 'kraus'): probs = list_assignement(probs) self._name = name self._level = int(level) assert len(probs) == self.prob_length[name] if form == 'kraus': assert sum(probs) <= 1. if form == 'depolarizing': assert sum(probs) <= 1. self.probs = list_assignement(probs)
def __init__(self, name: str, probs: typing.List[float], level: int): probs = list_assignement(probs) if name not in noises_available: raise TequilaException( 'The name you asked for, {}, is not recognized'.format(name)) self._name = name self._level = int(level) if len(probs) != self.prob_length[name]: raise TequilaException( '{} noise requires {} probabilities; recieved {}'.format( name, self.prob_length[name], len(probs))) if name in krausses: assert sum(probs) <= 1. self.probs = list_assignement(probs)
def __init__(self, generators: typing.Union[QubitHamiltonian, typing.List[QubitHamiltonian]], steps: int = 1, angles: typing.Union[list, numbers.Real, Variable] = None, control: typing.Union[list, int] = None, threshold: numbers.Real = 0.0, join_components: bool = True, randomize_component_order: bool = True, randomize: bool = True): """ :param generators: list of generators :param angles: coefficients for each generator :param steps: Trotter Steps :param control: control qubits :param threshold: neglect terms in the given Hamiltonians if their coefficients are below this threshold :param join_components: The generators are trotterized together. If False the first generator is trotterized, then the second etc Note that for steps==1 as well as len(generators)==1 this has no effect :param randomize_component_order: randomize the order in the generators order before trotterizing :param randomize: randomize the trotter decomposition of each generator """ super().__init__(name="Trotterized", target=self.extract_targets(generators), control=control) self.generators = list_assignement(generators) self.angles = angles self.steps = steps self.threshold = threshold self.join_components = join_components self.randomize_component_order = randomize_component_order self.randomize = randomize self.finalize()
def PhaseDamp(p: float, level: int): ''' Returns a NoiseModel of one QuantumNoise, having a kraus map corresponding to phase damping; Krauss map is defined following Nielsen and Chuang; E_0= [[1,0], [0,sqrt(1-p)]] E_1= [[0,0], [0,sqrt(p)]] Parameters ---------- p: float: the probability with which the noise is applied. level: int: the # of qubits in operations to apply this noise to. Returns ------- NoiseModel ''' new = NoiseModel.wrap_noise( QuantumNoise(name='phase damp', probs=list_assignement(p), level=level)) return new
def __init__(self, noises: typing.List[typing.Union[dict, Noise]] = None): if noises is None: self.noises = [] else: self.noises = [ Noise.from_dict(d) for d in list_assignement(noises) ]
def DepolarizingError(p: float, level: int): new = NoiseModel.wrap_noise( Noise(name='depolarizing', probs=list_assignement(p), level=level, form='depolarizing')) return new
def AmplitudeDamp(p: float, level: int): ''' Returns a NoiseModel one QuantumNoise, corresponding to amplitude damping. this channel takes 1 to 0, but leaves 0 unaffected. kraus maps: E_0= [[1,0], [0,sqrt(1-p)]] E_1= [[0,sqrt(p)], [0,0]] Parameters ---------- p: float: the probability with which the noise is applied. level: int: the # of qubits in operations to apply this noise to. Returns ------- NoiseModel ''' new = NoiseModel.wrap_noise( QuantumNoise(name='amplitude damp', probs=list_assignement(p), level=level)) return new
def Z(qubit) -> QubitHamiltonian: """ Initialize a single Pauli Z Operator Parameters ---------- qubit: int or list of ints qubit(s) on which the operator should act Returns ------- QubitHamiltonian """ qubit = list_assignement(qubit) return pauli(qubit=qubit, type=["Z"] * len(qubit))
def BitFlip(p: float, level: int): ''' Returns a NoiseModel with a krauss map corresponding to application of pauli X with likelihood p. Parameters ---------- p: a float, the probability with which the noise is applied. level: int, the # of qubits in operations to apply this noise to. Returns: NoiseModel ------- ''' new = NoiseModel.wrap_noise( QuantumNoise(name='bit flip', probs=list_assignement(p), level=level)) return new
def PhaseAmplitudeDamp(p1: float, p2: float, level: int): ''' Returns a NoiseModel with a krauss map corresponding to simultaneous phase and amplitude damping. Parameters ---------- p1: a float, the probability with which AMPLITUDE is damped. p2: a float, the probability with which PHASE is damped. level: int, the # of qubits in operations to apply this noise to. Returns: NoiseModel ------- ''' new = NoiseModel.wrap_noise( QuantumNoise(name='phase-amplitude damp', probs=list_assignement([p1, p2]), level=level)) return new
def DepolarizingError(p: float, level: int): ''' Returns a NoiseModel with a krauss map corresponding to equal probabilities of each of the three pauli matrices being applied. Parameters ---------- p: a float, the probability with which the noise is applied. level: int, the # of qubits in operations to apply this noise to. Returns: NoiseModel ------- ''' new = NoiseModel.wrap_noise( QuantumNoise(name='depolarizing', probs=list_assignement(p), level=level)) return new
def BitFlip(p: float, level: int): """ Returns a NoiseModel with one QuantumNoise, having a kraus map corresponding to applying pauli X with likelihood p. Parameters ---------- p: float: the probability with which the noise is applied. level: int: the # of qubits in operations to apply this noise to. Returns ------- NoiseModel """ new = NoiseModel.wrap_noise( QuantumNoise(name='bit flip', probs=list_assignement(p), level=level)) return new
def PhaseAmplitudeDamp(p1: float, p2: float, level: int): ''' Returns a NoiseModel with one QuantumNoise, having a kraus map corresponding to phase and amplitude damping. Parameters ---------- p1: float: the probability with which phase is damped p2: float: the probability with which amplitude is damped level: int: the # of qubits in operations to apply this noise to. Returns ------- NoiseModel ''' new = NoiseModel.wrap_noise( QuantumNoise(name='phase-amplitude damp', probs=list_assignement([p1, p2]), level=level)) return new
def Sm(qubit) -> QubitHamiltonian: """ Notes ---------- Initialize .. math:: \\frac{1}{2} \\left( \\sigma_x + i \\sigma_y \\right) Parameters ---------- qubit: int or list of ints qubit(s) on which the operator should act Returns ------- QubitHamiltonian """ qubit = list_assignement(qubit) result = I() for q in qubit: result *= 0.5 * (X(qubit=q) - 1.j * Y(qubit=q)) return result
def PhaseFlip(p: float, level: int): new = NoiseModel.wrap_noise( Noise(name='phase flip', probs=list_assignement(p), level=level)) return new
def PhaseAmplitudeDamp(p1: float, p2: float, level: int): new = NoiseModel.wrap_noise( Noise(name='phase-amplitude damp', probs=list_assignement([p1, p2]), level=level)) return new
def AmplitudeDamp(p: float, level: int): new = NoiseModel.wrap_noise( Noise(name='amplitude damp', probs=list_assignement(p), level=level)) return new
def __init__(self, name, target): super().__init__(name=name, target=tuple(sorted(list_assignement(target))))