<jupyter_start><jupyter_text>Example: Find the data from qRAMPrepare a qRAM of $n$-addresses in which the numbers $k_0, k_1, .. , k_{n-1}$ are stored in this order.  Find the address in which the number $m$ is stored using Grover's algorithm.  - $n = 4$- $k = [1,2,5,7]$- $m = 5$ qRAM operation.Here we show a circuit example of qRAM.<jupyter_code>address = QuantumRegister(2)
data = QuantumRegister(3)
oracle = QuantumRegister(1)
c = ClassicalRegister(2)
qc = QuantumCircuit(address,data,oracle,c)

# address preparation
qc.h([address[0],address[1]])
qc.x(oracle[0])
qc.h(oracle[0])
qc.barrier()

##Qram part

# address 0 -> data = 1 (001)
qc.x([address[0],address[1]])
qc.ccx(address[0],address[1],data[2]) 
qc.x([address[0],address[1]])
qc.barrier()

# address 1 -> data = 2 (010)
qc.x(address[0])
qc.ccx(address[0],address[1],data[1])
qc.x(address[0])
qc.barrier()

# address 2 -> data = 5 (101)
qc.x(address[1])
qc.ccx(address[0],address[1],data[2])
qc.ccx(address[0],address[1],data[0])
qc.x(address[1])
qc.barrier()
# address 3 -> data = 7 (111)
qc.ccx(address[0],address[1],data[2])
qc.ccx(address[0],address[1],data[1])
qc.ccx(address[0],address[1],data[0])
qc.barrier()

#flip phase of m = 5 (101)
qc.x(data[1])
qc.mct([data[0], data[1], data[2]], oracle[0], mode='noancilla')
qc.barrier()

## Reverse Qram part

# address 3 -> data = 7 (111)
qc.ccx(address[0],address[1],data[2])
qc.ccx(address[0],address[1],data[1])
qc.ccx(address[0],address[1],data[0])
qc.barrier()

# address 2 -> data = 5 (101)
qc.x(address[1])
qc.ccx(address[0],address[1],data[2])
qc.ccx(address[0],address[1],data[0])
qc.x(address[1])
qc.barrier()

# address 1 -> data = 2 (010)
qc.x(address[0])
qc.ccx(address[0],address[1],data[1])
qc.x(address[0])
qc.barrier()

# address 0 -> data = 1 (001)
qc.x([address[0],address[1]])
qc.ccx(address[0],address[1],data[2])
qc.x([address[0],address[1]])
qc.barrier()


#diffusion
qc.h(address[:2])
qc.x(address[:2])
qc.h(address[1])
qc.cx(address[0], address[1])
qc.h(address[1])
qc.x(address[:2])
qc.h(address[:2])

#Measure the address
qc.measure(address[0:2], c[0:2])

# Reverse the output string.
qc = qc.reverse_bits()

#backend = provider.get_backend('ibmq_qasm_simulator')
backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend=backend, shots=80000, seed_simulator=12345, backend_options={"fusion_enable":True})
result = job.result()
count =result.get_counts()
print(count)

qc.draw(output='mpl')<jupyter_output>{'10': 80000}
{'fraction_non_alphanumeric': 0.21844660194174756, 'fraction_numerical': 0.061893203883495146, 'mean_word_length': 6.426426426426427, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '648752', 'license': 'MIT', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1036, 'n_words': 194, 'path': 'qiskit/challenges/IBMQuantumChallenge_NOV_2020/hints/hint_2b_nb/Search QRAM Example.ipynb', 'repo_name': 'mickahell/quantum_experiences', 'size': '2472'}