Skip to content

Commit cabede2

Browse files
chore: used qutips own compute fidelity
1 parent 27bc48e commit cabede2

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

tutorials-v5/optimal-control/control-grape-cnot.md

+1-27
Original file line numberDiff line numberDiff line change
@@ -179,33 +179,7 @@ U_f
179179
```
180180

181181
```python
182-
def overlap(U_target, U_f):
183-
"""
184-
Calculate the overlap between the target unitary U_target and
185-
the final unitary U_f.
186-
187-
Parameters:
188-
U_target (qutip.Qobj): Target unitary operator.
189-
U_f (qutip.Qobj): Final unitary operator.
190-
191-
Returns:
192-
float: Real part of the overlap value.
193-
float: Fidelity (absolute square of the overlap).
194-
"""
195-
# dividing over U_target.shape[0] is for normalization
196-
overlap_value = (U_target.dag() * U_f).tr() / U_target.shape[0]
197-
fidelity = abs(overlap_value) ** 2
198-
return overlap_value.real, fidelity
199-
200-
201-
# Example usage
202-
overlap_real, fidelity = overlap(U_target, U_f)
203-
print(f"Overlap (real part): {overlap_real}")
204-
print(f"Fidelity: {fidelity}")
205-
```
206-
207-
```python
208-
np.shape(U_f)
182+
print(f"Fidelity: {qt.process_fidelity(U_f, U_target)}")
209183
```
210184

211185
## Proceess tomography

0 commit comments

Comments
 (0)