deltakit.circuit.Circuit.apply_gate_noise#
- Circuit.apply_gate_noise(noise_profile: NoiseProfile | Iterable[NoiseProfile], adjacency: LayerAdjacency, recursive: bool = True)#
Apply gate noise according to the noise profile. This will add a noise layer into the circuit either before or after a gate layer if there’s a gate in the gate layer which is also in the noise profile. If no gates are found in the gate layer which are in the noise profile no noise layers are added for that gate layer.
- Parameters:
noise_profile (Mapping[Type[GateT], Callable[[GateT], NoiseChannelT | Iterable[NoiseChannelT]]]) – A mapping of gate type to the noise channel to apply. Every time the gate is found in a gate layer the noise channel is generated and added to the noise layer.
adjacency (LayerAdjacency) – Whether the gate noise should be applied before or after gates.
recursive (bool, optional) – Whether to recurse into nested circuits; by default, True.
Examples
>>> import deltakit_circuit as sp >>> circuit = sp.Circuit(sp.GateLayer(sp.gates.X(0))) >>> circuit.apply_gate_noise( ... lambda noise_context: [ ... sp.noise_channels.PauliXError(qubit, 0.1) for qubit in ... noise_context.gate_layer_qubits(sp.gates.X)], ... sp.Circuit.LayerAdjacency.AFTER) >>> circuit.layers [GateLayer([ X(Qubit(0)) ]), NoiseLayer([ X_ERROR(Qubit(0), probability=0.1) ])]>>> circuit = sp.Circuit(sp.GateLayer(sp.gates.X(0))) >>> circuit.apply_gate_noise( ... lambda noise_context: [ ... sp.noise_channels.PauliXError(qubit, 0.1) for qubit in ... noise_context.gate_layer_qubits(sp.gates.X)], ... sp.Circuit.LayerAdjacency.BEFORE) >>> circuit.layers [NoiseLayer([ X_ERROR(Qubit(0), probability=0.1) ]), GateLayer([ X(Qubit(0)) ])]