Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
ML Quant Sep
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hachem Kadri
ML Quant Sep
Commits
2a305e9d
Commit
2a305e9d
authored
2 years ago
by
Balthazar Casale
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
f8cb46a6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/models/approx_based.py
+103
-0
103 additions, 0 deletions
src/models/approx_based.py
with
103 additions
and
0 deletions
src/models/approx_based.py
0 → 100644
+
103
−
0
View file @
2a305e9d
"""
Contain approximate methods to detect separability
"""
from
..types
import
Label
import
numpy
as
np
class
DistToSep
:
"""
Distance from a separable approximation
"""
def
__init__
(
self
,
dist_threshold
,
sep_key
=
None
,
sep_mthd
=
None
):
"""
:param dist_threshold: minimum distance to be considered entangled
:param sep_key: key containing the separable approximation in the info dictionary
:param sep_mthd: method to compute the separable approximation (if key_sep == None)
"""
self
.
dist_threshold
=
dist_threshold
self
.
sep_key
=
sep_key
self
.
sep_mthd
=
sep_mthd
def
predict
(
self
,
states
,
infos
=
{}):
"""
predict a state as separable or entangled in function of its distance to a separable approximation
:param states: quantum density matrices
:param infos: dictionary of information
:return: array of Label
"""
aprx
=
None
inf_aprx
=
{}
return_aprx
=
False
if
self
.
sep_key
is
not
None
:
aprx
=
infos
[
self
.
sep_key
]
elif
self
.
sep_mthd
is
not
None
:
return_aprx
=
True
aprx
,
inf_aprx
=
self
.
sep_mthd
(
states
,
infos
)
y
=
np
.
full
(
len
(
states
),
Label
.
ENT
)
y
[
np
.
linalg
.
norm
(
aprx
-
states
,
axis
=
(
1
,
2
))
<
self
.
dist_threshold
]
=
Label
.
SEP
if
return_aprx
:
return
y
,
{
'
aprx
'
:
aprx
,
**
inf_aprx
}
else
:
return
y
,
{}
class
WitQuality
:
"""
Quality of an approximate entanglement witness
"""
def
__init__
(
self
,
min_score
,
sep_test_set
,
wit_key
=
None
,
wit_mthd
=
None
,
return_scores
=
False
):
"""
:param min_score: minimum score for the witness to be considered valid
:param sep_test_set: DMStack of separable states on which the witness will be tested
:param wit_key: key containing the witness in the information dictionary
:param wit_mthd: method to compute the witness (if wit_key == None)
:param return_scores: return or not the score achieved by each witness as info (key :
'
wit_score
'
)
"""
self
.
min_score
=
min_score
self
.
test_set
=
sep_test_set
self
.
wit_key
=
wit_key
self
.
wit_mthd
=
wit_mthd
self
.
return_scores
=
return_scores
def
predict
(
self
,
states
,
infos
=
{}):
"""
predict a state as separable or entangled in function of the quality of an approximate entanglement witness
:param states: quantum density matrices
:param infos: dictionary of informations
:return: array of Label
"""
wits
=
None
inf_wits
=
{}
return_wit
=
False
if
self
.
wit_key
is
not
None
:
wits
=
infos
[
self
.
wit_key
]
elif
self
.
wit_mthd
is
not
None
:
wits
,
inf_wits
=
self
.
wit_mthd
(
states
,
infos
)
resp
=
np
.
full
(
len
(
states
),
True
)
# tr(W_rho rho) < 0
resp
=
np
.
logical_and
(
resp
,
np
.
trace
(
wits
@
states
,
axis1
=
1
,
axis2
=
2
).
real
<
0
)
# tr(W_rho sigma) >= 0 for vast majority of separables sigma
scores
=
np
.
zeros
(
len
(
states
))
for
i
in
range
(
len
(
wits
))
:
scores
[
i
]
=
np
.
average
(
np
.
trace
(
np
.
matmul
(
wits
[
i
],
self
.
test_set
),
axis1
=
1
,
axis2
=
2
).
real
>=
0
)
resp
=
np
.
logical_and
(
resp
,
scores
>
self
.
min_score
)
if
self
.
return_scores
:
inf_wits
=
{
'
wit_score
'
:
scores
,
**
inf_wits
}
if
return_wit
:
inf_wits
=
{
'
wit
'
:
wits
,
**
inf_wits
}
y
=
np
.
full
(
len
(
states
),
Label
.
SEP
)
y
[
resp
]
=
Label
.
ENT
return
y
,
inf_wits
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment