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
5ef92f78
Commit
5ef92f78
authored
2 years ago
by
Balthazar Casale
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
bb22671f
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/samplers/pure.py
+37
-0
37 additions, 0 deletions
src/samplers/pure.py
with
37 additions
and
0 deletions
src/samplers/pure.py
0 → 100644
+
37
−
0
View file @
5ef92f78
"""
Contain method to sample pure quantum states
"""
import
numpy
as
np
from
.utils
import
RandomGinibre
,
kron
,
dagger
class
RandomHaar
:
"""
Random density matrices sampled from the Haar measure
"""
def
__init__
(
self
,
product
=
False
):
"""
:param product: if True, the matrices will be of the form A \otimes B
where A, B sampled from the Haar measure
"""
self
.
product
=
product
def
states
(
self
,
n_states
,
dims
):
"""
sample states from the Haar measure
:param n_states: number of states
:param dims: dimensions of the subsystems
:return: a set of random states (DMStack), a information dictionary (empty)
"""
if
self
.
product
:
s1
,
_
=
RandomHaar
().
states
(
n_states
,
[
dims
[
0
]])
s2
,
_
=
RandomHaar
().
states
(
n_states
,
[
dims
[
1
]])
return
kron
(
s1
,
s2
),
{}
else
:
dim
=
np
.
product
(
dims
)
states
=
RandomGinibre
.
matrices
(
n_states
,
[
dim
,
1
])
states
=
states
@
dagger
(
states
)
states
/=
np
.
trace
(
states
,
axis1
=
1
,
axis2
=
2
)[:,
None
,
None
]
return
states
,
{}
\ 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