<jupyter_start><jupyter_text><jupyter_code># Function to convert binary fractional to decimal  
def binaryToDecimal(binary, length) : 
    point = binary.find('.') 
    if (point == -1) : 
        point = length  
    intDecimal = 0
    fracDecimal = 0
    twos = 1
    for i in range(point-1, -1, -1) :  
        intDecimal += ((ord(binary[i]) - 
                        ord('0')) * twos)  
        twos *= 2
    twos = 2
    for i in range(point + 1, length): 
        fracDecimal += ((ord(binary[i]) -
                         ord('0')) / twos);  
        twos *= 2.0 
    ans = intDecimal + fracDecimal 
    return ans 


def qpe_c_unitary(circ,n,phase):
    repetitions = 1
    for j in range(n):
        for i in range(repetitions):
            circ.cphaseshift(j, n, 2*pi*phase); 
        repetitions *= 2

def add_qft_n(circ, n):
    for j in range(n):
        circ.h(j)
        for k in range(j+1,n):
            circ.cphaseshift(k, j, pi/float(2**(k-j)))
    for qubit in range(n//2):
        circ.swap(qubit, n-qubit-1)


def add_qft_dagger_n(circ, n):
    for qubit in range(n//2):
        circ.swap(qubit, n-qubit-1)
    for j in range(n):
        for m in range(j):
            circ.cphaseshift(j, m, -pi/float(2**(j-m)))
        circ.h(j)
    for qubit in range(n//2):
        circ.swap(qubit, n-qubit-1)<jupyter_output><empty_output><jupyter_text>Test for |110><jupyter_code>circ = Circuit()

n=5
phase=0.333

for j in range(n):
    circ.h(j)

# Input Function
circ.x(n)
qpe_c_unitary(circ,n,phase)

#add n Qubit QFT-1
add_qft_dagger_n(circ,n)


print(circ)
task = device.run(circ, s3_folder, shots=4000)
while task.state() != "COMPLETED" :
    print(task.state())
    time.sleep(3)
print(task.state())
result = task.result()
print(f"measurement_counts: {result.measurement_counts}\n")
print(f"measurement_probabilities: {result.measurement_probabilities}\n")
# Categorize measurements by input register values
import matplotlib.pyplot as plt
%matplotlib inline

answer_plot = {}
for measresult in result.measurement_counts.keys():
    measresult_input = measresult[:n] #First n qubits
    if measresult_input in answer_plot:
        answer_plot[measresult_input] += result.measurement_counts[measresult]
    else:
        answer_plot[measresult_input] = result.measurement_counts[measresult] 

print(f"measurement_of_input_registers: {sorted(answer_plot, key=answer_plot.__getitem__,reverse=True),}\n")
#plt.bar(answer_plot.keys(), answer_plot.values())
plt.bar(sorted(answer_plot, key=answer_plot.__getitem__,reverse=True),sorted(answer_plot.values(),reverse=True))
plt.xticks(rotation=45)
plt.show()

for i in sorted(answer_plot, key=answer_plot.__getitem__,reverse=True):
    out=str(i)
    print(i,int(out,2)/2**len(out),answer_plot[i]/10,"%")<jupyter_output>01011 0.34375 262.3 %
01010 0.3125 76.9 %
01100 0.375 18.8 %
01001 0.28125 11.9 %
01101 0.40625 6.3 %
01000 0.25 4.1 %
01110 0.4375 3.6 %
00111 0.21875 2.3 %
01111 0.46875 1.9 %
00101 0.15625 1.4 %
00110 0.1875 1.2 %
10000 0.5 0.8 %
10101 0.65625 0.8 %
11001 0.78125 0.6 %
10011 0.59375 0.6 %
00100 0.125 0.6 %
00000 0.0 0.6 %
00001 0.03125 0.6 %
10010 0.5625 0.5 %
10001 0.53125 0.5 %
10100 0.625 0.5 %
11101 0.90625 0.4 %
11011 0.84375 0.4 %
10110 0.6875 0.4 %
00011 0.09375 0.4 %
11000 0.75 0.4 %
11111 0.96875 0.3 %
11110 0.9375 0.3 %
11010 0.8125 0.3 %
00010 0.0625 0.1 %
11100 0.875 0.1 %
10111 0.71875 0.1 %
{'fraction_non_alphanumeric': 0.14437242192103714, 'fraction_numerical': 0.12905126694166175, 'mean_word_length': 3.0272835112692764, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '204388', 'license': 'Apache-2.0', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1359, 'n_words': 298, 'path': '07-QPE_n-Qubit_LocalSimulator.ipynb', 'repo_name': 'jag-p/braket-sample-notebooks', 'size': '3394'}