In [1]:
BELLOP = 'chsh'
In [2]:
import matplotlib.pyplot as plt
import numpy as np
import json, csv
from functools import partial
#%config InlineBackend.figure_formats = ['svg']
In [3]:
import os
EXPORTDIR = 'data_export'
FIGUREDIR = 'figures'
os.makedirs(EXPORTDIR, exist_ok=True)
os.makedirs(FIGUREDIR, exist_ok=True)
def path_fig(filename):
    return os.path.join(FIGUREDIR, filename)
SAVEFIG_KWARGS = {'metadata':{'CreationDate':None}}
def path_export(filename):
    return os.path.join(EXPORTDIR, filename)
In [4]:
from IPython.display import Markdown as md, display, HTML
import html
import warnings
def report_error(message):
    display(md('<b style="font-size:5rem; color:red; line-height:5rem">{}</b>'.format(
        html.escape(message)
    )))

display(md(f'# Results for {BELLOP.upper()}'))

Results for CHSH

In [5]:
FIELDS = [BELLOP,'cond_entropy','cond_entropy_bound']

bell_val_bounds = {}
entropies_bounds = {}

with open(path_export(f'witness_bounds_{BELLOP}.tsv'), 'w', newline='') as outfile:
    csvwr = csv.writer(outfile, delimiter='\t')
    csvwr.writerow(FIELDS)
    for bound in range(0, 105, 5):
        entropies, bell_val = [], []
        bound /= 100
        with open(f'out_bell/bound_witnesses_{BELLOP}.{bound:.2f}.jsonl') as f:
            last = None
            for l in f:
                d = json.loads(l)
                entropies.append(d['cond_entropy'])
                bell_val.append(d[BELLOP])
                last = d
            if last:
                csvwr.writerow((last[BELLOP], last['cond_entropy'], -bound))
        bell_val_bounds[-bound] = bell_val
        entropies_bounds[-bound] = entropies
In [6]:
fig = plt.figure(figsize=(8,7))
for bound, bell_val in reversed(bell_val_bounds.items()):
    plt.plot(bell_val, label=str(bound))
plt.title(f'maximized {BELLOP.upper()}')
plt.xlabel('iterations (witness count)')
plt.ylabel(BELLOP.upper())
plt.grid()
plt.legend()
plt.show(fig)
fig.savefig(path_fig(f'witn_{BELLOP}_val.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [7]:
fig = plt.figure(figsize=(8,7))
for bound, entropies in entropies_bounds.items():
    plt.plot(entropies, label=str(bound))
plt.title(f'Entropies for maximized {BELLOP.upper()}')
plt.xlabel('iterations (witness count)')
plt.ylabel('conditional entropy')
plt.grid()
plt.legend()
plt.show(fig)
fig.savefig(path_fig(f'witn_{BELLOP}_entr.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)

Analiza wników seesaw z apkroksymacjami półokreślonymi entropii (apx $\pm$1)

In [8]:
def extract_by_keys(data, keys):
    return [ data[key] for key in keys ]

def read_data(path, extract_funcs):
    rows = []
    with open(path, 'r') as f:
        for line in f:
            try:
                row = []
                data = json.loads(line)
                for func in extract_funcs:
                    row += (
                            matrix_to_octave_str(value) if isinstance(value, list) else value
                            for value in func(data)
                            )
                rows.append(row)
            except json.JSONDecodeError as e:
                warnings.warn(f"Failed to decode line {len(rows)+1} in {path}: {e!r}")
                break
    return rows

def fields(bellop):
    return [bellop, 'cond_entropy','s_bound']

DATA_PATH_FMT = 'out_bell/{bellop}_seesaw_{bound}_{apx}.jsonl'
EXPECTED_ROWS = 100

incomplete_paths = []

def plot(bound, bellop=BELLOP):
    fig, ax = plt.subplots(figsize=(12, 7))
    ax.grid(True)
    handles = []
    stats = {'s_bound': bound}
    rowsum = 0
    for i, apx in enumerate((+1, -1)):
        data_path = DATA_PATH_FMT.format(bound=bound, apx=apx, bellop=bellop)
        try:
            rows = read_data(data_path,
                         [partial(extract_by_keys, keys=fields(bellop))])
        except FileNotFoundError as e:
            warnings.warn(f'{data_path}: {FileNotFoundError!r}')
            rows = []
        rowsum += len(rows)
        if len(rows) != EXPECTED_ROWS:
            incomplete_paths.append((data_path, len(rows)))
        if len(rows) == 0:
            report_error(f"Empty file: {data_path}")
            continue
        elif len(rows) < EXPECTED_ROWS:
            report_error(f"Only {len(rows)} lines read, but expected {EXPECTED_ROWS}: {data_path}")
        elif len(rows) > EXPECTED_ROWS:
            report_error(f"More lines ({len(rows)}) than expected ({EXPECTED_ROWS}): {data_path}")
        bell_vals, cond_entropy, s_bound = zip(*rows)
        if not (np.array(s_bound) == bound).all():
            print(s_bound, 'should be equal', bound)
        stats[f'max_entr_{apx:+}'], stats[f'min_entr_{apx:+}'] = max(cond_entropy), min(cond_entropy)
        stats[f'max_{bellop}_{apx:+}'], stats[f'min_{bellop}_{apx:+}'] = max(bell_vals), min(bell_vals)
        handles[i:i] = ax.plot(cond_entropy, bell_vals, '.', markersize=4., label=f'{bound} apx={apx}')
    lim = plt.ylim()
    ax.vlines(bound, -10, 10)
    plt.ylim(lim)
    ax.legend(handles=handles)
    ax.set_ylabel(bellop.upper())
    ax.set_xlabel('conditional entropy')
    if rowsum != 0:
        plt.show(fig)
    plt.close(fig)
    return stats
In [9]:
records = []
for b in np.linspace(-1,0,21).round(12):
    records.append(plot(b))
In [10]:
from pprint import pprint
pprint(incomplete_paths)
[]
In [11]:
if len(incomplete_paths) > 0:
       report_error('Incomplete files:')
print(' '.join(path for path, count in incomplete_paths))

In [12]:
import pandas as pd
stats = pd.DataFrame.from_records(records)
In [13]:
pd.set_option("precision", 7)
stats
Out[13]:
s_bound max_entr_+1 min_entr_+1 max_chsh_+1 min_chsh_+1 max_entr_-1 min_entr_-1 max_chsh_-1 min_chsh_-1
0 -1.00 -1.0000000 -1.0000000 2.8284271 2.8284270 -1.0000000 -1.0000000 2.8284271 2.8284271
1 -0.95 -0.9499921 -0.9499921 2.8144210 2.8144209 -0.9500091 -0.9500091 2.8144265 2.8144265
2 -0.90 -0.8999924 -0.8999924 2.7967053 2.7967052 -0.9000087 -0.9000087 2.7967115 2.7967114
3 -0.85 -0.8499927 -0.8499928 2.7767509 2.7767508 -0.8500082 -0.8500082 2.7767574 2.7767573
4 -0.80 -0.7999931 -0.7999932 2.7549592 2.7549591 -0.8000079 -0.8000079 2.7549659 2.7549658
5 -0.75 -0.7499934 -0.7499935 2.7315296 2.7315296 -0.7500074 -0.7500075 2.7315364 2.7315363
6 -0.70 -0.6999937 -0.6999938 2.7065774 2.7065772 -0.7000071 -0.7000072 2.7065842 2.7065841
7 -0.65 -0.6499940 -0.6499940 2.6801724 2.6801724 -0.6500068 -0.6500068 2.6801794 2.6801793
8 -0.60 -0.5999943 -0.5999943 2.6523573 2.6523572 -0.6000064 -0.6000066 2.6523643 2.6523641
9 -0.55 -0.5499945 -0.5499946 2.6231550 2.6231549 -0.5500062 -0.5500062 2.6231619 2.6231618
10 -0.50 -0.4999948 -0.4999949 2.5925744 2.5925743 -0.5000058 -0.5000059 2.5925813 2.5925812
11 -0.45 -0.4499951 -0.4499952 2.5606130 2.5606128 -0.4500055 -0.4500056 2.5606198 2.5606196
12 -0.40 -0.3999954 -0.3999956 2.5272585 2.5272583 -0.4000051 -0.4000052 2.5272651 2.5272650
13 -0.35 -0.3499956 -0.3499958 2.4924900 2.4924896 -0.3500048 -0.3500048 2.4924964 2.4924963
14 -0.30 -0.2999959 -0.2999961 2.4562783 2.4562781 -0.3000045 -0.3000045 2.4562846 2.4562845
15 -0.25 -0.2499962 -0.2499963 2.4185863 2.4185861 -0.2500042 -0.2500042 2.4185924 2.4185923
16 -0.20 -0.1999966 -0.1999967 2.3793685 2.3793684 -0.2000038 -0.2000038 2.3793744 2.3793742
17 -0.15 -0.1499968 -0.1499969 2.3385710 2.3385706 -0.1500035 -0.1500036 2.3385765 2.3385764
18 -0.10 -0.0999970 -0.0999972 2.2961302 2.2961298 -0.1000032 -0.1000033 2.2961355 2.2961354
19 -0.05 -0.0499973 -0.0499977 2.2519730 2.2519718 -0.0500029 -0.0500029 2.2519777 2.2519775
20 0.00 0.0000025 0.0000021 2.2060134 2.2060125 -0.0000027 -0.0000028 2.2060181 2.2060178
In [14]:
diffs = stats[["s_bound"]].copy()
for apx in +1, -1:
    diffs[f's_max_diff_{apx:+}'] = stats[f'max_entr_{apx:+}'] - stats[f'min_entr_{apx:+}']
    diffs[f'{BELLOP}_max_diff_{apx:+}'] = stats[f'max_{BELLOP}_{apx:+}'] - stats[f'min_{BELLOP}_{apx:+}']

def both_apx(fmtstr, bellop=BELLOP):
    return [fmtstr.format(apx=+1, bellop=bellop), fmtstr.format(apx=-1, bellop=bellop)]

diffs[f's_max_diff'] = (
    stats[both_apx('max_entr_{apx:+}')].max(axis=1)
    - stats[both_apx('min_entr_{apx:+}')].min(axis=1)
)
diffs[f'{BELLOP}_max_diff'] = (
    stats[both_apx('max_{bellop}_{apx:+}')].max(axis=1)
    - stats[both_apx('min_{bellop}_{apx:+}')].min(axis=1)
)
pd.set_option("precision", 5)
diffs
Out[14]:
s_bound s_max_diff_+1 chsh_max_diff_+1 s_max_diff_-1 chsh_max_diff_-1 s_max_diff chsh_max_diff
0 -1.00 1.82194e-09 8.36910e-08 4.28480e-09 4.80962e-08 4.28480e-09 8.54886e-08
1 -0.95 2.91478e-08 4.52218e-08 3.81046e-08 6.18785e-08 1.70871e-05 5.61651e-06
2 -0.90 3.37291e-08 5.26271e-08 5.76788e-08 6.18411e-08 1.63705e-05 6.22543e-06
3 -0.85 4.95073e-08 5.38547e-08 1.13426e-09 6.95786e-08 1.54670e-05 6.52753e-06
4 -0.80 8.18405e-08 7.98031e-08 1.71871e-09 5.20466e-08 1.48108e-05 6.76668e-06
5 -0.75 1.06896e-07 7.10106e-08 5.53403e-08 7.92471e-08 1.40917e-05 6.85852e-06
6 -0.70 1.54017e-07 1.50609e-07 5.93636e-08 7.30767e-08 1.34689e-05 6.98585e-06
7 -0.65 3.56471e-08 8.18457e-08 3.89306e-08 9.86400e-08 1.28398e-05 7.02801e-06
8 -0.60 1.54849e-09 8.94139e-08 1.14100e-07 1.36102e-07 1.22341e-05 7.04276e-06
9 -0.55 9.08960e-08 1.02306e-07 1.56679e-09 7.90492e-08 1.16346e-05 7.02202e-06
10 -0.50 1.31179e-07 1.80888e-07 1.15865e-07 1.44999e-07 1.11002e-05 7.04591e-06
11 -0.45 1.43066e-07 1.66696e-07 1.10898e-07 2.12490e-07 1.04843e-05 6.96631e-06
12 -0.40 1.98366e-07 2.20542e-07 9.58067e-08 1.67487e-07 9.85514e-06 6.85507e-06
13 -0.35 2.04884e-07 4.46685e-07 4.10355e-08 1.07900e-07 9.19100e-06 6.85697e-06
14 -0.30 1.84998e-07 2.73099e-07 1.19063e-08 9.44540e-08 8.55418e-06 6.52331e-06
15 -0.25 8.11090e-08 1.73412e-07 4.39215e-08 1.21985e-07 7.98625e-06 6.26073e-06
16 -0.20 1.49169e-07 1.01933e-07 1.52451e-09 1.21122e-07 7.28268e-06 5.94425e-06
17 -0.15 1.34944e-07 3.92634e-07 2.36652e-08 1.38668e-07 6.79542e-06 5.92924e-06
18 -0.10 1.47606e-07 3.68247e-07 1.94662e-08 1.01674e-07 6.23250e-06 5.65197e-06
19 -0.05 4.75143e-07 1.16940e-06 1.34493e-09 1.45010e-07 5.67307e-06 5.85066e-06
20 0.00 3.43244e-07 8.62159e-07 1.39169e-07 2.88767e-07 5.28232e-06 5.59649e-06
In [15]:
fig, (ax, ax2) = plt.subplots(nrows=2, figsize=(12, 24), dpi=150)
hp1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_+1'], 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1'], '.-', label=f'max_{BELLOP}[apx=-1]')
ax.legend(handles=[hp1,hm1])
ax.grid(True)
ax2.grid(True)
h3diff, = ax2.plot(diffs['s_bound'], diffs[f'{BELLOP}_max_diff'], '+-b', label=f'max_{BELLOP}_diff')
hdiff, = ax2.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1']-stats[f'max_{BELLOP}_+1'], '.-g', label=f'max_{BELLOP}[apx=-1]-max_{BELLOP}[apx=+1]')
h2diff, = ax2.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1']-stats[f'min_{BELLOP}_+1'], 'x-r', label=f'max_{BELLOP}[apx=-1]-min_{BELLOP}[apx=+1]')
ax2.legend(handles=[hdiff,h2diff, h3diff])
plt.show(fig)
fig.savefig(path_fig(f'seesaw_apx_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [16]:
export = stats[['s_bound', f'max_{BELLOP}_-1', f'max_{BELLOP}_+1']].copy()
export[f'max_{BELLOP}_is_-1'] = export[[f'max_{BELLOP}_-1', f'max_{BELLOP}_+1']].max(axis=1) == export[f'max_{BELLOP}_-1']
pd.set_option("precision", 8)
export
Out[16]:
s_bound max_chsh_-1 max_chsh_+1 max_chsh_is_-1
0 -1.00 2.82842711 2.82842711 True
1 -0.95 2.81442655 2.81442098 True
2 -0.90 2.79671145 2.79670528 True
3 -0.85 2.77675736 2.77675088 True
4 -0.80 2.75496590 2.75495921 True
5 -0.75 2.73153642 2.73152963 True
6 -0.70 2.70658420 2.70657737 True
7 -0.65 2.68017938 2.68017244 True
8 -0.60 2.65236429 2.65235733 True
9 -0.55 2.62316193 2.62315501 True
10 -0.50 2.59258131 2.59257445 True
11 -0.45 2.56061978 2.56061298 True
12 -0.40 2.52726514 2.52725851 True
13 -0.35 2.49249644 2.49249003 True
14 -0.30 2.45628460 2.45627835 True
15 -0.25 2.41859237 2.41858629 True
16 -0.20 2.37937436 2.37936851 True
17 -0.15 2.33857652 2.33857098 True
18 -0.10 2.29613547 2.29613019 True
19 -0.05 2.25197769 2.25197300 True
20 0.00 2.20601814 2.20601340 True
In [17]:
export.to_csv(path_export(f'seesaw_max_export_{BELLOP}.tsv'), sep='\t')

Porównanie

In [18]:
witness_bounds = pd.read_csv(path_export(f'witness_bounds_{BELLOP}.tsv'), sep='\t')
In [19]:
FIXEDM_FIELDS = fields(BELLOP)+['apx']
fixedm = read_data(f'out_bell/fixedm_{BELLOP}_entr_approx_states.jsonl', [partial(extract_by_keys, keys=FIXEDM_FIELDS)])
foundm = read_data(f'out_bell/foundm/fixedm_{BELLOP}_entr_approx_states.jsonl', [partial(extract_by_keys, keys=FIXEDM_FIELDS)])
In [20]:
witness_bounds
Out[20]:
chsh cond_entropy cond_entropy_bound
0 2.20601553 -1.30317979e-12 -0.00
1 2.25197508 -5.00000000e-02 -0.05
2 2.29613273 -1.00000000e-01 -0.10
3 2.33857361 -1.50000000e-01 -0.15
4 2.37937132 -2.00000000e-01 -0.20
5 2.41858921 -2.50000000e-01 -0.25
6 2.45628132 -3.00000000e-01 -0.30
7 2.49249306 -3.50000000e-01 -0.35
8 2.52726163 -4.00000000e-01 -0.40
9 2.56061618 -4.50000000e-01 -0.45
10 2.59257765 -5.00000000e-01 -0.50
11 2.62315827 -5.50000000e-01 -0.55
12 2.65236059 -6.00000000e-01 -0.60
13 2.68017573 -6.50000000e-01 -0.65
14 2.70658057 -7.00000000e-01 -0.70
15 2.73153282 -7.50000000e-01 -0.75
16 2.75496234 -8.00000000e-01 -0.80
17 2.77675393 -8.50000000e-01 -0.85
18 2.79670818 -9.00000000e-01 -0.90
19 2.81442359 -9.50000000e-01 -0.95
In [21]:
fixedm = pd.DataFrame.from_records(fixedm, columns=FIXEDM_FIELDS)
fixedm_p1, fixedm_m1 = fixedm[fixedm['apx']==+1], fixedm[fixedm['apx']==-1]
foundm = pd.DataFrame.from_records(foundm, columns=FIXEDM_FIELDS)
foundm_p1, foundm_m1 = foundm[foundm['apx']==+1], foundm[foundm['apx']==-1]

Łączenie DataFrame z samym sobą

In [22]:
pd.set_option("precision", 10)
fixedm_p1.merge(fixedm_m1, on='s_bound', suffixes=('_p1', '_m1'))
Out[22]:
chsh_p1 cond_entropy_p1 s_bound apx_p1 chsh_m1 cond_entropy_m1 apx_m1
0 2.8284270764 -0.9999999782 -1.00 1 2.8284270761 -0.9999999780 -1
1 2.8144210419 -0.9499922233 -0.95 1 2.8144210419 -0.9499922232 -1
2 2.7967052872 -0.8999923611 -0.90 1 2.7967052996 -0.8999923939 -1
3 2.7767508984 -0.8499927457 -0.85 1 2.7767508984 -0.8499927457 -1
4 2.7549592125 -0.7999930950 -0.80 1 2.7549592126 -0.7999930950 -1
5 2.7315296276 -0.7499934072 -0.75 1 2.7315296276 -0.7499934072 -1
6 2.7065773346 -0.6999937106 -0.70 1 2.7065773345 -0.6999937103 -1
7 2.6801725806 -0.6499941939 -0.65 1 2.6801725806 -0.6499941939 -1
8 2.6523573482 -0.5999943180 -0.60 1 2.6523573482 -0.5999943180 -1
9 2.6231550196 -0.5499945561 -0.55 1 2.6231550196 -0.5499945562 -1
10 2.5925746860 -0.4999952643 -0.50 1 2.5925746859 -0.4999952643 -1
11 2.5606129848 -0.4499951031 -0.45 1 2.5606129848 -0.4499951031 -1
12 2.5272584806 -0.3999953755 -0.40 1 2.5272584806 -0.3999953755 -1
13 2.4924899809 -0.3499956685 -0.35 1 2.4924899809 -0.3499956685 -1
14 2.4562783130 -0.2999959368 -0.30 1 2.4562783103 -0.2999959331 -1
15 2.4185862993 -0.2499962152 -0.25 1 2.4185862994 -0.2499962152 -1
16 2.3793685588 -0.1999965444 -0.20 1 2.3793685588 -0.1999965444 -1
17 2.3385710200 -0.1499968839 -0.15 1 2.3385710200 -0.1499968839 -1
18 2.2961301737 -0.0999970430 -0.10 1 2.2961301901 -0.0999970620 -1
19 2.2519730207 -0.0499977180 -0.05 1 2.2519730207 -0.0499977180 -1
20 2.2060132721 0.0000024093 0.00 1 2.2060132721 0.0000024093 -1
In [23]:
# i z innym df
fixedm_p1.merge(witness_bounds, left_on='s_bound', right_on='cond_entropy_bound', suffixes=('_p1', '_m1'))
Out[23]:
chsh_p1 cond_entropy_p1 s_bound apx chsh_m1 cond_entropy_m1 cond_entropy_bound
0 2.8144210419 -0.9499922233 -0.95 1 2.8144235858 -9.5000000002e-01 -0.95
1 2.7967052872 -0.8999923611 -0.90 1 2.7967081810 -9.0000000000e-01 -0.90
2 2.7767508984 -0.8499927457 -0.85 1 2.7767539341 -8.5000000000e-01 -0.85
3 2.7549592125 -0.7999930950 -0.80 1 2.7549623389 -8.0000000000e-01 -0.80
4 2.7315296276 -0.7499934072 -0.75 1 2.7315328195 -7.5000000001e-01 -0.75
5 2.7065773346 -0.6999937106 -0.70 1 2.7065805663 -7.0000000000e-01 -0.70
6 2.6801725806 -0.6499941939 -0.65 1 2.6801757312 -6.5000000000e-01 -0.65
7 2.6523573482 -0.5999943180 -0.60 1 2.6523605892 -6.0000000000e-01 -0.60
8 2.6231550196 -0.5499945561 -0.55 1 2.6231582745 -5.5000000000e-01 -0.55
9 2.5925746860 -0.4999952643 -0.50 1 2.5925776526 -5.0000000001e-01 -0.50
10 2.5606129848 -0.4499951031 -0.45 1 2.5606161832 -4.5000000000e-01 -0.45
11 2.5272584806 -0.3999953755 -0.40 1 2.5272616307 -4.0000000000e-01 -0.40
12 2.4924899809 -0.3499956685 -0.35 1 2.4924930552 -3.5000000000e-01 -0.35
13 2.4562783130 -0.2999959368 -0.30 1 2.4562813153 -3.0000000000e-01 -0.30
14 2.4185862993 -0.2499962152 -0.25 1 2.4185892097 -2.5000000000e-01 -0.25
15 2.3793685588 -0.1999965444 -0.20 1 2.3793713239 -2.0000000000e-01 -0.20
16 2.3385710200 -0.1499968839 -0.15 1 2.3385736144 -1.5000000000e-01 -0.15
17 2.2961301737 -0.0999970430 -0.10 1 2.2961327339 -1.0000000000e-01 -0.10
18 2.2519730207 -0.0499977180 -0.05 1 2.2519750800 -5.0000000000e-02 -0.05
19 2.2060132721 0.0000024093 0.00 1 2.2060155322 -1.3031797863e-12 -0.00

Wspólny wykres

In [24]:
fig, ax = plt.subplots(figsize=(12, 12), dpi=150)
hwitn, = ax.plot(witness_bounds['cond_entropy_bound'], witness_bounds[BELLOP], 'r-', marker=5, label=f'max_{BELLOP} with witness (fixed meas.)')
hfp1, = ax.plot(fixedm_p1['s_bound'], fixedm_p1[BELLOP], 'c-', marker=6, label=f'max_{BELLOP} apx=+1 fixed mesurements')
hfm1, = ax.plot(fixedm_m1['s_bound'], fixedm_m1[BELLOP], 'b-', marker=7, label=f'max_{BELLOP} apx=-1 fixed mesurements')
hp1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_+1'], 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1'], '.-', label=f'max_{BELLOP}[apx=-1]')
fndp1, = ax.plot(foundm_p1['s_bound'], foundm_p1[BELLOP], '|--', label=f'max_{BELLOP} apx=+1 found meas.')
fndm1, = ax.plot(foundm_m1['s_bound'], foundm_m1[BELLOP], '|--', label=f'max_{BELLOP} apx=-1 found meas.')

ax.legend(handles=[hp1,hm1, hwitn, hfp1,hfm1, fndp1, fndm1])
ax.grid(True)
plt.show(fig)
fig.savefig(path_fig(f'compare_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [25]:
diffbase = fixedm_p1

def diff(df, key_eq, key_val):
    merged = diffbase.merge(df, left_on='s_bound', right_on=key_eq, suffixes=('_base', ''))
    return merged['s_bound'], merged[key_val]-merged[f'{BELLOP}_base' if BELLOP in df.columns else BELLOP]


fig, ax = plt.subplots(figsize=(12, 12), dpi=150)


hwitn, = ax.plot(*diff(witness_bounds, 'cond_entropy_bound', BELLOP), 'r-', marker=5, label=f'max_{BELLOP} with witness (fixed meas.)')
hfp1, = ax.plot(*diff(fixedm_p1, 's_bound', BELLOP), 'c-', marker=6, label=f'max_{BELLOP} apx=+1 fixed mesurements')
hfm1, = ax.plot(*diff(fixedm_m1, 's_bound', BELLOP), 'b-', marker=7, label=f'max_{BELLOP} apx=-1 fixed mesurements')
hp1, = ax.plot(*diff(stats, 's_bound', f'max_{BELLOP}_+1'), 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(*diff(stats, 's_bound', f'max_{BELLOP}_-1'), '.-', label=f'max_{BELLOP}[apx=-1]')

from matplotlib.ticker import SymmetricalLogLocator
plt.yscale('symlog', linthresh=1e-4)
ax.yaxis.set_minor_locator(SymmetricalLogLocator(linthresh=1e-4, base=10, subs=range(2,10)))
ax.tick_params(which='minor', length=4)
ax.legend(handles=[hp1,hm1, hwitn, hfp1,hfm1])
ax.grid(True)
plt.title(f'Value minus corresponding value of [max_{BELLOP} apx=-1 fixed mesurements]')
plt.show(fig)
fig.savefig(path_fig(f'diff_fixedm_p1_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)

^ UWAGA! Powyższy wykres: oś Y jest częściowo w skali logarytmicznej, a częściowo w liniowej! ^

In [26]:
# Seesaw difference to fixedm_p1
s_bound, seesaw_p1_diff = diff(stats, 's_bound', f'max_{BELLOP}_+1')
s_bound2, seesaw_m1_diff = diff(stats, 's_bound', f'max_{BELLOP}_-1')
pd.DataFrame({'s_bound':s_bound, 'seesaw_p1_diff':seesaw_p1_diff, 'seesaw_m1_diff':seesaw_m1_diff, 's_bound2':s_bound2})
Out[26]:
s_bound seesaw_p1_diff seesaw_m1_diff s_bound2
0 -1.00 3.2533828964e-08 0.0000000343 -1.00
1 -0.95 -6.6568218049e-08 0.0000055047 -0.95
2 -0.90 -7.3780164200e-09 0.0000061654 -0.90
3 -0.85 -1.4550230354e-08 0.0000064591 -0.85
4 -0.80 6.3684613139e-11 0.0000066869 -0.80
5 -0.75 6.0713611916e-10 0.0000067881 -0.75
6 -0.70 3.3250691978e-08 0.0000068685 -0.70
7 -0.65 -1.4196198084e-07 0.0000068042 -0.65
8 -0.60 -1.5580845947e-08 0.0000069378 -0.60
9 -0.55 -1.0435758480e-08 0.0000069093 -0.55
10 -0.50 -2.4061281900e-07 0.0000066244 -0.50
11 -0.45 -6.7506014112e-09 0.0000067929 -0.45
12 -0.40 2.9839644533e-08 0.0000066644 -0.40
13 -0.35 4.5479144450e-08 0.0000064558 -0.35
14 -0.30 3.3058807247e-08 0.0000062833 -0.30
15 -0.25 -1.1661577926e-08 0.0000060757 -0.25
16 -0.20 -4.5969050788e-08 0.0000057963 -0.20
17 -0.15 -4.1539092610e-08 0.0000054951 -0.15
18 -0.10 1.5181252699e-08 0.0000052989 -0.10
19 -0.05 -1.6798327174e-08 0.0000046645 -0.05
20 0.00 1.3036557212e-07 0.0000048647 0.00