Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MeanFi
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
Service Desk
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
Quantum Tinkerer
MeanFi
Merge requests
!4
Couldn't fetch the linked file.
Interface refactoring
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Interface refactoring
interface-refactoring
into
main
Overview
66
Commits
140
Pipelines
46
Changes
1
Merged
Kostas Vilkelis
requested to merge
interface-refactoring
into
main
1 year ago
Overview
5
Commits
140
Pipelines
46
Changes
1
Expand
Find a design which is more intuitive and minimal.
0
0
Merge request reports
Viewing commit
9c4bf187
Show latest version
1 file
+
41
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
9c4bf187
add minimal example and function for hopping dict to flat and back
· 9c4bf187
Johanna Zijderveld
authored
1 year ago
examples/dict_to_flat.py
0 → 100644
+
41
−
0
Options
# %%
import
numpy
as
np
from
codes.kwant_helper
import
utils
from
codes
import
kwant_examples
# %%
# Example hopping dictionary to use:
graphene_builder
,
int_builder
=
kwant_examples
.
graphene_extended_hubbard
()
tb_model
=
utils
.
builder2tb_model
(
graphene_builder
)
# %%
def
hop_dict_to_flat
(
hop_dict
):
sorted_vals
=
np
.
array
(
list
(
hop_dict
.
values
()))[
np
.
lexsort
(
np
.
array
(
list
(
hop_dict
.
keys
())).
T
)
]
flat
=
sorted_vals
[...,
*
np
.
triu_indices
(
sorted_vals
.
shape
[
-
1
])].
flatten
()
return
flat
def
flat_to_hop_dict
(
flat
,
shape
,
hop_dict_keys
):
matrix
=
np
.
zeros
(
shape
,
dtype
=
complex
)
matrix
[...,
*
np
.
triu_indices
(
shape
[
-
1
])]
=
flat
.
reshape
(
*
shape
[:
-
2
],
-
1
)
indices
=
np
.
arange
(
shape
[
-
1
])
diagonal
=
matrix
[...,
indices
,
indices
]
matrix
+=
np
.
moveaxis
(
matrix
[
-
1
::
-
1
],
-
1
,
-
2
).
conj
()
matrix
[...,
indices
,
indices
]
-=
diagonal
hop_dict_keys
=
np
.
array
(
list
(
hop_dict_keys
))
sorted_keys
=
hop_dict_keys
[
np
.
lexsort
(
hop_dict_keys
.
T
)]
hop_dict
=
dict
(
zip
(
map
(
tuple
,
sorted_keys
),
matrix
))
return
hop_dict
# %%
flat
=
hop_dict_to_flat
(
tb_model
)
shape
=
(
len
(
tb_model
.
keys
()),
*
list
(
tb_model
.
values
())[
0
].
shape
)
hop_dict
=
flat_to_hop_dict
(
flat
,
shape
,
tb_model
.
keys
())
# %%
Loading