📄 twirl.m
字号:
% twirl Twirling% twirl(rho) twirls the multi-qubit density matrix rho.% [rho,difference]=twirl(rho) also gives the % norm of the difference between the original and the % twirled state. The difference is computed through the norm % ||A||=sum_kl |A_kl|^2. Obviously, the difference is zero% for Werner states. The form twirl(rho,d) makes it% possible to twirl a register of qudits with dimension d. % Using the form twirl(rho,d,Nit) we can determine how many random% unitaries are used for twirling. (The algorithm% is not the straightforward integration of% the integral in the formula for twirling.)% The default value for Nit is 100.% For the algorithm see % http://www.arxiv.org/abs/quant-ph/0609052.% Copyright (C) 2005 Geza Toth E.mail: toth@alumni.nd.edu%% This program is free software; you can redistribute it and/or% modify it under the terms of the GNU General Public License% as published by the Free Software Foundation; see gpl.txt% of this subroutine package.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.% % You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 51 Franklin Street, Fifth Floor, % Boston, MA 02110-1301, USA.function [r,difference]=twirl(rho,varargin);if length(varargin)==0, % Dimension of quidits d=2; % Number of random unitaries used Nit=100;elseif length(varargin)==1, d=varargin{1}; Nit=100;elseif length(varargin)==2, d=varargin{1}; Nit=varargin{2};else error('Wrong number of input arguments');end %ifx=[0 1;1 0];z=[1 0;0 -1];y=i*x*z;[sy,sx]=size(rho);N=log2(sx)/log2(d); U=zeros(d,d);r=rho;for n=1:Nit % Initializing the random number generator based on the clock % is not a good idea, if the clock counts only seconds ... % Then after each restart we get back the same sequence of numbers % if the program does not run for more than a second. % Thus I omitted the following line: % if mod(n,100)==0, rand('state',sum(100*clock)); end %if % Create a random dxd unitary % from d orthogonal vectors for k=1:d vv=randn(d,1)+i*randn(d,1); for m=1:k-1 vv=vv-U(:,m)*(U(:,m)'*vv); end %for U(:,k)=vv/sqrt(vv'*vv); end %for UU=U; for n=2:N UU=kron(UU,U); end %for r=(r+UU*r*UU')/2;end %fordifference=trace((r-rho)*(r-rho)');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -