Skip to content

Commit

Permalink
Fix the leaking noise objects (#89)
Browse files Browse the repository at this point in the history
A list of noise objects defined by the user is passed to the function. However, when adding T1 and T2 noise, the generated objects were added directly to the list. This changes the `noise_list` defined by the user and is a problem if the same `Processor` instance is used to perform more than one simulation. The T1,T2 noise objects from the previous run will accumulate in the `noise_list`. Therefore, we copy the list before add T1 T2 noise.
  • Loading branch information
BoxiLi committed Aug 3, 2021
1 parent 4566775 commit 88cc63c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/qutip_qip/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def process_noise(pulses, noise_list, dims, t1=None, t2=None,
noisy_pulses: list of :class:`.Pulse`
The noisy pulses, including the system noise.
"""
noise_list = noise_list.copy()
noisy_pulses = deepcopy(pulses)
systematic_noise = Pulse(None, None, label="systematic_noise")

Expand Down
8 changes: 8 additions & 0 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,11 @@ def test_pulse_dict(self):
processor = Processor(1)
processor.add_control(sigmax(), 0, label="test")
assert("test" in processor.get_pulse_dict())

def test_repeated_use_of_processor(self):
processor = Processor(1, t1=1.)
processor.add_pulse(
Pulse(sigmax(), targets=0, coeff=True))
result1 = processor.run_state(basis(2, 0), tlist=np.linspace(0, 1, 10))
result2 = processor.run_state(basis(2, 0), tlist=np.linspace(0, 1, 10))
assert_allclose(result1.states[-1].full(), result2.states[-1].full())

0 comments on commit 88cc63c

Please sign in to comment.