Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles MOUSSA committed Dec 4, 2024
1 parent 965099f commit 06c6062
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/test_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@

from typing import Callable

import jax.numpy as jnp
import numpy as np
import pytest
from jax import Array

from horqrux.apply import apply_gate, apply_operator
from horqrux.apply import apply_gate
from horqrux.noise import NoiseInstance, NoiseType
from horqrux.parametric import PHASE, RX, RY, RZ
from horqrux.primitive import NOT, SWAP, H, I, S, T, X, Y, Z
from horqrux.utils import equivalent_state, product_state, random_state
from horqrux.primitive import NOT, H, I, S, T, X, Y, Z
from horqrux.utils import random_state

MAX_QUBITS = 7
PARAMETRIC_GATES = (RX, RY, RZ, PHASE)
PRIMITIVE_GATES = (NOT, H, X, Y, Z, I, S, T)

NOISE_oneproba = (NoiseType.BITFLIP, NoiseType.PHASEFLIP, NoiseType.DEPOLARIZING, NoiseType.AMPLITUDE_DAMPING, NoiseType.PHASE_DAMPING)
NOISE_oneproba = (
NoiseType.BITFLIP,
NoiseType.PHASEFLIP,
NoiseType.DEPOLARIZING,
NoiseType.AMPLITUDE_DAMPING,
NoiseType.PHASE_DAMPING,
)
ALL_NOISES = list(NoiseType)


def noise_instance(noise_type: NoiseType) -> NoiseInstance:
if noise_type in NOISE_oneproba:
errors = 0.1
elif noise_type == NoiseType.PAULI_CHANNEL:
errors=(0.4, 0.5, 0.1)
errors = (0.4, 0.5, 0.1)
else:
errors = (0.2, 0.8)

return NoiseInstance(noise_type, error_probability=errors)


@pytest.mark.parametrize("gate_fn", PRIMITIVE_GATES)
@pytest.mark.parametrize("noise_type", ALL_NOISES)
def test_noisy_primitive(gate_fn: Callable, noise_type: NoiseType) -> None:
Expand Down Expand Up @@ -57,4 +63,3 @@ def test_noisy_parametric(gate_fn: Callable, noise_type: NoiseType) -> None:
output_dm = apply_gate(orig_state, noisy_gate, values)
# check output is a density matrix
assert len(output_dm.shape) == 2 * MAX_QUBITS

0 comments on commit 06c6062

Please sign in to comment.