<s> import numpy as np <EOL> import math <EOL> class Op : <EOL> def __init__ ( self ) : <EOL> self . M = [ ] <EOL> self . name = [ ] ; <EOL> self . mutation_partners = [ ] ; <EOL> self . anti_operator = [ ] ; <EOL> self . mutation_partners_no = [ ] <EOL> self . anti_operator_no = [ ] <EOL> self . create_operators ( ) <EOL> self . check_unitarity ( ) <EOL> self . determine_index_of_mutation_partners ( ) <EOL> self . determine_index_of_anti_operators ( ) <EOL> def create_operators ( self ) : <EOL> alpha = math . pi / <NUM_LIT> ; <EOL> da = math . pi / <NUM_LIT> ; <EOL> self . M . append ( np . matrix ( <EOL> [ [ math . cos ( da / <NUM_LIT> ) - <NUM_LIT> * math . sin ( da / <NUM_LIT> ) , <NUM_LIT:0.0> ] , <EOL> [ <NUM_LIT:0.0> , math . cos ( da / <NUM_LIT> ) + <NUM_LIT> * math . sin ( da / <NUM_LIT> ) ] ] ) ) <EOL> self . name . append ( '<STR_LIT>' ) ; <EOL> self . mutation_partners . append ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . anti_operator . append ( '<STR_LIT>' ) ; <EOL> self . M . append ( np . matrix ( <EOL> [ [ math . cos ( - da / <NUM_LIT> ) - <NUM_LIT> * math . sin ( - da / <NUM_LIT> ) , <NUM_LIT:0.0> ] , <EOL> [ <NUM_LIT:0.0> , math . cos ( - da / <NUM_LIT> ) + <NUM_LIT> * math . sin ( - da / <NUM_LIT> ) ] ] ) ) <EOL> self . name . append ( '<STR_LIT>' ) ; <EOL> self . mutation_partners . append ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . anti_operator . append ( '<STR_LIT>' ) ; <EOL> self . M . append ( np . matrix ( [ <EOL> [ math . cos ( da / <NUM_LIT> ) - <NUM_LIT> * math . cos ( alpha ) * math . sin ( da / <NUM_LIT> ) , <EOL> - math . sin ( alpha ) * math . sin ( da / <NUM_LIT> ) ] , <EOL> [ math . sin ( alpha ) * math . sin ( da / <NUM_LIT> ) , <EOL> math . cos ( da / <NUM_LIT> ) + <NUM_LIT> * math . cos ( alpha ) * math . sin ( da / <NUM_LIT> ) ] ] ) ) <EOL> self . name . append ( '<STR_LIT>' ) ; <EOL> self . mutation_partners . append ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . anti_operator . append ( '<STR_LIT>' ) ; <EOL> self . M . append ( np . matrix ( [ <EOL> [ math . cos ( - da / <NUM_LIT> ) - <NUM_LIT> * math . cos ( alpha ) * math . sin ( - da / <NUM_LIT> ) , <EOL> - math . sin ( alpha ) * math . sin ( - da / <NUM_LIT> ) ] , <EOL> [ math . sin ( alpha ) * math . sin ( - da / <NUM_LIT> ) , <EOL> math . cos ( - da / <NUM_LIT> ) + <NUM_LIT> * math . cos ( alpha ) * math . sin ( - da / <NUM_LIT> ) ] ] ) ) <EOL> self . name . append ( '<STR_LIT>' ) ; <EOL> self . mutation_partners . append ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . anti_operator . append ( '<STR_LIT>' ) ; <EOL> def check_unitarity ( self ) : <EOL> for k in range ( len ( self . M ) ) : <EOL> if ( np . trace ( self . M [ k ] * self . M [ k ] . getH ( ) ) - <NUM_LIT:2> != <NUM_LIT:0> ) : <EOL> print "<STR_LIT>" + self . name [ k ] + "<STR_LIT>" + str ( <EOL> k ) + "<STR_LIT>" <EOL> exit ( ) <EOL> def determine_index_of_mutation_partners ( self ) : <EOL> for k in range ( len ( self . M ) ) : <EOL> hlp = [ ] <EOL> for m in range ( len ( self . mutation_partners [ k ] ) ) : <EOL> for n in range ( len ( self . M ) ) : <EOL> if self . mutation_partners [ k ] [ m ] is self . name [ n ] : <EOL> hlp . append ( n ) <EOL> self . mutation_partners_no . append ( hlp ) <EOL> def determine_index_of_anti_operators ( self ) : <EOL> for k in range ( len ( self . M ) ) : <EOL> found_operator = False <EOL> for n in range ( len ( self . M ) ) : <EOL> if self . anti_operator [ k ] is self . name [ n ] : <EOL> self . anti_operator_no . append ( n ) ; <EOL> found_operator = True <EOL> if found_operator == False : <EOL> print "<STR_LIT>" + self . name [ <EOL> k ] + "<STR_LIT>" + str ( k ) + "<STR_LIT:)>" <EOL> def __str__ ( self ) : <EOL> hlpstr = '<STR_LIT>' <EOL> for k in range ( len ( self . M ) ) : <EOL> hlpstr = hlpstr + self . name [ k ] + "<STR_LIT:U+0020>" + str ( <EOL> self . anti_operator_no [ k ] ) + "<STR_LIT:\n>" <EOL> return "<STR_LIT>" + hlpstr <EOL> def calc_fidelity ( sequence , Op , Ugoal ) : <EOL> Uapprox = np . eye ( len ( Ugoal ) ) <EOL> for k in range ( len ( sequence ) ) : <EOL> Uapprox = Op . M [ sequence [ k ] ] * Uapprox <EOL> result = ( <NUM_LIT:1.0> / len ( Ugoal ) ) * abs ( np . trace ( Ugoal * Uapprox . getH ( ) ) ) <EOL> return result </s>
