|
17 | 17 | Module containing the Wavefunction object and methods for working with wavefunctions.
|
18 | 18 | """
|
19 | 19 | import itertools
|
20 |
| -import struct |
21 | 20 | import warnings
|
22 | 21 | from typing import Dict, Iterator, List, Optional, Sequence, cast
|
23 | 22 |
|
@@ -81,18 +80,9 @@ def from_bit_packed_string(coef_string: bytes) -> "Wavefunction":
|
81 | 80 | From a bit packed string, unpacks to get the wavefunction
|
82 | 81 | :param coef_string:
|
83 | 82 | """
|
84 |
| - num_octets = len(coef_string) |
85 |
| - |
86 |
| - # Parse the wavefunction |
87 |
| - wf = np.zeros(num_octets // OCTETS_PER_COMPLEX_DOUBLE, dtype=np.cfloat) |
88 |
| - for i, p in enumerate(range(0, num_octets, OCTETS_PER_COMPLEX_DOUBLE)): |
89 |
| - re_be = coef_string[p : p + OCTETS_PER_DOUBLE_FLOAT] |
90 |
| - im_be = coef_string[p + OCTETS_PER_DOUBLE_FLOAT : p + OCTETS_PER_COMPLEX_DOUBLE] |
91 |
| - re = struct.unpack(">d", re_be)[0] |
92 |
| - im = struct.unpack(">d", im_be)[0] |
93 |
| - wf[i] = complex(re, im) |
94 |
| - |
95 |
| - return Wavefunction(wf) |
| 83 | + num_cfloat = len(coef_string) // OCTETS_PER_COMPLEX_DOUBLE |
| 84 | + amplitude_vector = np.ndarray(shape=(num_cfloat,), buffer=coef_string, dtype=">c16") |
| 85 | + return Wavefunction(amplitude_vector) |
96 | 86 |
|
97 | 87 | def __len__(self) -> int:
|
98 | 88 | return len(self.amplitudes).bit_length() - 1
|
|
0 commit comments