Skip to content

Commit 3aef457

Browse files
Merge pull request #44 from benoitseron/certification
Certification
2 parents ce4d191 + a93af4d commit 3aef457

18 files changed

+343
-435
lines changed

src/BosonSampling.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ include("scattering.jl")
3636

3737
include("bunching/bunching.jl")
3838
include("partitions/legacy.jl")
39+
include("partitions/partition_expectation_values.jl")
40+
include("partitions/partitions.jl")
3941

40-
include("circuits/circuit_elements.jl")
4142

4243
include("boson_samplers/tools.jl")
4344
include("boson_samplers/classical_sampler.jl")
4445
include("boson_samplers/cliffords_sampler.jl")
4546
include("boson_samplers/methods.jl")
46-
include("boson_samplers/metropolis_independant_sampler.jl")
4747
include("boson_samplers/metropolis_sampler.jl")
4848
include("boson_samplers/noisy_sampler.jl")
4949

src/certification/bayesian.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
### first, a simple bayesian estimator ###
22

3-
43
confidence(χ) = χ/(1+χ)
54

65
function update_confidence(event, p_q, p_a, χ)
@@ -10,7 +9,7 @@ function update_confidence(event, p_q, p_a, χ)
109

1110
end
1211

13-
function compute_χ(events,p_q, p_a)
12+
function compute_χ(events, p_q, p_a)
1413
χ = 1.
1514
for event in events
1615
χ = update_confidence(event, p_q, p_a, χ)

src/certification/notebooks/comparison.jl

Lines changed: 0 additions & 96 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/example_usage.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,22 @@ input_state = Input{Bosonic}(first_modes(n,m))
238238

239239
bunching_events(input_state,sub)
240240
#### not what we want
241+
242+
### multiple counts probabilities ###
243+
244+
245+
m = 10
246+
n = 3
247+
set1 = zeros(Int,m)
248+
set2 = zeros(Int,m)
249+
set1[1:2] .= 1
250+
set2[3:4] .= 1
251+
252+
interf = RandHaar(m)
253+
part = Partition([Subset(set1), Subset(set2)])
254+
255+
i = Input{Bosonic}(first_modes(n,m))
256+
o = PartitionCountsAll(part)
257+
ev = Event(i,o,interf)
258+
259+
compute_probability!(ev)

src/main.jl

Lines changed: 131 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,143 @@
1+
using Revise
2+
using BosonSampling
13
using Permanents
2-
using Plots
3-
using Test
4-
using Combinatorics
5-
using Random
6-
using IterTools
7-
using Statistics
8-
using LinearAlgebra #removed so as to be able to use generic types such as BigFloats, can be put back if needed
9-
using PolynomialRoots
10-
using StatsBase
11-
#using JLD
12-
using CSV
13-
using DataFrames
14-
using Tables
15-
using Plots#; plotly() #plotly allows to make "dynamic" plots where you can point the mouse and see the values, they can also be saved like that but note that this makes them heavy (and html instead of png)
16-
using PrettyTables #to display large matrices
17-
using Roots
18-
using BenchmarkTools
19-
using Optim
20-
using ProgressMeter
21-
using Parameters
4+
using PrettyTables
225
using ArgCheck
23-
using Distributions:Normal
6+
using Test
7+
8+
### multiple counts buisness ###
9+
10+
11+
### first, a simple bayesian estimator ###
12+
13+
confidence(χ) = χ/(1+χ)
14+
15+
function update_confidence(event, p_q, p_a, χ)
16+
17+
χ *= p_q(event)/p_a(event)
18+
χ
19+
20+
end
21+
22+
function compute_χ(events, p_q, p_a)
23+
χ = 1.
24+
for event in events
25+
χ = update_confidence(event, p_q, p_a, χ)
26+
end
27+
χ
28+
end
29+
30+
function compute_confidence(events,p_q, p_a)
31+
32+
"""a bayesian confidence estimator:
33+
34+
returns the probability that the null hypothesis Q is right compared to
35+
the alternative hypothesis A
36+
37+
the functions take in events
38+
p_q is a function that takes in an event and gives its probability in the null hypothesis
39+
p_a is the same for the alternative hypothesis
40+
χ is the ratio between null hypothesis probabilities and alternative ones
41+
42+
"""
43+
44+
confidence(compute_χ(events,p_q, p_a))
45+
end
46+
47+
function compute_confidence_array(events, p_q, p_a)
48+
49+
"""gives an array of the probability of H being true
50+
as we process more and more events"""
51+
52+
χ_array = [1.]
53+
54+
for event in events
55+
push!(χ_array, update_confidence(event, p_q, p_a, χ_array[end]))
56+
end
57+
58+
confidence.(χ_array)
59+
60+
end
61+
62+
### tests with standard boson sampling ###
63+
64+
# we will test that we are indeed in the bosonic case
65+
# compared to the distinguishable one
66+
67+
# first we generate a series of bosonic events
68+
69+
n_events = 10
70+
n = 3
71+
m = 4
72+
interf = RandHaar(m)
73+
input_state = Input{Bosonic}(first_modes(n,m))
74+
75+
events = []
76+
77+
OutputMeasurement{FockDetection}(random_mode_occupation_collisionless(n,m))
78+
79+
for i in 1:n_events
80+
81+
# generate a random output pattern
82+
output_state = FockDetection(random_mode_occupation_collisionless(n,m))
83+
84+
# compute the event probability
85+
this_event = Event(input_state, output_state, interf)
86+
compute_probability!(this_event)
87+
push!(events, this_event)
88+
89+
end
90+
91+
# now we have the vector of observed events with probabilities
92+
93+
events
94+
95+
# next, from events, recover the probabilities under both
96+
# hypothesis
97+
98+
function p_B(event::Event)
99+
100+
interf = event.interferometer
101+
r = event.input_state.r
102+
input_state = Input{Bosonic}(r)
103+
output_state = event.output_measurement
104+
105+
event_H = Event(input_state, output_state, interf)
106+
compute_probability!(event_H)
107+
108+
event_H.proba_params.probability
109+
110+
end
111+
112+
function p_D(event::Event)
113+
114+
interf = event.interferometer
115+
r = event.input_state.r
116+
input_state = Input{Distinguishable}(r)
117+
output_state = event.output_measurement
118+
119+
event_A = Event(input_state, output_state, interf)
120+
compute_probability!(event_A)
24121

25-
const ATOL = 1e-10
122+
event_A.proba_params.probability
26123

124+
end
27125

28-
include("special_matrices.jl")
29-
include("matrix_tests.jl")
30-
include("proba_tools.jl")
31-
include("type_functions.jl")
32-
include("types/types.jl")
33-
include("scattering.jl")
126+
# hypothesis : the events were from a bosonic distribution
34127

35-
include("circuits/circuit_elements.jl")
128+
p_q = p_B
129+
p_a = p_D
36130

37-
include("partitions/legacy.jl")
38-
include("partitions/partitions.jl")
131+
confidence(compute_χ(events, p_q, p_a))
39132

40-
include("bunching/bunching.jl")
133+
# hypothesis : the events were from a distinguishable distribution
41134

135+
p_q = p_D
136+
p_a = p_B
42137

138+
confidence(compute_χ(events, p_q, p_a))
43139

44-
include("permanent_conjectures/bapat_sunder.jl")
45-
include("permanent_conjectures/counter_example_functions.jl")
46-
include("permanent_conjectures/counter_example_numerical_search.jl")
47-
include("permanent_conjectures/permanent_on_top.jl")
140+
@test confidence(compute_χ(events, p_q, p_a)) + confidence(compute_χ(events, p_a, p_q)) 1 atol = 1e-10
48141

49-
permanent = ryser
142+
##### the only thing I see is a problem in the probabilities themselves?
143+
####### it just looks like stuff is inversed somewhere...

0 commit comments

Comments
 (0)