Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JesU2504 authored Oct 18, 2023
1 parent 4751462 commit b47d9a0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions codes/satisfy_ansatz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import sys
sys.path.insert(0, '../')
import qtm.qcompilation

def find_satisfying_ansatz(num_qubit, max_depth, num_param ,state_name):
best_fidelity = 0
best_state = qtm.qsp.QuantumStatePreparation(f"../experiments/qsp/{state_name}_g2_{num_qubit}_1.qspobj")

for i in ['g2gn','g2','g2gnw']:
for j in [1,2,3,4,5,6,7,8,9,10]:
qspobj2 = qtm.qsp.QuantumStatePreparation(f"../experiments/qsp/{state_name}_{i}_{num_qubit}_{j}.qspobj")

# Compare fidelity
if qspobj2.fidelity > best_fidelity:
best_state = qspobj2
best_fidelity = qspobj2.fidelity
if qspobj2.fidelity == best_fidelity:

# When fidelity is the same, compare depth
if qspobj2.u.depth() < best_state.u.depth():
best_state = qspobj2

# When depth is the same, compare num_params
elif qspobj2.u.depth() == qspobj2.u.depth():
if qspobj2.num_params < best_state.num_params:
best_state = qspobj2

return best_state.ansatz

print(find_satisfying_ansatz(3,2,2,'AME'))

0 comments on commit b47d9a0

Please sign in to comment.