Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netket
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vicentini Filippo
netket
Commits
e0da0db6
Commit
e0da0db6
authored
1 year ago
by
Filippo Vicentini
Browse files
Options
Downloads
Patches
Plain Diff
fix breakages in tests
parent
426379d1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
netket/operator/_local_operator.py
+3
-1
3 additions, 1 deletion
netket/operator/_local_operator.py
netket/operator/_local_operator_convert.py
+21
-18
21 additions, 18 deletions
netket/operator/_local_operator_convert.py
with
24 additions
and
19 deletions
netket/operator/_local_operator.py
+
3
−
1
View file @
e0da0db6
...
...
@@ -197,7 +197,9 @@ class LocalOperator(DiscreteOperator):
def
to_pauli_strings
(
self
)
->
"
PauliStrings
"
:
# noqa: F821
"""
Convert to PauliStrings object
"""
return
local_operators_to_pauli_strings
(
self
)
return
local_operators_to_pauli_strings
(
self
.
hilbert
,
self
.
operators
,
self
.
acting_on
,
self
.
constant
,
self
.
dtype
)
def
copy
(
self
,
*
,
dtype
:
Optional
[
DType
]
=
None
):
"""
Returns a copy of the operator, while optionally changing the dtype
...
...
This diff is collapsed.
Click to expand it.
netket/operator/_local_operator_convert.py
+
21
−
18
View file @
e0da0db6
...
...
@@ -128,7 +128,11 @@ def _local_operator_to_pauli_strings(
return
list
(
operators
),
list
(
weights
)
def
local_operators_to_pauli_strings
(
op
):
def
_convert_to_dense
(
m
):
return
m
.
todense
()
if
issparse
(
m
)
else
m
def
local_operators_to_pauli_strings
(
hilbert
,
operators
,
acting_on
,
constant
,
dtype
):
"""
Convert a LocalOperator into PauliStrings
Args:
...
...
@@ -137,19 +141,12 @@ def local_operators_to_pauli_strings(op):
Returns:
PauliStrings
"""
mats
=
op
.
operators
acting_on
=
op
.
acting_on
operators
=
[]
pauli_strings
=
[]
weights
=
[]
if
len
(
op
.
mats
)
>
0
:
def
_convert_to_dense
(
m
):
return
m
.
todense
()
if
issparse
(
m
)
else
m
if
len
(
operators
)
>
0
:
# convert to dense-numpy as we later use jax which does not support sparse.
mats
=
map
(
_convert_to_dense
,
mats
)
mats
=
map
(
_convert_to_dense
,
operators
)
# maximum number of non-identity operators
n_max
=
max
(
list
(
map
(
len
,
acting_on
)))
...
...
@@ -158,18 +155,24 @@ def local_operators_to_pauli_strings(op):
bases_strs
=
_get_paulistrings_till_n
(
n
=
n_max
)
# loop trough operators and convert to Pauli strings by projecting
for
op
,
act
in
zip
(
mats
,
acting_on
):
for
op
,
act
in
zip
(
operators
,
acting_on
):
# convert to dense-numpy as we later use jax which does not support sparse.
op
=
_convert_to_dense
(
op
)
n_paulis
=
len
(
act
)
op_list
,
w_list
=
_local_operator_to_pauli_strings
(
op
,
act
,
bases
[
n_paulis
],
bases_strs
[
n_paulis
],
op
.
hilbert
.
size
op
,
act
,
bases
[
n_paulis
],
bases_strs
[
n_paulis
],
hilbert
.
size
)
operator
s
+=
op_list
pauli_string
s
+=
op_list
weights
+=
w_list
# add the constant
operators
.
append
(
"
I
"
*
op
.
hilbert
.
size
)
weights
.
append
(
op
.
constant
)
# add the constant if it's not zero
if
np
.
abs
(
constant
)
>
1e-13
:
pauli_strings
.
append
(
"
I
"
*
hilbert
.
size
)
weights
.
append
(
constant
)
return
nk
.
operator
.
PauliStrings
(
op
.
hilbert
,
operators
=
operator
s
,
weights
=
weights
,
dtype
=
op
.
dtype
hilbert
,
operators
=
pauli_string
s
,
weights
=
weights
,
dtype
=
dtype
)
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