From b47d9a05de90b1c2ec9fa531c545662d84f25f6f Mon Sep 17 00:00:00 2001 From: JesU2504 <119404538+JesU2504@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:21:43 +0900 Subject: [PATCH] Add files via upload --- codes/satisfy_ansatz.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 codes/satisfy_ansatz.py diff --git a/codes/satisfy_ansatz.py b/codes/satisfy_ansatz.py new file mode 100644 index 00000000..f5e67840 --- /dev/null +++ b/codes/satisfy_ansatz.py @@ -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')) +