0% found this document useful (0 votes)
10 views

Quant Rinku

Uploaded by

KRISH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
10 views

Quant Rinku

Uploaded by

KRISH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
= A corel) Out signers © Quantum Assignment nhs covr Ad commen 422MA2148 Rinku Grover's Algorithm (rowe's igo a quantum search alg that can search an unsorted database uacaticaly ester han essial algorithms fon aiskit import uantuncireust, Aer, transpite, assenbte sport manpy 22 mp ~ gen rengein)) {Ge append or ge-x, rengelnl) fence List argent), 2) centred) {-26pendor gen, rangein!) et prover searchin, aarkedclenet) (= Ooantncireust ne 9) (eshrongelnet)) rum-iterations = intnp.pi/4 = mp.sart(2ven / en\markedelenent) fof elenent £9 worked stent Spplyetfurson ae, 9) oe angen) Ger oracte.gote(@e, marked.eleren, or sndex, valve In eroneatel reverseo(narked etenet)) geomet (List range), or sndex, value in enunerae( reversedinared eteret) Statue == 1 betine the marked elenent(s) in the rarked element = ("130") Srover-cirest ~ grover searchin, marked clement) sme @ O teow backend = Aer. get_packendlgasn_sinitator®) ‘ranspited_eleeust = transpitegrover-cireut, backend) Fesult = Backend. run qos). resutt) Counts = resuttget-counts|) Explanation: pthoncny cote ‘ron aise soport QuantunCircuit, er, transpile, asserble ‘ron qiskt.visialization import plot histogran sport numpy 35 0 ‘Thi section imports the necessary modules from Qik for buleing quantum ccults and \eualinng resus. so imports NumPy for numetes computations gerhirongen)) {Ge append or ge-x, rengeln)) centre eanct (List angen), #2) GE aopendor(ge-x, rengeln!) ecnrenetn)) ‘+ The apply-aitfusion function implements the fusion operator, ake sep in Grover's algorti which vets the ampltude about the mean, et orover searchin, marked etenent) Genironeind ‘in_Sterations ~ Snsap.pi/4 » mp.sarti2ien / enimarkedlenent) Pee ea ee Tor element in marked stent apply siffsion ae, 6) e-measurel range), angen) “+ arover_searah is the main function implementing Grover’ algorthn intaizes 2 quantum rut wth nex qubits and apples Hadamard gates toa ub, caleulates he optimal numberof erations anc ten executes the Grover erations: applying the orale and Gtfuson operators um iterations times. ‘for index, value in enunerate(reversed\narked_elevent) stvaive == "T gesmet List range), or index, value ih enunerate( eversed(nared etenet}) ‘+ The orsete sate function constts the os, flpping the son ofthe marked elements rnarkedeteent = (110) Grover_cirust = groversearenin, arked_etenent) Sackend = ergot backed 'guse simulator") Fesult = Sockend. un qos) result) Counts = result get_counts\) Dlat-hstogran(counts) ‘This par intiizes the marked laments in th database, tines the number of quits, creates the Grover'scxcul, transis ito the simulator backend, runs the crcl, reteves ‘the osu and fly vues the resulta a histogram.

You might also like