Raw File
const int N = 500;
const double Bx = 2;

const double total_T = 15.0;  // total duration of adiabatic evolution
const int M = 1; // number of Trotter steps

// elements of Bz and J are randomly generated from uniform(-2, 2)
const double Bz[] = {1.816665331509678, -0.4435124487956479, 0.08807097526881469, 1.2351788424785184, -1.6847666031853397, 1.7969273663633984, 1.3427813755984368, -1.5444654229077384, -0.7617442660489027, 0.38424750172781375, 1.3920751894982462, 0.19777170357301532, 0.8963739896262037, 0.146101952143177, 0.9441888140154311, -1.3577415631647867, -1.7894445473464748, 1.6043698638441914, 0.18728749532916966, -1.8123833918729866, -1.9755743572433238, 0.20115420186952404, 1.7971482069558449, -0.679565643315263, -0.9968219203373376, -1.2876863284722901, -1.0724680218364129, 1.8366175755944756, -0.6692996692522368, 1.2096945050542733, 1.3556365420301804, 1.7207141936318515, -1.8616524187622145, -0.6335849066507548, 1.7887577356496331, 0.07816794263855442, 1.5267004862933211, -0.7781139352493431, -0.4049614647438373, -1.3911471985804575, -1.7949195915064182, 0.24780531997824307, -0.27559038134952685, -1.413470485615425, -0.7310808522372838, 1.15481787485363, -1.6879454728587744, 1.0074490291626685, 0.9889075170498431, -0.035544569620141075, 1.4973059180529105, -1.199165708999495, 1.8328110139237443, 0.6386734768696996, -1.6205948829043626, -1.015572848887655, -0.3463940369679692, 0.5464163091760446, -0.908996563381943, 1.8645070228190894, -1.1962488810839265, 1.2993615787716832, -0.5167971885335074, -0.5814891464744569, -0.035278887211252385, -0.5754052326906169, 0.60173030468949, -0.19229906656943774, -1.0546137198934842, -0.2874235369650937, -0.2276718638153863, -0.08418807120241611, 1.5156666857035916, -0.5541534100496284, -1.293668420066353, 1.0679805760443117, 1.6712939008569103, -0.7078131383343851, -1.5050369895297342, -1.554083388725933, 1.5232514883948851, 0.4271196017571799, -0.01683188617950515, -1.0017367182008319, -0.15929652062572952, -1.843931807449469, -0.7148133620478623, -0.24890534136407627, -1.3850870843388496, -1.058740216310484, 0.48428948720317067, 1.2167582831019392, -1.333275728106996, 1.7650567719547765, 0.7966455523022158, -1.8290761622147529, 0.5917400689862022, -1.8454415446873305, 1.1859238832860797, -1.02439503351096, 1.6113317735894004, 1.1906039400033506, -0.6568135479868751, 1.2949777504201228, 0.395608227135372, 1.358415466005518, 1.9897719994720586, 0.20310103826104653, -1.6406209944896193, -1.3249661451490184, 0.6824152987655445, 1.636912913964896, -0.0694594580950385, 1.3906236052396204, 1.283881528108354, -1.0695999871580946, -0.5930337259071403, 1.6367874375827896, 1.0991746026020248, 1.8718798940328143, -1.9296805109125597, -0.30808839098050367, 0.4014045133005788, 0.9770047883959689, -0.2778200766569361, -0.07070066755985538, -0.873177132447235, -0.28938460103549124, 0.8070649161747192, 0.03611180453916951, -1.0748002056332333, -1.5276320728534687, -0.9078755004172985, 0.26546160730964496, 1.769226776791061, 0.8797679718324956, 0.95383946750264, -1.0838985974825475, 1.2706413111891548, 1.9310355925415887, -0.47806735014100843, -1.5415386288296151, -1.3358979173706746, -0.6348237870225453, -1.8778816190680492, 0.40610372787788984, -0.37096522034820456, 0.8163622285753629, -1.5037600735683432, -0.266703080070529, 1.1354723272173928, -0.04234709738043341, -1.5516668235278837, 0.47443015343590833, -0.5643766385729325, 0.6286990184304351, -0.9883317746545783, 1.561026181408498, 0.12193646295507499, 0.22664373735503895, -1.1653724644883026, 0.7823248981989623, 1.307956838572537, 1.0995933782266443, -0.33113212682370374, 1.8037136676881467, 1.9864856864601044, 1.9158887371178954, -1.9687350961864358, 1.0340815760985689, -1.4940490818120682, -0.5636916802124343, 0.7940861801407588, 1.8611959290700146, 0.05068559996433386, -1.4376838096823579, -0.7994300153113469, -1.0345736012578688, 0.28646664147286716, 0.42834419774223864, 1.9859302470507543, -1.581634416143304, -0.5908592058895636, 1.9946820679174095, -0.7362672596100315, -0.7753971669089599, -0.1461685435729474, 1.4961158060953679, 0.023600140681598436, 0.28842354097865597, 1.5178961463797345, 1.9722272765817803, 1.5820280859237066, -1.0654862724288034, -0.6719633182709019, -0.05183839905904897, 0.8634358995579046, 1.7116975014438398, -0.8883227639240556, -1.4193899119686022, -0.1181106926833424, -0.7288049208942184, -1.221089655183401, 1.413474407560341, 0.23040231217038754, -0.8388780150324511, -1.2477380649777432, -0.5583498912735565, 0.18076208825841, 0.32217834767149833, -0.6051915007598145, 0.4635184439118465, 0.5763778212100865, 0.5883046526966851, -0.1604367942767171, -0.4192753528200206, -0.2325991035981967, 1.8385946129700885, -0.769656093325612, 1.7796256331964417, 0.5517971015750223, 0.030195679837711875, 0.34508397161012105, -0.8406103541751757, -1.7389966198098783, -0.6007639353120675, 1.1647649284533435, -0.798496224909742, -0.4515512247115039, 1.2505504426455292, 0.7201584064962603, -0.392758345304947, 0.3289230169678339, 1.4550939270441803, -0.5376183065848124, 0.617469128279879, 1.1490173605586236, 0.6344593777838647, -1.6406172001626622, -1.2246699079133112, -1.846224692446273, 0.8449810629051684, -1.0792958573734963, -0.18889216771717177, 1.9521743055604066, -1.6733768228860328, 0.5131644991269373, 0.7234705788759577, 1.4764593264744623, -1.930088394750161, -0.9919436446687326, -1.1875460539101854, -1.0071679897017245, 0.0864697459015753, 0.96877055727058, 0.08138013868629823, 1.1514752853380825, 1.4488832571012944, -0.6058485159875397, -1.0423861007571786, -1.885452575096402, 0.768324611093806, 1.4689290850336536, -1.144254305822098, 1.5807900628436542, -1.4828314808356384, -0.08090547534229309, 0.40204865273027846, -0.7690774349114449, 0.7435915820259291, 0.7986477956381148, 1.8710723219141858, 0.2917925090558646, -0.6575075552805956, 1.5520425384470946, 1.328532348262335, 0.41075398686634124, 1.914449582860989, -1.6466359700425963, -0.3524497951309873, 1.9857183377443919, 1.336660026453616, -1.9621458632592672, 0.9243394663577331, -1.9709689402205663, 1.6842766768700734, 0.6570617881433001, -1.8004072351057565, 0.9845332047619624, -0.7599671608956635, -1.9827867667840442, 1.8653960711148412, 1.2755862668584763, -1.018035206929965, 1.3678585511645371, 0.7573509639861533, 1.3014513842386712, -1.1182311661558106, 1.8713276171426596, 0.996048386486796, -0.882875139811615, 1.1146622785505373, -1.4130437915984317, 0.2493079880646265, 1.1646977006918688, 1.1169935161302007, 0.14487510067815945, 1.5788662982113308, -1.712614598293237, 0.2569708834381923, 0.42141597613675064, 0.602129151107917, 0.49717355009522146, -0.8643072311457018, -0.5540850602532226, -1.7233191916253667, 0.6071193415030409, 0.7803456101227093, 0.6424196816323162, 1.7527071325827914, -1.8535222271426446, -1.2689872498992756, -1.1187158305070586, 0.9372546225121581, -1.229115002709337, -1.7361467373762567, -1.028299772755862, 0.2839380042863362, -0.2654221107041064, 0.10013099353305188, 1.173709226161228, -1.5042277167877023, -1.5199814297540364, -1.8048685542270793, 1.9412975220240725, 0.6934151957260211, 0.8685505332667764, 1.0951537588323448, -0.7075904318680171, -1.7313376975987342, 1.256809956661137, 1.8573667752918719, -1.350800941845713, -1.5436541381678537, -0.6612538173702882, -1.9666978175519865, -1.826976866950036, 1.373772560026595, -1.4974637665958532, -0.3713140899147489, 1.7005327998478572, 0.395340649892141, -0.3228096799887501, 0.06544719099673468, -0.9161823646973355, 0.9061250063818345, 0.7201058597956225, 1.7823400722337595, 0.30539234751635336, 0.26367255517368493, -1.4952794495723616, 0.0032786349488684863, -1.5374913053978925, 0.18293099672159885, 0.2692924981692584, 1.9512152633903024, 0.19438389365571052, 0.3924187764463949, -0.34690038933758105, 1.2662273068872447, -0.1580917859157145, -1.02495145576645, -1.6381757965357329, 0.7841810075324944, -1.8484745088922816, -0.10637623353975512, -0.8147694484648498, 0.06813978476975668, -0.7665595863124066, -0.20998011191520005, 0.3597790711832123, 0.02715249672895448, 0.4735802418102919, 1.3337786400346423, -1.4286194648587611, 1.6581278815688831, -1.66635946147187, -1.6148966379806948, 1.8860561762258778, -1.2587467173901645, -0.929587201930365, 0.10060778807353721, 0.958744322212727, 1.6724365701611057, 0.4115350075358011, 0.3515594983377195, 1.3260733945987977, -1.2423349056612087, 0.5649075021775634, -1.8134529192939666, 1.4745283869665586, 1.302865242934764, -1.9387220678983135, 0.7943203168137329, -0.6885168417265004, -0.29306744024201015, 0.5597698772586779, 1.9665757648810769, 0.743946600425287, -1.9678496095495817, 1.8184338784043383, -0.6304162175268861, -1.5739866940240366, -0.7879029941787801, -0.41953576964524286, -0.6425647489662847, -1.8436757612041927, 0.6418403574106546, 1.5366092051704823, 1.8935884277456263, -0.731750469588694, 1.3799765409672933, -0.6864707404098964, 0.6225608403060616, 0.38190938424824505, 0.34386761471868255, -1.9576899651274093, -0.5894082829354663, -0.11631880076376655, 0.3569488371391216, -0.05867377242990246, -1.8648587275500539, 1.1990130119372142, 0.4499094161539148, 0.06260492974826404, 1.2656695154749675, -1.119634822460121, 0.536855241903369, 0.17561694070886658, -1.9513044092111498, -1.7623493644417167, 1.9283701303246614, -0.6048362854755891, -0.9149543198035932, 0.2637846561470756, 1.0955624586630939, -0.8481673593000152, -1.1941276306258164, 0.6819516487580435, -1.532107070224293, -1.1998800299557022, -0.18158274702423816, 0.5439067466977852, 0.5209188575364374, -1.1474471852562256, 0.4134639316612647, 1.6634574849072599, 1.2556908181652746, 0.8288254154563672, -0.649095376909905, 0.7997112518858196, -1.6407453179574887, 1.9963242619776649, -0.8745519695047599, 1.6305680628968395, -1.0352629643568338, -0.9704968933197349, 0.06583178519073307, -1.1697046039326242, -1.541772833265148, -0.11556695520678195, 1.3346471556456652, -1.745740975436044, -1.539628414466466, 1.5276296331102608, 1.5557934052988154, 1.1074336277362753, 0.6045553985886847, 0.8994549959457574, -1.9572606530987469, 0.16730826193240889, 1.7041568292858407, -0.3853967605765911, -0.8262572931403112, 0.6905488173683407, 0.4115591121366662, 1.851323088431379, 1.7358701147666546, -1.296207409147439, 0.5727852260468724, 1.0524273636815171, 1.1521739730378964, -0.9649393869072016, 1.994432126040071, -1.3488541398427811, -0.7202570239842476, 1.6937333463419626, 1.6815459271668778, 0.9098483131303783, 1.762867618256248};
const double J[] = {1.0430341469551832, 1.1492468782662293, -0.35502347593242245, 1.0453404300004743, 1.3711170338928969, 1.3557743181224935, -0.5291258534619412, 1.1909596266652187, -0.6118033175795139, 1.2026463763717752, -0.6213122116660812, 0.6545232423956695, 1.9460452578783167, -1.8210528330331441, 1.4445859655858486, -1.9317481676478998, -1.2329251597284725, -1.2723071375291308, 0.7934183347129222, 0.9753446605781178, 0.7484197882436807, 1.8131734735164677, -0.009259859961267214, 1.7044263021060062, 1.6727918358102558, -1.5872171823792098, -0.422471728398071, 1.1057379620368724, -0.0311609470547225, -1.0747091558858939, -1.0837924472746505, 1.6997802958750707, 1.43095259831827, -0.718934719784103, -0.3267981304834935, -1.0238747674195356, -1.4586896621227181, -0.21480393028934408, -1.820701700493736, 0.5826663861835071, 1.344410484474642, -1.3803520568234102, -1.6664199383207747, -1.1011128140707718, -0.5030752151939977, -0.7559014982472392, -0.29929617340533676, -0.21924703886528274, 1.138263259760441, -0.10374301475910475, -0.3929614360352831, -1.0533419482103312, -1.3871675737100224, -0.8027565140084727, -1.5195470342196757, 1.8531130942528846, 0.978184260679575, 1.7271366963216424, 0.19654340746947874, 0.6243606192582107, -0.24475012558391107, -0.4366832210021805, -1.9860606598296622, -1.460111036665808, -0.5328311445373841, -0.6911213793614608, 1.3777288708211337, 1.901572095578727, 0.5489866805023356, -0.22266376762838158, -1.0937131260716453, 1.873969622397571, -0.440522636834054, 1.773764129366624, -0.7045920899382927, -0.7368695243552352, 0.9659348869134714, -1.7719174194296707, -1.931778327946637, 1.7029356598723622, 1.8339525237979752, 0.7328829378996415, 0.09010488098745384, -0.7654296058062515, -0.49412111019923666, -0.6677048183954577, -0.11508644216169284, -0.5279785640059931, -0.9798994171345274, 0.20018836110088145, 0.2307011967453656, -0.5310364441662303, 0.5878615351754255, -0.4795334197263017, 0.875704595966976, -0.3366378717151046, 1.348402783490597, -1.1632440292830384, -1.7713269502822722, 1.7458840064110959, 1.439160115732368, -1.0850675155949832, 0.26784324763152556, 1.2268491255401948, 1.1175471220299857, -1.9113747498983407, 0.45319655866849606, -0.26752212766500527, 1.3848714730160996, -0.4595246381398148, 1.2788960600478028, -1.7967339449884712, 1.723013958507138, 1.8198480355031803, 0.6868259745805791, 1.1245170813506622, -0.010653358173903005, -0.14631702138592484, -1.0215592262879407, 0.7706258417083212, -0.24515628313233506, -1.7964007308804733, -0.9306956185460415, -1.1000059732702545, -1.254360017821428, 0.7414441333732618, -1.966145781518672, -0.6301583494197471, 0.23688196622049018, 0.6541194664682592, 0.527246128648442, -1.4056123651345214, 1.4196873713401907, -0.72881883562841, -0.21445654837949135, -1.5213480804102062, 0.9198345905110861, -1.93435754071671, 0.5661169730073103, 1.8351323708443665, 1.9108693578827305, -1.2086561584183575, -0.014519328123423048, -1.2589176974973002, 1.69687564567091, 0.16580880415391785, 0.8457910158526492, -1.080941757641574, 1.9324446925404737, 1.3923523167383354, 0.9896593082716363, -1.9159177880796534, -0.07058718242040563, 1.4825273481682393, 1.9040122322053752, -1.8495427935526245, -1.2595636165342756, -1.0755200717073223, 0.3450437168133793, 0.5227908026750616, 1.8004770176224394, 1.2747937424558482, -1.6006925457549843, 0.7104981653828211, -1.2647099219551827, 1.3727234749528079, -0.17145123135154794, 1.5294617076779304, 0.17197175303739165, 0.6033965673153525, -1.819351431673776, 0.03225825158102236, 1.0847359767240077, 0.14358174499987753, 1.1696854464754254, 1.6519301714539747, 1.4439241384060382, 1.5604916492210283, -1.4945206956206354, -1.1466026870642723, 0.0633504330260295, -0.8100661090266743, -1.5094567761216946, -1.3869716281961164, -0.1523504932253883, -1.952867140111505, 0.5365573844052913, 1.116783031585736, 1.4687975070094619, 1.855879263043855, 0.9960765883668197, 1.6902146451378037, 0.6805634942930454, -1.8572937006378538, -0.1282023829149166, 0.751667100669684, -0.9237997086295362, 1.5659371468890222, 1.4875174032370246, -1.1842423487355114, -0.47781534156280214, 1.0238914305565188, 0.6291479767432704, 0.05852443700544718, 1.8755726255424223, -0.589156344208233, -1.0848778500528051, 0.9595295881204593, -1.4272405306329436, -1.4472818735591106, 1.3197081986691614, 0.5136307915424307, -0.28054826478336636, 0.7036895301076163, 0.6498552629670158, 1.681191489273043, -0.5052172526949081, 1.018212411356573, -1.2580352350808286, -0.9002247953249531, 0.2728001618650264, -1.0050284969571823, 1.8202796639642682, -0.4686431790282293, -1.7102396177470425, -1.7394767688434025, -0.424142612735142, 1.2539146647145851, -1.2725526095706945, -0.8459747755876168, -0.7315816433989775, -1.5937957203365758, 0.7169883292332742, 0.867606720846581, -0.2629086198758883, -1.2129182027710503, -1.667146868264532, -0.7418684637185526, 0.3242559812407797, 0.14910698723082394, 0.21357558659411469, 1.747444185021363, -0.04557480154583127, -1.9219335846064696, 1.2231897085495973, 1.4198419676542762, 1.7003954607096725, -0.6669925304231255, 0.5635801578540689, 1.1169635547603334, -1.8665459518212146, -0.8485508845835783, -0.8746830299465502, 1.8306492136714776, 1.867535640351948, -1.9636758459557146, -0.18933539890968776, -0.8712199111024996, 1.2242104672515683, -1.1049252867833004, 0.4764278995038693, -0.3559277053461818, 1.9064750320064414, -0.1413858218202999, 1.2478835890610314, 0.6350115557386493, -1.9525577509303584, -1.388501817069208, 1.2299100185927334, -0.3695257885155572, -1.871895404752978, -1.7902022305943754, 1.8137938943629286, 0.5666413633932663, 1.1138992458318326, -0.671160004107132, -1.6949903226148808, 1.7906717381094603, 1.1977087009311491, 1.0149728527403519, -1.1641468582479337, 1.5395798926099413, -0.17475885426594484, 1.124798902361289, -0.8825300697010618, -1.5179199562433814, 1.5520772634119568, -1.9289926259812722, -0.23906009349982815, -1.4754280743438497, 1.2333386321362578, -1.8758191236629025, 0.7474827236563746, -0.06531949901756162, -0.5942998152064072, -1.223328402586107, 1.9858083508462876, -0.04865994755164893, 0.3447696706656367, -1.6696632050166231, -0.5037190265916367, 0.8148808352094723, -0.5303906610672877, -0.7939720806699984, -1.282101210978575, 1.7093510050490486, -0.8813668431539217, -0.5564915806075215, 0.6876676102799402, -0.3872590090936745, 0.757632806320979, -1.0724210882725878, 0.5452899893056453, 1.5375892940381388, 1.614381780939187, -1.2948175653678948, -1.0261818452237503, -1.5542546175861385, 0.6360734760303592, -0.5801773643445518, 1.1006872432723855, 1.9336637521412077, -0.2948464743057122, 0.8197497406668957, 1.3919856358672686, 1.5648971323471996, 0.32479931228215086, -1.275485111985006, -0.8374345919533903, 0.2887759851333853, 1.0541247367727489, 1.51436345697672, 0.7700420187949435, 0.42621103003799243, 1.9637175644917462, 1.0806198495849273, -1.1400428119857793, -1.479790903815029, -0.8008488013348902, 0.38996932662360173, -0.7451997524043277, -1.6133619705599922, 1.27592855298952, -0.18810434343029447, -1.6114316755335754, 0.42961230454209165, -0.47144451332835313, 0.5867421333342344, 0.5312031613404975, 1.9139693134474793, 1.0574123837422165, 0.47278569244078295, -0.7141334279962805, 0.46301619351097667, -1.1411481177149865, 0.731389543521499, 1.836155470531006, 1.7518018630344692, -0.9012380459443574, -0.8463816118160286, 0.5009465787675182, 1.5489168306144991, 1.9836779399280458, -0.6214312470046641, -0.46461517016342935, -0.5120828822950387, -0.7283677941154432, -0.17528939755197293, -1.3482085359979608, 1.5214696291784278, -1.7859401557937518, 1.5943047201549794, -0.1234910552005557, 0.8422309509981831, 0.30781217320991194, 1.6075914773950837, -0.8111839660891924, -0.14685382501626387, 1.3799372561493892, -1.582153182088664, 0.29430375991702995, -1.6931406655237602, 1.6299198335156455, 0.06828579111101707, -1.4996564276424151, -0.9397952061553796, -1.9738184601337037, 0.2495410485083256, 1.0429952088101815, -1.643779855011458, -1.3765274249026018, 1.2960557694365211, 0.4549707772087199, -1.668171846239817, -1.8851208680131282, -1.5543613285305136, -1.751563284535366, 1.0027128587537506, -1.0755584585597924, -1.053506174753283, 1.8119482175584918, -1.262364091972675, 0.43785005546796407, -0.05315267312778582, 1.4654008344849632, 0.12453999617144484, -1.9039846055795744, -1.4132915822593537, -1.4639964779467642, -0.824504987074425, 1.418312141164734, 0.2876825034423618, -0.07854853044776, 0.058436072881226764, 1.4092499646284766, 0.7177327234337967, -0.4635167794602024, 1.0747739438293178, 0.2284043736221113, 1.4551528821570563, 1.8094343932692039, -0.20586111601742463, -0.6444158283879395, -1.5510376904202192, 0.3532664135689103, -1.2150580155251358, 1.6626291329351321, -1.25084543240615, -1.1537525932267294, 1.6298084859236304, -0.500797393381279, -1.6649336941682655, 1.2537834203833826, -1.9626146933619295, 0.27812188136892013, 1.991870950153535, 0.7903901315983388, 0.48291860980307266, 1.5363660037794236, -0.7602436622435724, -0.7107688160814924, -1.6604082184956601, 1.575433787378684, -0.43957808188866077, -1.1068314815011404, -1.0169720828645876, -0.042372960620914224, -1.7183233518519736, -1.9279643431665363, 0.5691640242832725, 0.7218552793877224, -1.5446225502318325, 1.216227699674691, 0.1876652210515184, 1.1749648909161636, -0.68447454255816, -0.38862337858855556, 1.5309088689170358, -0.9243346795316545, -0.38430457041125, -0.818907342458254, 1.6162641755348135, 0.3234131202193229, -1.29162195553385, -1.1106419376180985, 0.8197396417326286, -0.062105923312582245, 1.9520494651992903, -1.611393611908143, -1.0360760105324305, 1.8811957493401104, 1.2523551338626957, -1.5055928336782962, -0.6857439604970157, 0.3047978508070024, 0.6140288951458923, 1.9707843308141646, -0.23322378792412257, -1.168417204506106, -0.7524885154562027, 0.807947917436048, 0.521607931459322, -0.6275547638104744, -1.3769705665707725, -0.0556139247781382, -0.9875818248535078, -0.49277248521732187, 1.7496063274897895, -0.1472093045637477, 1.3816266843528062, -0.7462755851047977, -1.197983124751138, -0.7843612594777847, 1.3143312156642506, -0.9513355486676693, -0.48358573582600917, 0.14122298738699968, -1.2542938218876554, -0.702711473632919};

module CZ(qbit q1, qbit q2, double phi) {
    Rz(q2, 0.5*phi);
    CNOT(q1, q2);
    Rz(q2, -0.5*phi);
    CNOT(q1, q2);
}

module ZcrossZ(qbit q1, qbit q2, double phi) {
    // printf("performing sigma_z cross sigma_z Hamiltonian\n");
    Rz(q1, phi);
    Rz(q2, -phi);
    CZ(q1, q2, -2.0*phi);
}

module initialize(qbit reg[N]) {
  int n;
  for(n=0; n < N; n++) {
    PrepZ(reg[n], 0);
    H(reg[n]);
  }  
}

module red_hamiltonian(qbit reg[N], int m) {
  int n;
  for (n = 0; n < N-1; n += 2) {  // red pairs
    double phi = J[n] * (2.0*m - 1) / M;        
    ZcrossZ(reg[n], reg[n + 1], phi);
  }
}

module black_hamiltonian(qbit reg[N], int m) {
  int n;
  for (n = 1; n < N-1; n += 2) {  // black pairs
    double phi = J[n] * (2.0*m - 1) / M;        
    ZcrossZ(reg[n], reg[n + 1], phi);
  }
}

module Bz_hamiltonian(qbit reg[N], int m) {
  int n;
  for (n = 0; n < N; n++) {
    double theta1 = (1.0 - (2.0*m-1)/M) * -2 * Bx * total_T / M;
    double theta2 = (1.0 - (2.0*m-1)/M) * -2 * Bz[n] * total_T / M;     
    H(reg[n]);
    Rz(reg[n], theta1);
    H(reg[n]);
    Rz(reg[n], theta2);    
  }
}

module measure(qbit reg[N]) {
  int n;
  for (n = 0; n < N; n++) {
    MeasZ(reg[0]);
  }  
}

int main() {
  qbit reg[N];
  
  // Initialize all qubits to |+> state
  initialize(reg);
  
  int m;
  for (m=1; m <= M; m++) {
    // Z-Z Hamiltonian, executed in parallel across qbits
    red_hamiltonian(reg, m);    
    black_hamiltonian(reg, m);
    // Bz Hamiltonian, executed in parallel across qbits   
    Bz_hamiltonian(reg, m);
  }

  // Measure all qubits in Z basis
  measure(reg);

  return 0;
}
back to top