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
724b1d6f
Commit
724b1d6f
authored
Jun 8, 2023
by
Balthazar Casale
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
44b9a1ae
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/types.py
+56
-0
56 additions, 0 deletions
src/types.py
with
56 additions
and
0 deletions
src/types.py
0 → 100644
+
56
−
0
View file @
724b1d6f
import
numpy
as
np
import
scipy.io
as
sio
from
enum
import
IntEnum
class
Label
(
IntEnum
):
"""
the standards labels for the separability problem
"""
SEP
=
0
ENT
=
1
UNK
=
2
class
DMStack
(
np
.
ndarray
):
"""
a DMStack represent a stack of density matrices on a certain state space.
It is a numpy.ndarray of shape (n_matrices, ...) and have n additional attribute dims which is a list indicating
the dimension of the subsystem.
The density matrices contained in a DMStack are not necessarily in the form of complex density matrices.
"""
def
__new__
(
cls
,
input_array
,
dims
):
obj
=
np
.
asarray
(
input_array
).
view
(
cls
)
obj
.
dims
=
dims
return
obj
def
__array_finalize__
(
self
,
obj
):
if
obj
is
None
:
return
self
.
dims
=
getattr
(
obj
,
'
dims
'
,
None
)
# save / load datasets
def
save_dmstack
(
filename
,
stack
,
infos
):
df
=
{
'
dims
'
:
stack
.
dims
,
'
states
'
:
stack
,
**
infos
}
sio
.
savemat
(
filename
,
df
)
def
load_dmstack
(
filename
):
df
=
sio
.
loadmat
(
filename
)
dims
=
df
.
pop
(
'
dims
'
)[
0
]
states
=
df
.
pop
(
'
states
'
)
remove
=
[
'
__header__
'
,
'
__version__
'
,
'
__globals__
'
]
# standard keys for sio
for
key
in
remove
:
df
.
pop
(
key
)
infos
=
{}
for
key
in
df
.
keys
():
infos
[
key
]
=
np
.
squeeze
(
df
[
key
])
# sio store 1D array as 2D matrices of the form [1,len(data)]
return
DMStack
(
states
,
dims
),
infos
\ 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