emu-mps 2.0.1__py3-none-any.whl → 2.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- emu_mps/__init__.py +1 -1
- emu_mps/hamiltonian.py +333 -347
- emu_mps/mpo.py +1 -1
- emu_mps/mps.py +14 -5
- emu_mps/mps_backend.py +3 -1
- emu_mps/mps_backend_impl.py +88 -18
- emu_mps/mps_config.py +29 -0
- emu_mps/optimatrix/__init__.py +14 -3
- emu_mps/optimatrix/optimiser.py +76 -66
- emu_mps/optimatrix/permutations.py +98 -43
- emu_mps/tdvp.py +11 -3
- {emu_mps-2.0.1.dist-info → emu_mps-2.0.3.dist-info}/METADATA +2 -2
- emu_mps-2.0.3.dist-info/RECORD +19 -0
- emu_mps-2.0.1.dist-info/RECORD +0 -19
- {emu_mps-2.0.1.dist-info → emu_mps-2.0.3.dist-info}/WHEEL +0 -0
|
@@ -1,91 +1,146 @@
|
|
|
1
|
-
import
|
|
1
|
+
import torch
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def
|
|
4
|
+
def eye_permutation(n: int) -> torch.Tensor:
|
|
5
5
|
"""
|
|
6
|
-
|
|
6
|
+
Returns toch.tensor([0, 1, 2, .., n-1])
|
|
7
|
+
"""
|
|
8
|
+
return torch.arange(n)
|
|
9
|
+
|
|
7
10
|
|
|
11
|
+
def permute_list(input_list: list, perm: torch.Tensor) -> list:
|
|
12
|
+
"""
|
|
13
|
+
Permutes the input list according to the given permutation.
|
|
8
14
|
Parameters
|
|
9
15
|
-------
|
|
10
16
|
input_list :
|
|
11
17
|
A list to permute.
|
|
12
18
|
permutation :
|
|
13
19
|
A list of indices representing the new order.
|
|
14
|
-
|
|
15
20
|
Returns
|
|
16
21
|
-------
|
|
17
22
|
The permuted list.
|
|
18
|
-
|
|
19
23
|
Example
|
|
20
24
|
-------
|
|
21
|
-
>>> permute_list(['a',
|
|
25
|
+
>>> permute_list(['a','b','c'], torch.tensor([2, 0, 1]))
|
|
22
26
|
['c', 'a', 'b']
|
|
23
27
|
"""
|
|
24
|
-
|
|
25
|
-
permuted_list = [None] * len(input_list)
|
|
26
|
-
for i, p in enumerate(permutation):
|
|
27
|
-
permuted_list[i] = input_list[p]
|
|
28
|
-
return permuted_list
|
|
28
|
+
return [input_list[i] for i in perm.tolist()]
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def
|
|
31
|
+
def permute_tuple(input_tuple: tuple, perm: torch.Tensor) -> tuple:
|
|
32
32
|
"""
|
|
33
|
-
|
|
33
|
+
Permutes the input tuple according to the given permutation.
|
|
34
|
+
Parameters
|
|
35
|
+
-------
|
|
36
|
+
input_tuple :
|
|
37
|
+
A tuple to permute.
|
|
38
|
+
permutation :
|
|
39
|
+
A tuple of indices representing the new order.
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
The permuted tuple.
|
|
43
|
+
Example
|
|
44
|
+
-------
|
|
45
|
+
>>> permute_tuple(('a','b','c'), torch.tensor([2, 0, 1]))
|
|
46
|
+
('c', 'a', 'b')
|
|
47
|
+
"""
|
|
48
|
+
lst_elem = list(input_tuple)
|
|
49
|
+
return tuple(permute_list(lst_elem, perm))
|
|
34
50
|
|
|
35
|
-
Inverts the input permutation list.
|
|
36
51
|
|
|
52
|
+
def permute_string(input_str: str, perm: torch.Tensor) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Permutes the input string according to the given permutation.
|
|
37
55
|
Parameters
|
|
38
56
|
-------
|
|
57
|
+
input_string :
|
|
58
|
+
A string to permute.
|
|
39
59
|
permutation :
|
|
40
|
-
A list of indices representing the order
|
|
41
|
-
|
|
60
|
+
A list of indices representing the new order.
|
|
42
61
|
Returns
|
|
43
62
|
-------
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Example:
|
|
63
|
+
The permuted string.
|
|
64
|
+
Example
|
|
47
65
|
-------
|
|
48
|
-
>>>
|
|
49
|
-
|
|
66
|
+
>>> permute_string("abc", torch.tensor([2, 0, 1]))
|
|
67
|
+
'cab'
|
|
50
68
|
"""
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
inv_perm[permutation] = np.arange(len(permutation))
|
|
54
|
-
return list(inv_perm)
|
|
69
|
+
permuted = permute_list(list(input_str), perm)
|
|
70
|
+
return "".join(permuted)
|
|
55
71
|
|
|
56
72
|
|
|
57
|
-
def
|
|
73
|
+
def inv_permutation(permutation: torch.Tensor) -> torch.Tensor:
|
|
58
74
|
"""
|
|
59
|
-
|
|
75
|
+
inv_permutation(permutation) -> inverted_perm
|
|
60
76
|
|
|
61
|
-
|
|
77
|
+
Inverts the input permutation list.
|
|
62
78
|
|
|
63
79
|
Parameters
|
|
64
80
|
-------
|
|
65
|
-
matrix :
|
|
66
|
-
square matrix nxn
|
|
67
81
|
permutation :
|
|
68
|
-
|
|
82
|
+
A list of indices representing the order
|
|
69
83
|
|
|
70
84
|
Returns
|
|
71
85
|
-------
|
|
72
|
-
|
|
86
|
+
permutation list inverse to the input list
|
|
73
87
|
|
|
74
88
|
Example:
|
|
75
89
|
-------
|
|
76
|
-
>>>
|
|
77
|
-
|
|
78
|
-
... [4, 5, 6],
|
|
79
|
-
... [7, 8, 9]])
|
|
80
|
-
>>> permutation = [1, 0, 2]
|
|
81
|
-
>>> permute_matrix(matrix, permutation)
|
|
82
|
-
array([[5, 4, 6],
|
|
83
|
-
[2, 1, 3],
|
|
84
|
-
[8, 7, 9]])
|
|
90
|
+
>>> inv_permutation(torch.tensor([2, 0, 1]))
|
|
91
|
+
tensor([1, 2, 0])
|
|
85
92
|
"""
|
|
93
|
+
inv_perm = torch.empty_like(permutation)
|
|
94
|
+
inv_perm[permutation] = torch.arange(len(permutation))
|
|
95
|
+
return inv_perm
|
|
96
|
+
|
|
86
97
|
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
def permute_tensor(tensor: torch.Tensor, perm: torch.Tensor) -> torch.Tensor:
|
|
99
|
+
"""
|
|
100
|
+
Permute a 1D or square 2D torch tensor using the given permutation indices.
|
|
101
|
+
For 1D tensors, applies the permutation to the elements.
|
|
102
|
+
For 2D square tensors, applies the same permutation to both rows and columns.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
tensor : torch.Tensor
|
|
107
|
+
A 1D or 2D square tensor to be permuted.
|
|
108
|
+
perm : torch.Tensor
|
|
109
|
+
A 1D tensor of indices specifying the permutation order.
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
torch.Tensor
|
|
114
|
+
A new tensor with elements (1D) or rows and columns (2D) permuted according to `perm`.
|
|
115
|
+
|
|
116
|
+
Raises
|
|
117
|
+
------
|
|
118
|
+
ValueError
|
|
119
|
+
If tensor is not 1D or square 2D.
|
|
120
|
+
|
|
121
|
+
Examples
|
|
122
|
+
--------
|
|
123
|
+
>>> vector = torch.tensor([10, 20, 30])
|
|
124
|
+
>>> perm = torch.tensor([2, 0, 1])
|
|
125
|
+
>>> permute_tensor(vector, perm)
|
|
126
|
+
tensor([30, 10, 20])
|
|
127
|
+
|
|
128
|
+
>>> matrix = torch.tensor([
|
|
129
|
+
... [1, 2, 3],
|
|
130
|
+
... [4, 5, 6],
|
|
131
|
+
... [7, 8, 9]])
|
|
132
|
+
>>> perm = torch.tensor([1, 0, 2])
|
|
133
|
+
>>> permute_tensor(matrix, perm)
|
|
134
|
+
tensor([[5, 4, 6],
|
|
135
|
+
[2, 1, 3],
|
|
136
|
+
[8, 7, 9]])
|
|
137
|
+
"""
|
|
138
|
+
if tensor.ndim == 1:
|
|
139
|
+
return tensor[perm]
|
|
140
|
+
elif tensor.ndim == 2 and tensor.shape[0] == tensor.shape[1]:
|
|
141
|
+
return tensor[perm][:, perm]
|
|
142
|
+
else:
|
|
143
|
+
raise ValueError("Only 1D tensors or square 2D tensors are supported.")
|
|
89
144
|
|
|
90
145
|
|
|
91
146
|
if __name__ == "__main__":
|
emu_mps/tdvp.py
CHANGED
|
@@ -73,12 +73,20 @@ def apply_effective_Hamiltonian(
|
|
|
73
73
|
# this order seems to be pretty balanced, but needs to be
|
|
74
74
|
# revisited when use-cases are more well-known
|
|
75
75
|
state = torch.tensordot(left_bath, state, 1)
|
|
76
|
-
state =
|
|
77
|
-
|
|
76
|
+
state = state.permute(0, 3, 1, 2)
|
|
77
|
+
ham = ham.permute(0, 2, 1, 3)
|
|
78
|
+
state = state.reshape(state.shape[0], state.shape[1], -1).contiguous()
|
|
79
|
+
ham = ham.reshape(-1, ham.shape[2], ham.shape[3]).contiguous()
|
|
80
|
+
state = torch.tensordot(state, ham, 1)
|
|
81
|
+
state = state.permute(0, 2, 1, 3)
|
|
82
|
+
state = state.reshape(state.shape[0], state.shape[1], -1).contiguous()
|
|
83
|
+
right_bath = right_bath.permute(2, 1, 0)
|
|
84
|
+
right_bath = right_bath.reshape(-1, right_bath.shape[2]).contiguous()
|
|
85
|
+
state = torch.tensordot(state, right_bath, 1)
|
|
78
86
|
return state
|
|
79
87
|
|
|
80
88
|
|
|
81
|
-
_TIME_CONVERSION_COEFF = 0.001 # Omega and delta are given in rad
|
|
89
|
+
_TIME_CONVERSION_COEFF = 0.001 # Omega and delta are given in rad/μs, dt in ns
|
|
82
90
|
|
|
83
91
|
|
|
84
92
|
def evolve_pair(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: emu-mps
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.3
|
|
4
4
|
Summary: Pasqal MPS based pulse emulator built on PyTorch
|
|
5
5
|
Project-URL: Documentation, https://pasqal-io.github.io/emulators/
|
|
6
6
|
Project-URL: Repository, https://github.com/pasqal-io/emulators
|
|
@@ -25,7 +25,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
25
25
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
26
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
|
-
Requires-Dist: emu-base==2.0.
|
|
28
|
+
Requires-Dist: emu-base==2.0.3
|
|
29
29
|
Description-Content-Type: text/markdown
|
|
30
30
|
|
|
31
31
|
<div align="center">
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
emu_mps/__init__.py,sha256=wGG0u1wHUcq_MuDjygyApshJY_ome-TZMVggIfHcgns,734
|
|
2
|
+
emu_mps/algebra.py,sha256=ngPtTH-j2ZCBWoaJZXlkUyIlug7dY7Q92gzfnRlpPMA,5485
|
|
3
|
+
emu_mps/custom_callback_implementations.py,sha256=CUs0kW3HRaPE7UeFNQOFbeWJMsz4hS2q4rgS57BBp-A,2411
|
|
4
|
+
emu_mps/hamiltonian.py,sha256=gOPxNOBmk6jRPPjevERuCP_scGv0EKYeAJ0uxooihes,15622
|
|
5
|
+
emu_mps/mpo.py,sha256=1ogQ25GZCwMzZ_m449oGHcYyDKrofBCr1eyzzrIPMhQ,8824
|
|
6
|
+
emu_mps/mps.py,sha256=GIiWxctNmHARgf-PgQc6IHKNCe5HYSnbtlXI6Hc-0wI,20085
|
|
7
|
+
emu_mps/mps_backend.py,sha256=bS83qFxvdoK-c12_1WaPw6O7xUc7vdWifZNHUzNP5sM,2091
|
|
8
|
+
emu_mps/mps_backend_impl.py,sha256=8aPSn6ZGFf4DtTodzajX6WJtQHI9F8eMUN1AbrPzbgw,25611
|
|
9
|
+
emu_mps/mps_config.py,sha256=JCK_frUVyMRJjI0NPU-dpCg-uO3JKeVzQMOLDkQ9XVk,8104
|
|
10
|
+
emu_mps/noise.py,sha256=h4X2EFjoC_Ok0gZ8I9wN77RANXaVehTBbjkcbY_GAmY,784
|
|
11
|
+
emu_mps/observables.py,sha256=7GQDH5kyaVNrwckk2f8ZJRV9Ca4jKhWWDsOCqYWsoEk,1349
|
|
12
|
+
emu_mps/tdvp.py,sha256=0qTw9qhg0WbaAyBgeTpULHrNL0ytj80ZUb1P6GKD7Ww,6172
|
|
13
|
+
emu_mps/utils.py,sha256=BqRJYAcXqprtZVJ0V_j954ON2bhTdtZiaTojsYyrWrg,8193
|
|
14
|
+
emu_mps/optimatrix/__init__.py,sha256=fBXQ7-rgDro4hcaBijCGhx3J69W96qcw5_3mWc7tND4,364
|
|
15
|
+
emu_mps/optimatrix/optimiser.py,sha256=k9suYmKLKlaZ7ozFuIqvXHyCBoCtGgkX1mpen9GOdOo,6977
|
|
16
|
+
emu_mps/optimatrix/permutations.py,sha256=9DDMZtrGGZ01b9F3GkzHR3paX4qNtZiPoI7Z_Kia3Lc,3727
|
|
17
|
+
emu_mps-2.0.3.dist-info/METADATA,sha256=ZU1USoiZ12em9lo4GgAWFiGE0oBT83yXitpm2fx8LvA,3505
|
|
18
|
+
emu_mps-2.0.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
19
|
+
emu_mps-2.0.3.dist-info/RECORD,,
|
emu_mps-2.0.1.dist-info/RECORD
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
emu_mps/__init__.py,sha256=GIR0FJOvmMHby7Vx_Da3w7YqqLpOxa0E8E3poxXsapY,734
|
|
2
|
-
emu_mps/algebra.py,sha256=ngPtTH-j2ZCBWoaJZXlkUyIlug7dY7Q92gzfnRlpPMA,5485
|
|
3
|
-
emu_mps/custom_callback_implementations.py,sha256=CUs0kW3HRaPE7UeFNQOFbeWJMsz4hS2q4rgS57BBp-A,2411
|
|
4
|
-
emu_mps/hamiltonian.py,sha256=LcBs6CKBb643a1e9AAVtQoUfa4L_0dIhLOKecx5OOWs,15864
|
|
5
|
-
emu_mps/mpo.py,sha256=wSonS6i3zEt3yRTgyZ7F6vT51pUKavFcLOxFFphBv8k,8793
|
|
6
|
-
emu_mps/mps.py,sha256=KqAjo-nxgM-xQSg1NFNchwXKoPRcrKuuycFMsWr7iX8,19610
|
|
7
|
-
emu_mps/mps_backend.py,sha256=_3rlg6XeI4fHaDiJRfPL6pDkX9k48hAHKXd8fkvkOFs,2004
|
|
8
|
-
emu_mps/mps_backend_impl.py,sha256=M_do7QRBLAoHfwF_EpyMCb6g7w7BSs5hsPa5UE0z9Zs,22958
|
|
9
|
-
emu_mps/mps_config.py,sha256=89nu5OhNUX31eAeeYvvKnAHegpPVD43jH5Nmp635HVU,6984
|
|
10
|
-
emu_mps/noise.py,sha256=h4X2EFjoC_Ok0gZ8I9wN77RANXaVehTBbjkcbY_GAmY,784
|
|
11
|
-
emu_mps/observables.py,sha256=7GQDH5kyaVNrwckk2f8ZJRV9Ca4jKhWWDsOCqYWsoEk,1349
|
|
12
|
-
emu_mps/tdvp.py,sha256=pIQ2NXA2Mrkp3elhqQbX3pdJVbtKkG3c5r9fFlJo7pI,5755
|
|
13
|
-
emu_mps/utils.py,sha256=BqRJYAcXqprtZVJ0V_j954ON2bhTdtZiaTojsYyrWrg,8193
|
|
14
|
-
emu_mps/optimatrix/__init__.py,sha256=lHWYNeThHp57ZrwTwXd0p8bNvcCv0w_AZ31iCWflBUo,226
|
|
15
|
-
emu_mps/optimatrix/optimiser.py,sha256=7j9_jMQC-Uh2DzdIVB44InRzZO6AbbGhvmm7lC6N3tk,6737
|
|
16
|
-
emu_mps/optimatrix/permutations.py,sha256=JRXGont8B4QgbkV9CzrA0w7uzLgBrmZ1J9aa0G52hPo,1979
|
|
17
|
-
emu_mps-2.0.1.dist-info/METADATA,sha256=aGt2cFa9rplEaJAo8z4J5uoAkqq9WnQIlOhciUc6vkg,3505
|
|
18
|
-
emu_mps-2.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
19
|
-
emu_mps-2.0.1.dist-info/RECORD,,
|
|
File without changes
|