-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance testing of degeneracy checking for PT generation (#130)
* test outline * Degenecary performance tests implmented * correct sys path insert --------- Co-authored-by: Piper Fowler-Wright <piperfw@gmail.com>
- Loading branch information
1 parent
8d60437
commit 2aaa779
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2024 The TEMPO Collaboration | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Skript to plot the PT-TEBD performance analysis results. | ||
""" | ||
import sys | ||
sys.path.insert(0, '.') | ||
|
||
import oqupy.operators as op | ||
import oqupy | ||
from operator import itemgetter | ||
import dill | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
|
||
plt.style.use('./tests/performance/analysis/matplotlib_style.mplstyle') | ||
|
||
with open("./tests/data/performance_results/pt_degen.pkl", 'rb') as f: | ||
all_results = dill.load(f) | ||
|
||
styles = ['-', '--', '-.', ':'] | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
# PLOT | ||
# ----------------------------------------------------------------------------- | ||
|
||
result_list = all_results[0] | ||
|
||
unique_wall_times = [] | ||
unique_spin_array = [] | ||
non_unique_wall_times = [] | ||
non_unique_spin_array = [] | ||
|
||
for results in result_list: | ||
|
||
unique_wall_times.extend(list(map(itemgetter('walltime'), | ||
filter(itemgetter('unique'), | ||
results)))) | ||
unique_spin_array.extend(list(map(itemgetter('spin_size'), | ||
filter(itemgetter('unique'), | ||
results)))) | ||
non_unique_wall_times.extend(list(map(itemgetter('walltime'), | ||
filter(lambda x: not x.get('unique'), | ||
results)))) | ||
non_unique_spin_array.extend(list(map(itemgetter('spin_size'), | ||
filter(lambda x: not x.get('unique'), | ||
results)))) | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot(unique_spin_array, unique_wall_times, label="on") | ||
ax.plot(non_unique_spin_array, non_unique_wall_times, label="off") | ||
ax.legend(title="Unique") | ||
ax.set_yscale('log') | ||
ax.set_ylabel("Walltime (s)") | ||
ax.set_xlabel("Spin size") | ||
fig.savefig("./tests/data/plots/pt-degen-results.pdf") | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2024 The TEMPO Collaboration | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Script to run the PT performance analysis. | ||
""" | ||
|
||
import sys | ||
sys.path.insert(0,'.') | ||
|
||
import dill | ||
|
||
from tests.performance.run_all import run_all | ||
from tests.performance.pt_degen import ALL_TESTS | ||
|
||
# -- computation -------------------------------------------------------------- | ||
|
||
all_results = run_all(ALL_TESTS) | ||
with open('./tests/data/performance_results/pt_degen.pkl', 'wb') as f: | ||
dill.dump(all_results, f) | ||
|
||
print("... all done.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright 2020 The TEMPO Collaboration | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Performance test for degeneracy checking in process tensor generation | ||
""" | ||
import sys | ||
from time import perf_counter | ||
sys.path.insert(0,'.') | ||
|
||
import numpy as np | ||
|
||
import oqupy | ||
|
||
|
||
def pt_degen_performance_A(spin_size, unique): | ||
p = {'alpha': 0.1, | ||
'zeta': 1.0, | ||
'temperature': 0.0, | ||
'cutoff': 1.0, | ||
'cutoff_type': 'exponential', | ||
'dt': 0.2, | ||
'epsrel': 1e-6, | ||
'tcut': 2.0, | ||
'end_t': 2.0} | ||
|
||
correlations = oqupy.PowerLawSD(alpha=p['alpha'], | ||
zeta=p['zeta'], | ||
cutoff=p['cutoff'], | ||
cutoff_type=p['cutoff_type'], | ||
temperature=p['temperature']) | ||
|
||
coupling_op = np.diag( | ||
np.arange(spin_size, -spin_size+0.1, -1, dtype=float)) | ||
|
||
bath = oqupy.Bath(coupling_operator=coupling_op, | ||
correlations=correlations) | ||
pt_tempo_parameters = oqupy.TempoParameters( | ||
dt=p['dt'], tcut=p['tcut'], epsrel=p['epsrel']) | ||
result = {} | ||
t0 = perf_counter() | ||
oqupy.pt_tempo_compute(bath=bath, | ||
start_time=0.0, | ||
end_time=p['end_t'], | ||
parameters=pt_tempo_parameters, | ||
unique=unique) | ||
result['walltime'] = perf_counter()-t0 | ||
result['unique'] = unique | ||
result['spin_size'] = spin_size | ||
return result | ||
|
||
|
||
parameters_unique = [[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5], | ||
[True]] | ||
parameters_non_unique = [[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5], | ||
[False]] | ||
|
||
ALL_TESTS = [(pt_degen_performance_A, [parameters_unique, parameters_non_unique]), | ||
] | ||
|
||
REQUIRED_PTS = [] |