forked from NVIDIA/cuda-quantum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgate_calibration.py
More file actions
93 lines (74 loc) · 3.23 KB
/
gate_calibration.py
File metadata and controls
93 lines (74 loc) · 3.23 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import cudaq
from cudaq import boson, Schedule, ScalarOperator, ScipyZvodeIntegrator
import numpy as np
import cupy as cp
import os
import matplotlib.pyplot as plt
# This example demonstrates the use of the dynamics simulator and optimizer to optimize a pulse.
# Set the target to our dynamics simulator
cudaq.set_target("dynamics")
# Sample device parameters
# Assuming a simple transmon device Hamiltonian in rotating frame.
detuning = 0.0 # Detuning of the drive; assuming resonant drive
anharmonicity = -340.0 # Anharmonicity
sigma = 0.01 # sigma of the Gaussian pulse
cutoff = 4.0 * sigma # total length of drive pulse
# Dimensions of sub-system
# We model `transmon` as a 3-level system to account for leakage.
dimensions = {0: 3}
# Initial state of the system (ground state).
psi0 = cudaq.State.from_data(cp.array([1.0, 0.0, 0.0], dtype=cp.complex128))
def gaussian(t):
"""
Gaussian shape with cutoff. Starts at t = 0, amplitude normalized to one
"""
val = (np.exp(-((t-cutoff/2)/sigma)**2/2)-np.exp(-(cutoff/sigma)**2/8)) \
/ (1-np.exp(-(cutoff/sigma)**2/8))
return val
def dgaussian(t):
"""
Derivative of Gaussian. Starts at t = 0, amplitude normalized to one
"""
return -(t - cutoff / 2) / sigma * np.exp(-(
(t - cutoff / 2) / sigma)**2 / 2 + 0.5)
# Schedule of time steps.
steps = np.linspace(0.0, cutoff, 201)
schedule = Schedule(steps, ["t"])
# We optimize for a X(pi/2) rotation
target_state = np.array([1.0 / np.sqrt(2), -1j / np.sqrt(2), 0.0],
dtype=cp.complex128)
# Optimize the amplitude of the drive pulse (DRAG - Derivative Removal by Adiabatic Gate)
def cost_function(amps):
amplitude = 100 * amps[0]
drag_amp = 100 * amps[1]
# Qubit Hamiltonian
hamiltonian = detuning * boson.number(0) + (
anharmonicity / 2) * boson.create(0) * boson.create(
0) * boson.annihilate(0) * boson.annihilate(0)
# Drive term
hamiltonian += amplitude * ScalarOperator(gaussian) * (boson.create(0) +
boson.annihilate(0))
# Drag term (leakage reduction)
hamiltonian += 1j * drag_amp * ScalarOperator(dgaussian) * (
boson.annihilate(0) - boson.create(0))
# We optimize for a X(pi/2) rotation
evolution_result = cudaq.evolve(hamiltonian,
dimensions,
schedule,
psi0,
observables=[],
collapse_operators=[],
store_intermediate_results=False,
integrator=ScipyZvodeIntegrator())
final_state = evolution_result.final_state()
overlap = np.abs(final_state.overlap(target_state))
print(
f"Gaussian amplitude = {amplitude}, derivative amplitude = {drag_amp}, Overlap: {overlap}"
)
return 1.0 - overlap
# Specify the optimizer
optimizer = cudaq.optimizers.NelderMead()
optimal_error, optimal_parameters = optimizer.optimize(dimensions=2,
function=cost_function)
print("optimal overlap =", 1.0 - optimal_error)
print("optimal parameters =", optimal_parameters)