Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Conflicts:
	common/util/@Pulse/RIP_Spline.m
  • Loading branch information
blakejohnson committed Mar 26, 2015
2 parents ce4085d + 0909c6d commit df580a1
Show file tree
Hide file tree
Showing 190 changed files with 3,912 additions and 12,447 deletions.
Empty file modified .gitignore
100755 → 100644
Empty file.
35 changes: 35 additions & 0 deletions analysis/Batches/loadT1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%load T1 in multiple, consecutive files

numcal = 4; %number of normalization points
datestr = '150108';
expname = 'T1Q1';
quad = 'real';
startnum = 1645;
stopnum = 1845;

T1 = zeros(1,stopnum-startnum+1); %initialize arrays of T1 and error bars
dT1 = zeros(1,stopnum-startnum+1);
kk=1;

for filenum = startnum:stopnum
data = load_data(strcat('C:\Users\qlab\Documents\data\IBM_v11\',num2str(datestr),'\',num2str(filenum),'_IBM_v11_',expname,'.h5'));
ydata = cal_scale(data.data);
if quad == 'real'
normdata = real(ydata);
else
normdata = imag(ydata);
end
[T1(kk),dT1(kk)] = fitt1(data.xpoints(1:length(data.xpoints)-4), real(ydata));
kk=kk+1;
end

xaxis = startnum:stopnum;
figure()
errorbar(xaxis,T1/1000,dT1/1000,'.-','MarkerSize',12);
ylim([0,inf]);
xlim([startnum,stopnum]);
xlabel('File number');
ylabel('T1 (us)');
annotation('textbox','string',datestr)

fprintf('Average T1 = %.1f us\n', mean(T1/1000));
Empty file modified analysis/KT_estimation.m
100755 → 100644
Empty file.
64 changes: 32 additions & 32 deletions analysis/cQED_dataAnalysis/QPT_SDP.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
% easy to enforce. It also return the direct unconstrained inversion result.
%
% [choiSDP, choiLSQ] = QPT_SDP(expResults, measOps, measMap, U_preps, U_meas, nbrQubits)
% expResults: matrix of experimental results (numMeas x numPrep)
% expResults: vector of experimental results
% measOps: measurement operators in real units e.g. measuring 1V for the ground state and 1.23V for the excited state gives [[1, 0],[0,1.23]]
% measMap: matrix mapping of each experiment to associated measurement operator
% measMap: vector mapping of each experiment to associated measurement operator
% U_preps: cell array of the preparation unitaries
% U_meas: cell array of read-out unitaries
% nbrQubits: the number of qubits
Expand All @@ -28,24 +28,6 @@
numPrep = length(U_preps);
numMeas = length(U_meas);

%Assume perfect preparation in the ground state
rhoIn = zeros(d,d);
rhoIn(1,1) = 1;

%Transform the initial state by the preparation pulse
rhoPreps = cell(numPrep,1);
for ct = 1:length(U_preps)
rhoPreps{ct} = U_preps{ct}*rhoIn*U_preps{ct}';
end

%Transform the measurement operators by the measurement pulses
measurementoptsset = cell(numMeas,1);
for ct=1:length(measOps)
for measPulsect = 1:numMeas
measurementoptsset{ct}{measPulsect}= U_meas{measPulsect}'*measOps{ct}*U_meas{measPulsect};
end
end

% Set up the SDP problem with Yalmip
% First the Choi matrix in square form
choiSDP_yalmip = sdpvar(d2, d2, 'hermitian', 'complex');
Expand All @@ -54,19 +36,37 @@
% matrix (S) elements: for a given rhoIn and measOp then measResult = Tr(S*kron(rhoIn.', measOp))
fprintf('Setting up predictor matrix....');
predictorMat = zeros(numPrep*numMeas, d4, 'double');
rowct = 1;
for prepct = 1:numPrep
for measct = 1:numMeas
% Have to multiply by d to match Jay's convention of dividing the
% Choi matrix by d
% We can use the usual trick that trace(A*B) = trace(B*A) = sum(tranpose(B).*A)
% predictorMat(prepct, measct) = trace(choiSDP*kron(rhoPreps{prepct}.', measurementoptsset{measMap(prepct,measct)}{measct}))*d;
tmpMat = transpose(kron(rhoPreps{prepct}.', measurementoptsset{measMap(measct,prepct)}{measct}));
predictorMat(rowct, :) = d*tmpMat(:);
rowct = rowct+1;
end
end
prepIdx = 1;
measIdx = 1;

for expct = 1:length(expResults)
%Assume perfect preparation in the ground state
rhoIn = zeros(d,d);
rhoIn(1,1) = 1;
%Transform the initial state by the preparation pulse
rhoIn = U_preps{prepIdx}*rhoIn*U_preps{prepIdx}';

%Transform the measurement operators by the measurement pulses
measOp = U_meas{measIdx}' * measOps{measMap(expct)} * U_meas{measIdx};

% Have to multiply by d to match Jay's convention of dividing the
% Choi matrix by d
% We can use the usual trick that trace(A*B) = trace(B*A) = sum(tranpose(B).*A)
% predictorMat(prepct, measct) = trace(choiSDP*kron(rhoPreps{prepct}.', measurementoptsset{measMap(prepct,measct)}{measct}))*d;
tmpMat = transpose(kron(rhoIn.', measOp));
predictorMat(expct, :) = d*tmpMat(:);

%Roll the counters
measIdx = measIdx + 1;
if (measIdx > numMeas)
measIdx = 1;
prepIdx = prepIdx + 1;
end
if (prepIdx > numPrep)
prepIdx = 1;
end
end

%We want to minimize the difference between predicted results and experimental results
optGoal = norm(predictorMat*choiSDP_yalmip(:) - expResults(:),2);
fprintf('Done!\n.')
Expand Down
11 changes: 7 additions & 4 deletions analysis/cQED_dataAnalysis/QST_LSQ.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

%Function to perform least-squares inversion of state tomography data
%
% expResults : structure array (length total number of experiments)
% each structure containts fields data, measPulse, measOperator
% measPulses : cell array of unitaries of measurment pulses
% measOps : cell array of measurment operators
% expResults : data array
% varmat : convariance matrix for data
% measPulseMap: array mapping each experiment to a measurement readout
% pulse
% measOpMap: array mapping each experiment to a measurement channel
% measPulseUs : cell array of unitaries of measurement pulses
% measOps : cell array of measurment operators for each channel
% n : number of qubits

%Construct the predictor matrix. Each row is an experiment. The number of
Expand Down
Empty file modified analysis/cQED_dataAnalysis/SimulRB/fitSimulRB.m
100755 → 100644
Empty file.
Empty file modified analysis/cQED_dataAnalysis/analyfast.m
100755 → 100644
Empty file.
87 changes: 87 additions & 0 deletions analysis/cQED_dataAnalysis/analyzeCalCR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
function optvalue = analyzeCalCR(caltype, CRdata,channel, varargin)
%simple fit function to get optimum length/phase in a CR calibration
%and set in pulse params

%caltype:
% 1 - length
% 2 - phase

%channel: channel with the target data

CRpulsename = 'CR';

data = real(CRdata.data{channel});
xpoints = CRdata.xpoints{channel}(1:(length(data)-8)/2);
data = cal_scale(data,4); %Assuming the calibrations are 4 |0>, then 4 |1>.

data0 = data(1:length(data)/2);
data1 = data(length(data)/2+1:end);

sinf = @(p,t) p(1)*cos(2*pi/p(2)*t+p(3))+p(4);

if(caltype==1)
p=[1,4*xpoints(end),0,0];
else
p=[1,xpoints(end),0,0];
end

%fit sine curves
[beta0,~,~] = nlinfit(xpoints, data0(:),sinf,p);
[beta1,~,~] = nlinfit(xpoints, data1(:),sinf,p);
%todo: make fit xpoints finer
yfit0 = sinf(beta0,xpoints);
yfit1 = sinf(beta1,xpoints);

if(caltype==1)
yfit0c = yfit0(1:min(round(abs(beta0(2))/2/(xpoints(2)-xpoints(1))),end)); %select the first half period or less
yfit1c = yfit1(1:min(round(abs(beta1(2))/2/(xpoints(2)-xpoints(1))),end));
[~, indmin0] = min(abs(yfit0c(:))); %min returns the index of the first zero crossing
[~, indmin1] = min(abs(yfit1c(:))); %min returns the index of the first zero crossing
optlen = mean([xpoints(indmin0),xpoints(indmin1)]);
fprintf('Length index for CNOT = %f\n', mean([indmin0, indmin1]));
fprintf('Optimum length = %f ns\n', optlen)
fprintf('Mismatch between |0> and |1> = %f ns\n', abs(xpoints(indmin1)-xpoints(indmin0)))
elseif(caltype==2)
%find max contrast
ctrfit = yfit0-yfit1;
[~, indmax] = max(ctrfit);
optphase = xpoints(indmax);
fprintf('Phase index for maximum contrast = %d\n', indmax)
fprintf('Optimum phase = %f\n', optphase)
else
frpintf('Calibration type not supported')
return
end

if nargin>3
figure(varargin{1}); %I need to find a consistent way to deal with plots, DR
else
figure(101)
end
plot(xpoints, data0, 'b.', xpoints, data1, 'r.', xpoints, yfit0, 'b-', xpoints, yfit1, 'r-','MarkerSize',16);
legend('ctrlQ in |0>','ctrlQ in |1>');
ylim([-1,1]); ylabel('<Z>');

if(caltype==1)
xlabel ('CR flat pulse length (ns)');
else
xlabel ('Phase (deg)');
end
title(strrep(CRdata.filename, '_', '\_'));

%update length/phase in CR pulse parameters
warning('off', 'json:fieldNameConflict');
channelLib = json.read(getpref('qlab','ChannelParamsFile'));
warning('on', 'json:fieldNameConflict');
chDict = channelLib.channelDict;
if(caltype==1)
outlen = optlen*1e-9;
outphase = chDict.(CRpulsename).pulseParams.phase;
optvalue = optlen;
else
outlen = chDict.(CRpulsename).pulseParams.length;
outphase = optphase;
optvalue = optphase;
end
updateLengthPhase(CRpulsename, outlen, outphase);
end
71 changes: 49 additions & 22 deletions analysis/cQED_dataAnalysis/analyzeProcessTomo.m
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
function [gateFidelity, choiSDP] = analyzeProcessTomo(data, idealProcess, nbrQubits, nbrPrepPulses, nbrReadoutPulses, calRepeats)
function [gateFidelity, choiSDP, choiLSQ] = analyzeProcessTomo(data, idealProcess, nbrQubits, nbrPrepPulses, nbrReadoutPulses, nbrCalRepeats)
%analyzeProcess Performs SDP tomography, calculates gates fidelites and plots pauli maps.
%
% [gateFidelity, choiSDP] = analyzeProcessTomo(data, idealProcessStr, nbrQubits, nbrPrepPulses, nbrReadoutPulses, nbrRepeats)

% seperate calibration experiments from tomography data, and reshape
% accordingly
%The data.abs_Data comes a matrix (numPulseSeqs X numExpsperPulseSeq) with
%the calibration data the last 2^nbrQubits of each row. We need to go
%seperate calibration experiments from tomography data and flatten the
%experiment data

%The data comes in as a matrix (numSeqs X numExpsPerSeq) with
%the calibration data the last nbrCalRepeats2^nbrQubits of each row. We need to go
%through each column and extract the calibration data and record a map of
%which measurement operator each experiment corresponds to.

%First cat multi-measurement data together
if iscell(data)
numMeasChans = length(data);
data = cat(1, data{:});
else
numMeasChans = 1;
end

%Number of different preparations and readouts
numPreps = nbrPrepPulses^nbrQubits;
numMeas = nbrReadoutPulses^nbrQubits;

measMap = zeros(numMeas, numPreps, 'uint8');
measMat = zeros(numMeas, numPreps, 'double');
numSeqs = size(data,1);
expPerSeq = size(data,2)-2^nbrQubits*calRepeats;
measOps = cell(numSeqs,1);

idx=1;
for seqct = 1:size(data,1)
cals = data(seqct,end-2^nbrQubits*calRepeats+1:end);
raws = data(seqct,1:end-2^nbrQubits*calRepeats);
measOps{seqct} = diag(mean(reshape(cals, calRepeats, 2^nbrQubits),1));
measMat(idx:idx+expPerSeq-1) = raws;
measMap(idx:idx+expPerSeq-1) = seqct;
idx = idx+expPerSeq;
numExps = numPreps*numMeas*numMeasChans;
numCals = 2^(nbrQubits)*nbrCalRepeats;

%Rough rescaling by the variance to equalize things for the least squares
approxScale = std(data(:,end-numCals+1:end), 0, 2);
data = bsxfun(@rdivide, data, approxScale);

%Pull out the raw experimental data
rawData = data(:, 1:numMeas);

%Pull out the calibration data as measurement operators and assign each exp. to a meas. operator
measOps = cell(size(data,1),1);
measMap = nan(numExps,1);
results = nan(numExps,1);

%Go through row first as fast axis
idx = 1;
for row = 1:size(rawData,1)
measOps{row} = diag(mean(reshape(data(row, end-numCals+1:end), nbrCalRepeats, 2^nbrQubits),1));
for col = 1:size(rawData,2)
results(idx) = rawData(row,col);
measMap(idx) = row;
idx = idx + 1;
end
end


%Setup the state preparation and measurement pulse sets
U_preps = tomo_gate_set(nbrQubits, nbrPrepPulses);
U_meas = tomo_gate_set(nbrQubits, nbrReadoutPulses);

%Call the SDP program to do the constrained optimization
[choiSDP, choiLSQ] = QPT_SDP(measMat, measOps, measMap, U_preps, U_meas, nbrQubits);
[choiSDP, choiLSQ] = QPT_SDP(results, measOps, measMap, U_preps, U_meas, nbrQubits);

%Calculate the overlaps with the ideal gate
if ischar(idealProcess)
Expand All @@ -60,6 +78,15 @@
pauliMapLSQ = choi2pauliMap(choiLSQ);
pauliMapExp = choi2pauliMap(choiSDP);

%Permute according to hamming weight
weights = cellfun(@pauliHamming, pauliStrs);
[~, weightIdx] = sort(weights);

pauliMapIdeal = pauliMapIdeal(weightIdx, weightIdx);
pauliMapLSQ = pauliMapLSQ(weightIdx, weightIdx);
pauliMapExp = pauliMapExp(weightIdx, weightIdx);
pauliStrs = pauliStrs(weightIdx);

%Create red-blue colorscale
cmap = [hot(50); 1-hot(50)];
cmap = cmap(19:19+63,:); % make a 64-entry colormap
Expand Down
Loading

0 comments on commit df580a1

Please sign in to comment.