File data_analysis/auxfunctions/run_entanglement_evaluation_simulation.m changed (mode: 100644) (index de55d7f..90e61d3) |
1 |
1 |
%% [ev, model] = run_entanglement_evaluation_simulation(simulation_dir): |
%% [ev, model] = run_entanglement_evaluation_simulation(simulation_dir): |
2 |
|
%takes a directory simulation_dir |
|
3 |
|
%and creates a suitable evaluation object |
|
|
2 |
|
%takes a directory simulation_dir and creates a suitable evaluation object |
4 |
3 |
% |
% |
5 |
4 |
% simulation_dir must contain a script 'setup_eval.m' |
% simulation_dir must contain a script 'setup_eval.m' |
6 |
|
%and a simulation model 'model.mat' |
|
|
5 |
|
% and a simulation model 'model.mat' |
7 |
6 |
% |
% |
8 |
|
%run_entanglement_evaluation_simulation(simulation_dir, 'test') runs in test-mode |
|
|
7 |
|
%run_entanglement_evaluation_simulation(simulation_dir, 'test') runs an evaluation |
|
8 |
|
% over only the first 10 pulse pairs. |
9 |
9 |
%run_entanglement_evaluation_simulation(simulation_dir, 'quick') runs an evaluation |
%run_entanglement_evaluation_simulation(simulation_dir, 'quick') runs an evaluation |
10 |
10 |
% over only the first 1e3 pulse pairs. |
% over only the first 1e3 pulse pairs. |
11 |
11 |
function [ev, model] = run_entanglement_evaluation_simulation(simulation_dir, varargin) |
function [ev, model] = run_entanglement_evaluation_simulation(simulation_dir, varargin) |
12 |
12 |
assert_file_in_dir('setup_eval.m', simulation_dir); |
assert_file_in_dir('setup_eval.m', simulation_dir); |
13 |
13 |
assert_file_in_dir('model.mat', simulation_dir); |
assert_file_in_dir('model.mat', simulation_dir); |
14 |
14 |
|
|
15 |
|
|
|
16 |
|
test_mode = false; |
|
17 |
|
quick_mode = false; |
|
|
15 |
|
evaluation_mode = 'fulll'; % complete evalution |
18 |
16 |
for k=1:length(varargin) |
for k=1:length(varargin) |
19 |
17 |
switch varargin{k} |
switch varargin{k} |
20 |
18 |
case 'test' |
case 'test' |
21 |
|
test_mode = true; |
|
|
19 |
|
evaluation_mode = 'test'; % ultraquick evaluation: 10 pulepairs only |
22 |
20 |
case 'quick' |
case 'quick' |
23 |
|
quick_mode = true; |
|
|
21 |
|
evaluation_mode = 'quick'; % quick evaluation: 1e3 pulepairs only |
24 |
22 |
otherwise |
otherwise |
25 |
23 |
error('unrecognized varargin-argument'); |
error('unrecognized varargin-argument'); |
26 |
24 |
end |
end |
27 |
25 |
end |
end |
28 |
26 |
|
|
29 |
27 |
currenttime = datestr(now, 'yyyymmdd-HHMMSS'); |
currenttime = datestr(now, 'yyyymmdd-HHMMSS'); |
30 |
|
if test_mode |
|
31 |
|
currenttime = 'test' |
|
32 |
|
elseif quick_mode |
|
33 |
|
currenttime = [currenttime, '_quick'] |
|
|
28 |
|
if ~isequal(evaluation_mode, 'normal') |
|
29 |
|
currenttime = [currenttime, '_', evaluation_mode] |
34 |
30 |
end |
end |
35 |
31 |
mkdir(simulation_dir, currenttime); |
mkdir(simulation_dir, currenttime); |
36 |
32 |
export_dir = fullfile(simulation_dir, currenttime); |
export_dir = fullfile(simulation_dir, currenttime); |
|
... |
... |
function [ev, model] = run_entanglement_evaluation_simulation(simulation_dir, va |
40 |
36 |
to_log = @(string) append_string_to_txtfile(string, diary_file); |
to_log = @(string) append_string_to_txtfile(string, diary_file); |
41 |
37 |
|
|
42 |
38 |
whereami = pwd; |
whereami = pwd; |
43 |
|
|
|
44 |
|
addpath(genpath('/home/membrane/Documents/MATLAB/datoolbox')); |
|
45 |
|
addpath(genpath('/home/membrane/Documents/MATLAB/optomechanics')); |
|
46 |
39 |
cd(simulation_dir); |
cd(simulation_dir); |
47 |
40 |
|
|
48 |
41 |
load('model.mat'); % load experiment-model 'model' |
load('model.mat'); % load experiment-model 'model' |
|
... |
... |
function [ev, model] = run_entanglement_evaluation_simulation(simulation_dir, va |
56 |
49 |
|
|
57 |
50 |
save(fullfile(export_dir, 'model.mat'), 'model'); |
save(fullfile(export_dir, 'model.mat'), 'model'); |
58 |
51 |
|
|
59 |
|
theory_fig = figure; hold all; |
|
60 |
|
plot(model.pulse_gammas, model.log_neg,... |
|
61 |
|
'DisplayName', 'Singlemode theory with adiabatic elimination, noise-free'); |
|
62 |
|
|
|
63 |
|
gridxy(ev.pulse_gammas, 'Color',[0,0,0]+0.5,'Linestyle','-',... |
|
64 |
|
'DisplayName', 'gammas for evaluation'); |
|
65 |
|
|
|
66 |
|
ylims = [max(-0.5, 1.1*min(real(model.log_neg))),... |
|
67 |
|
1.1*max(real(model.log_neg))]; |
|
68 |
|
ylim(ylims); |
|
69 |
|
xlim([0.5*min(model.pulse_gammas), 1.5*max(model.pulse_gammas)]); |
|
70 |
|
set(gca,'xscale','log') |
|
71 |
|
|
|
72 |
|
xlabel('Pulse gammas [Hz]'); |
|
73 |
|
ylabel('Logarithmic negativity'); |
|
74 |
|
legend('Location','Best'); |
|
75 |
|
gridxy([],0); |
|
76 |
|
saveas(theory_fig, fullfile(export_dir, 'theory.fig')); |
|
77 |
|
saveas(theory_fig, fullfile(export_dir, 'theory.jpg')); |
|
78 |
|
|
|
79 |
52 |
ev.calculateModeVectors; %% calculate mode vectors |
ev.calculateModeVectors; %% calculate mode vectors |
80 |
|
if test_mode |
|
81 |
|
return |
|
82 |
|
end |
|
83 |
|
ev = calculate_entanglement(ev, quick_mode); %% run evaluation with current params |
|
84 |
|
|
|
85 |
|
%% export simulation curve and evaluation results |
|
86 |
|
simulation_fig = figure; hold all; |
|
87 |
|
plot(model.pulse_gammas, model.log_neg,... |
|
88 |
|
'DisplayName', 'Singlemode theory with adiabatic elimination, noise-free'); |
|
89 |
|
|
|
90 |
|
%gridxy(ev.pulse_gammas, 'Color',[0,0,0]+0.5,'Linestyle','-',... |
|
91 |
|
% 'DisplayName', 'gammas for evaluation'); |
|
92 |
|
|
|
93 |
|
for ii = 1:ev.tracepairs_no |
|
94 |
|
plot(ev.pulse_gammas, [ev.logneg_corrected{ii}{:}],'.',... |
|
95 |
|
'DisplayName',['signal = ', num2str(ev.signal_power_muW(ii,1)),'muW']); |
|
96 |
|
end |
|
97 |
|
ylims = [max(-0.5, 1.1*min(real(model.log_neg))),... |
|
98 |
|
2*max(real(model.log_neg))]; |
|
99 |
|
ylim(ylims); |
|
100 |
|
xlim([0.5*min(ev.pulse_gammas), 1.5*max(ev.pulse_gammas)]); |
|
101 |
|
set(gca,'xscale','log') |
|
|
53 |
|
ev = calculate_entanglement(ev, evaluation_mode); %% run evaluation with current params |
102 |
54 |
|
|
103 |
|
xlabel('Pulse gammas [Hz]'); |
|
104 |
|
ylabel('Logarithmic negativity'); |
|
105 |
|
legend('Location','Best'); |
|
106 |
|
title(export_dir); |
|
107 |
|
gridxy([],0); |
|
108 |
|
saveas(simulation_fig, fullfile(export_dir, 'simulation.fig')); |
|
109 |
|
saveas(simulation_fig, fullfile(export_dir, 'simulation.jpg')); |
|
110 |
|
|
|
111 |
|
%%export data |
|
|
55 |
|
%% export plots and data |
|
56 |
|
export_simulation_plot(ev, model, export_dir) |
112 |
57 |
ev.exportResults; |
ev.exportResults; |
113 |
58 |
dlmwrite(fullfile(export_dir, 'theory.csv'),([model.pulse_gammas; model.log_neg]')); |
dlmwrite(fullfile(export_dir, 'theory.csv'),([model.pulse_gammas; model.log_neg]')); |
114 |
59 |
|
|
|
... |
... |
end |
118 |
63 |
|
|
119 |
64 |
|
|
120 |
65 |
%% AUX FUNCTIONS %% |
%% AUX FUNCTIONS %% |
121 |
|
function ev = calculate_entanglement(ev, quick_mode) |
|
|
66 |
|
function ev = calculate_entanglement(ev, evaluation_mode) |
122 |
67 |
%% calculate quadratures |
%% calculate quadratures |
123 |
68 |
tic |
tic |
124 |
69 |
for i=1:ev.tracepairs_no |
for i=1:ev.tracepairs_no |
125 |
70 |
disp(''); |
disp(''); |
126 |
71 |
disp('***************'); |
disp('***************'); |
127 |
72 |
disp(['calculating quadratures for P=',num2str(ev.signal_power_muW(i,1)),'muW']); |
disp(['calculating quadratures for P=',num2str(ev.signal_power_muW(i,1)),'muW']); |
128 |
|
if quick_mode |
|
129 |
|
ev.calculatePulsedQuadratures(i, 'pulsepairs', 1e3); |
|
130 |
|
else |
|
|
73 |
|
if isequal(evaluation_mode, 'normal') |
131 |
74 |
ev.calculatePulsedQuadratures(i); |
ev.calculatePulsedQuadratures(i); |
|
75 |
|
elseif isequal(evaluation_mode, 'quick') |
|
76 |
|
ev.calculatePulsedQuadratures(i, 'pulsepairs', 1e3); |
|
77 |
|
elseif isequal(evaluation_mode, 'test') |
|
78 |
|
ev.calculatePulsedQuadratures(i, 'pulsepairs', 10); |
132 |
79 |
end |
end |
133 |
80 |
end |
end |
134 |
81 |
toc |
toc |
|
... |
... |
function ev = calculate_entanglement(ev, quick_mode) |
151 |
98 |
ev.calibratePulsedCMs; |
ev.calibratePulsedCMs; |
152 |
99 |
toc |
toc |
153 |
100 |
end |
end |
|
101 |
|
|
|
102 |
|
function export_simulation_plot(ev, model, export_dir) |
|
103 |
|
simulation_fig = figure; hold all; |
|
104 |
|
plot(model.pulse_gammas, model.log_neg,... |
|
105 |
|
'DisplayName', 'Singlemode theory with adiabatic elimination, noise-free'); |
|
106 |
|
%gridxy(ev.pulse_gammas, 'Color',[0,0,0]+0.5,'Linestyle','-',... |
|
107 |
|
% 'DisplayName', 'gammas for evaluation'); |
|
108 |
|
|
|
109 |
|
for ii = 1:ev.tracepairs_no |
|
110 |
|
plot(ev.pulse_gammas, [ev.logneg_corrected{ii}{:}],'.',... |
|
111 |
|
'DisplayName',['signal = ', num2str(ev.signal_power_muW(ii,1)),'muW']); |
|
112 |
|
end |
|
113 |
|
ylims = [max(-0.5, 1.1*min(real(model.log_neg))),... |
|
114 |
|
2*max(real(model.log_neg))]; |
|
115 |
|
ylim(ylims); |
|
116 |
|
xlim([0.5*min(ev.pulse_gammas), 1.5*max(ev.pulse_gammas)]); |
|
117 |
|
set(gca,'xscale','log') |
|
118 |
|
|
|
119 |
|
xlabel('Pulse gammas [Hz]'); |
|
120 |
|
ylabel('Logarithmic negativity'); |
|
121 |
|
legend('Location','Best'); |
|
122 |
|
parentfolders = regexp(export_dir, filesep, 'split'); |
|
123 |
|
title([parentfolders{end-1}, 10, parentfolders{end}], 'interpreter', 'none'); |
|
124 |
|
gridxy([],0); |
|
125 |
|
saveas(simulation_fig, fullfile(export_dir, 'simulation.fig')); |
|
126 |
|
saveas(simulation_fig, fullfile(export_dir, 'simulation.jpg')); |
|
127 |
|
end |