Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize effective noise channels #443

Merged
merged 50 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d668c75
depo noise added
Varda-star Dec 26, 2022
3bed4fe
Op matrix update.
Varda-star Dec 26, 2022
d65914e
depolarizing UT
Varda-star Dec 27, 2022
6ecf084
Why line 935 not verified.
Varda-star Dec 27, 2022
0cd0004
Trying to figure out why not 100% coverage for test_simulation
Varda-star Dec 29, 2022
44d70b8
Still not know why not 100% coverage.
Varda-star Dec 29, 2022
a47c0e1
Issue solved. Dephasing well added!
Varda-star Dec 29, 2022
b7434d5
uncorrelated noise approximation for dephasing channel
Varda-star Jan 5, 2023
8b903ae
reformating
Varda-star Jan 5, 2023
272cfc6
simconfig gen_noise
Varda-star Jan 5, 2023
a75211b
_check_gen_noise debugging.
Varda-star Jan 5, 2023
580001a
operator building in general noise setting 1.
Varda-star Jan 5, 2023
5761fd7
test_simconfig up to date.
Varda-star Jan 9, 2023
c57b0e5
simconfig 100% cov.
Varda-star Jan 9, 2023
9d5aba0
simulation 100% cov
Varda-star Jan 9, 2023
2273780
reformatting.
Varda-star Jan 9, 2023
f02db5b
Merge branch 'develop' into gen_eff_noise
Varda-star Jan 9, 2023
0e75f6b
Merge branch 'develop' into gen_eff_noise
Varda-star Jan 11, 2023
fc7b25a
Merge branch 'develop' into gen_eff_noise
Varda-star Jan 12, 2023
fd1f31c
Merge branch 'develop' into gen_eff_noise
Varda-star Jan 12, 2023
87fddbc
depolarizing model chosen
Varda-star Jan 12, 2023
5e53744
Merge branch 'gen_eff_noise' of https://github.com/Varda-star/Pulser …
Varda-star Jan 12, 2023
d41eb4c
gen-noise description updated.
Varda-star Jan 12, 2023
246dbb0
gen_noise description update.
Varda-star Jan 12, 2023
2935038
cov completed
Varda-star Jan 12, 2023
da58dc1
reformatting.
Varda-star Jan 12, 2023
8d6c251
Reformatting.
Varda-star Jan 13, 2023
54d5c6d
init issue solved
Varda-star Jan 13, 2023
51ce92b
np.isclose
Varda-star Jan 13, 2023
cb349cd
depolarizing noise description
Varda-star Jan 13, 2023
adbad66
warning updated.
Varda-star Jan 13, 2023
013ea6a
Update pulser-simulation/pulser_simulation/simulation.py
Varda-star Jan 13, 2023
9608ef9
Update pulser-simulation/pulser_simulation/simconfig.py
Varda-star Jan 13, 2023
009fcda
description updated
Varda-star Jan 13, 2023
a7bb15c
One effective noise channel allowed for one simulation
Varda-star Jan 16, 2023
10ec858
Collapse operator building relocated
Varda-star Jan 16, 2023
51c95e9
Merge branch 'develop' into gen_eff_noise
HGSilveri Jan 17, 2023
d1e2405
effecture noise type checking reformatted
Varda-star Jan 17, 2023
ca12a77
Update pulser-simulation/pulser_simulation/simconfig.py
Varda-star Jan 17, 2023
132a067
Update pulser-simulation/pulser_simulation/simconfig.py
Varda-star Jan 17, 2023
f58d4ec
Update pulser-simulation/pulser_simulation/simconfig.py
Varda-star Jan 17, 2023
6fa2ac0
Update pulser-simulation/pulser_simulation/simulation.py
Varda-star Jan 17, 2023
fa97d38
Merge branch 'develop' into gen_eff_noise
Varda-star Jan 18, 2023
07b74ee
test_eff_noise & test_depolarizing
Varda-star Jan 18, 2023
07cc94e
merge develop
Varda-star Jan 18, 2023
bab4dc8
coverage ok
Varda-star Jan 18, 2023
7a3fad0
separate UTs
Varda-star Jan 18, 2023
185fed7
UT naming
Varda-star Jan 18, 2023
66ad1b6
UT reviex 1
Varda-star Jan 18, 2023
7d075e0
variable naming
Varda-star Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pulser-simulation/pulser_simulation/simconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ def _check_noise_types(self) -> None:
dephasing_on = "dephasing" in self.noise
depolarizing_on = "depolarizing" in self.noise
eff_noise_on = "eff_noise" in self.noise
eff_noise_conflict = (
(dephasing_on and depolarizing_on)
or (depolarizing_on and eff_noise_on)
or (dephasing_on and eff_noise_on)
)
eff_noise_conflict = dephasing_on + depolarizing_on + eff_noise_on > 1
if eff_noise_conflict:
raise NotImplementedError(
"Depolarizing, dephasing and eff_noise channels"
Expand Down Expand Up @@ -228,7 +224,7 @@ def _check_eff_noise(self) -> None:
for prob in self.eff_noise_probs:
if not isinstance(prob, float):
raise TypeError(
"eff_noise_probs is a list of floats"
"eff_noise_probs is a list of floats,"
f" it must not contain a {type(prob)}."
)

Expand Down
14 changes: 7 additions & 7 deletions pulser-simulation/pulser_simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def set_config(self, cfg: SimConfig) -> None:
# Noise, samples and Hamiltonian update routine
self._construct_hamiltonian()

Kraus_ops = []
kraus_ops = []
if "dephasing" in self.config.noise:
if self.basis_name == "digital" or self.basis_name == "all":
# Go back to previous config
Expand All @@ -226,7 +226,7 @@ def set_config(self, cfg: SimConfig) -> None:
np.sqrt((1 - prob) ** n)
* qutip.tensor([self.op_matrix["I"] for _ in range(n)])
]
Kraus_ops.append(k * qutip.sigmaz())
kraus_ops.append(k * qutip.sigmaz())

if "depolarizing" in self.config.noise:
if self.basis_name == "digital" or self.basis_name == "all":
Expand All @@ -253,9 +253,9 @@ def set_config(self, cfg: SimConfig) -> None:
np.sqrt((1 - 3 * prob) ** n)
* qutip.tensor([self.op_matrix["I"] for _ in range(n)])
]
Kraus_ops.append(k * qutip.sigmax())
Kraus_ops.append(k * qutip.sigmay())
Kraus_ops.append(k * qutip.sigmaz())
kraus_ops.append(k * qutip.sigmax())
kraus_ops.append(k * qutip.sigmay())
kraus_ops.append(k * qutip.sigmaz())

if "eff_noise" in self.config.noise:
if self.basis_name == "digital" or self.basis_name == "all":
Expand Down Expand Up @@ -290,10 +290,10 @@ def set_config(self, cfg: SimConfig) -> None:
self.config.eff_noise_probs[i] * prob_id ** (n - 1)
)
K_op = k * self.config.eff_noise_opers[i]
HGSilveri marked this conversation as resolved.
Show resolved Hide resolved
Kraus_ops.append(K_op)
kraus_ops.append(K_op)

# Building collapse operators
for operator in Kraus_ops:
for operator in kraus_ops:
self._collapse_ops += [
self.build_operator([(operator, [qid])])
for qid in self._qid_index
Expand Down
31 changes: 14 additions & 17 deletions tests/test_simconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def matrices():
return pauli


def test_init(matrices):
def test_init1(matrices):
config = SimConfig(
noise=(
"SPAM",
Expand Down Expand Up @@ -70,26 +70,23 @@ def test_init(matrices):
ValueError, match="The standard deviation in amplitude"
):
SimConfig(amp_sigma=-0.001)


@pytest.mark.parametrize(
"noise_sample,",
[
("dephasing", "depolarizing"),
("eff_noise", "depolarizing"),
("eff_noise", "dephasing"),
("depolarizing", "eff_noise", "dephasing"),
],
)
def test_init2(matrices, noise_sample):
Varda-star marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(
NotImplementedError,
match="Depolarizing, dephasing and eff_noise channels",
):
SimConfig(noise=("dephasing", "depolarizing"))
with pytest.raises(
NotImplementedError,
match="Depolarizing, dephasing and eff_noise channels",
):
SimConfig(noise=("eff_noise", "depolarizing"))
with pytest.raises(
NotImplementedError,
match="Depolarizing, dephasing and eff_noise channels",
):
SimConfig(noise=("dephasing", "eff_noise"))
with pytest.raises(
NotImplementedError,
match="Depolarizing, dephasing and eff_noise channels",
):
SimConfig(noise=("dephasing", "depolarizing", "eff_noise"))
SimConfig(noise=noise_sample)
Varda-star marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(ValueError, match="The operators list length"):
SimConfig(noise=("eff_noise"), eff_noise_probs=[1.0])
with pytest.raises(ValueError, match="Fill the general noise parameters."):
Expand Down
12 changes: 10 additions & 2 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ def test_depolarizing():
seq, sampling_rate=0.01, config=SimConfig(noise="depolarizing")
)
assert sim.run().sample_final_state() == Counter({"0": 587, "1": 413})
Varda-star marked this conversation as resolved.
Show resolved Hide resolved
trace_2 = sim.run()._results[-1] ** 2
assert np.trace(trace_2) < 1 and not np.isclose(np.trace(trace_2), 1)
assert len(sim._collapse_ops) != 0
with pytest.warns(UserWarning, match="first-order"):
reg = Register.from_coordinates([(0, 0), (0, 6)], prefix="q")
Expand Down Expand Up @@ -671,10 +673,16 @@ def test_eff_noise(matrices):
config=SimConfig(
noise="eff_noise",
eff_noise_opers=[matrices["I"], matrices["Z"]],
eff_noise_probs=[0.95, 0.05],
eff_noise_probs=[0.975, 0.025],
),
)
assert sim.run().sample_final_state() == Counter({"0": 595, "1": 405})
sim_dph = Simulation(
seq, sampling_rate=0.01, config=SimConfig(noise="dephasing")
)
assert (
sim._collapse_ops == sim_dph._collapse_ops
and sim.run().states[-1] == sim_dph.run().states[-1]
)
assert len(sim._collapse_ops) != 0
with pytest.warns(UserWarning, match="first-order"):
reg = Register.from_coordinates([(0, 0), (0, 8)], prefix="q")
Expand Down