Skip to content

Commit 0e6ea9d

Browse files
Pure state final mode
1 parent 96341bf commit 0e6ea9d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

thewalrus/samples.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
is_classical_cov,
6767
reduced_gaussian,
6868
density_matrix_element,
69+
is_pure_cov,
70+
pure_state_amplitude,
6971
)
7072

7173
__all__ = [
@@ -124,6 +126,7 @@ def generate_hafnian_sample(
124126
local_mu = np.zeros(2 * N)
125127
else:
126128
local_mu = mean
129+
pure_cov = is_pure_cov(cov, hbar=hbar)
127130

128131
for k in range(N):
129132
total_photons = int(np.sum(result))
@@ -153,9 +156,20 @@ def generate_hafnian_sample(
153156
/ normalisation
154157
)
155158
else:
156-
prob_i = density_matrix_element(
157-
mu_red, V_red, indices, indices, include_prefactor=True, hbar=hbar
158-
).real
159+
if (k == N - 1) and (pure_cov == True):
160+
amp_i = pure_state_amplitude(
161+
mu_red, cov, indices, hbar=hbar, check_purity=False
162+
)
163+
prob_i = np.abs(amp_i) ** 2
164+
else:
165+
prob_i = density_matrix_element(
166+
mu_red,
167+
V_red,
168+
indices,
169+
indices,
170+
include_prefactor=True,
171+
hbar=hbar,
172+
).real
159173

160174
prob_cumulative += prob_i / prev_prob
161175
if prob_cumulative >= sample:

0 commit comments

Comments
 (0)