-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcost_function.py
More file actions
31 lines (19 loc) · 965 Bytes
/
cost_function.py
File metadata and controls
31 lines (19 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from cloning_circuit import create_cloning_circuit
from fidelity_count import calculate_fidelity
def compute_cost(thetas, phis = [0, np.pi/2, np.pi, 3*np.pi/2]) :
"""Computes the cost function, default values of phi are given as [0, np.pi/2, np.pi, 3*np.pi/2]"""
cost_function = 0
for phi in phis :
circuit = create_cloning_circuit(phi, thetas)
F1, F2 = calculate_fidelity(circuit)
cost_function += (1-F1)**2 +(1-F2)**2 + (F1-F2)**2
return(cost_function)
## TO TEST AND SEE WHAT THE FUNCTION DOES
# phis = [0, np.pi/2, np.pi, 3*np.pi/2] # Values we need to train the variational cloning machine. These are the default values so in practice
# no need to put in in argument.
# # A random seed for reproducibility
# np.random.seed(153)
# thetas = [np.random.uniform(0, 2 * np.pi) for _ in range(12)] # random initial values
# COST = compute_cost(thetas)
# print("Cost function is :", COST)