├── .gitignore
├── 1 Qubit Process Tomography.ipynb
├── 2 Qubit Process Tomography.ipynb
├── Almaden Qutrit Rabi- Two Photon Process and cycling.ipynb
├── Almaden Qutrit Rabi- Two Photon Process.ipynb
├── Almaden Qutrit Rabi.ipynb
├── CH4_2Qubit_Ham_Dyn.ipynb
├── CNOT_SIMULATED.ipynb
├── CrossResonance_Tomography.ipynb
├── CrossResonance_Tomography_SIMULATED.ipynb
├── DRAG_Dephasings.ipynb
├── DRAG_Dephasings_SIMULATED.ipynb
├── Figures
├── CR_X.png
├── CR_X.svg
├── CR_X_SIMULATED.png
├── CR_X_SIMULATED.svg
├── CR_Y.png
├── CR_Y.svg
├── CR_Y_SIMULATED.png
├── CR_Y_SIMULATED.svg
├── CR_Z.png
├── CR_Z.svg
├── CR_Z_SIMULATED.png
├── CR_Z_SIMULATED.svg
├── Cross_Gate_Pulse_Cancellation_Figures.ipynb
├── Figures.pptx
├── QubitVisualizationFigure.ipynb
├── RB.png
├── RB.svg
├── benchmark_results.nb
├── bloch_states.png
├── bloch_states.svg
├── compilation_flow.png
├── direct_x.png
├── direct_x.svg
├── drag_trajectory_2d.png
├── drag_trajectory_2d.svg
├── drag_trajectory_2d_SIMULATED.png
├── drag_trajectory_2d_SIMULATED.svg
├── drag_trajectory_2d_SIMULATED_inset.svg
├── drag_trajectory_bloch_sphere.png
├── drag_trajectory_bloch_sphere.svg
├── drag_trajectory_bloch_sphere_SIMULATED.png
├── drag_trajectory_bloch_sphere_SIMULATED.svg
├── error_reduction.png
├── inline_pulse_image.png
├── open_cnot_histogram.png
├── open_cnot_histogram.svg
├── optimized_open_cx.png
├── optimized_open_cx.svg
├── rx_standard_vs_direct.png
├── rx_standard_vs_direct.svg
├── rx_standard_vs_direct_residuals.png
├── rx_standard_vs_direct_residuals.svg
├── standard_open_cx.png
├── standard_open_cx.svg
├── standard_vs_direct_x_gate.ipynb
├── standard_vs_direct_x_gate.png
├── standard_x.png
├── standard_x.svg
├── target_x_experimental.png
├── target_x_simulated.png
├── target_y_experimental.png
├── target_y_simulated.png
├── target_z_experimental.png
├── target_z_simulated.png
├── zz_fidelity.png
└── zz_fidelity.svg
├── H2O_2Qubit_Ham_Dyn.ipynb
├── H2_VQE_2Qubit.ipynb
├── LiH_VQE_3Qubit.ipynb
├── OpenPulse Experiments.ipynb
├── OpenPulse vs OpenQASM.ipynb
├── Open_CNOT_EXPERIMENT.ipynb
├── QAOA_2Qubit_EXPERIMENT.ipynb
├── QAOA_2Qubit_EXPERIMENT_STANDARD_RX.ipynb
├── QAOA_5Qubit_EXPERIMENT.ipynb
├── Qubit Rabi.ipynb
├── Qutrit Rabi.ipynb
├── Qutrit Rabi_MeasurementLevel2.ipynb
├── Qutrit_Tests.ipynb
├── README.MD
├── RX_Gates.ipynb
├── RX_Tomo.ipynb
├── RX_Tomo_Armonk.ipynb
├── Randomized_Benchmarking_Armonk.ipynb
├── ReverseEngineerAlmadenParameters.ipynb
├── Scratchpads
├── Proof_of_ZZ_Identity.nb
└── Qutrit Rabi Exploratory.ipynb
├── TwoQubitDecompositionsIntoNativeGates.ipynb
├── ZZ_Interaction_EXPERIMENT.ipynb
├── ZZ_Tomo.ipynb
├── benchmarks.py
├── pulse_compiler_helper_fns.py
├── pulse_sim.ipynb
└── single_q_cal.ipynb
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.exe
7 | *.o
8 | *.so
9 |
10 | # Packages #
11 | ############
12 | # it's better to unpack these files and commit the raw source
13 | # git has its own built in compression methods
14 | *.7z
15 | *.dmg
16 | *.gz
17 | *.iso
18 | *.jar
19 | *.rar
20 | *.tar
21 | *.zip
22 |
23 | # Logs and databases #
24 | ######################
25 | *.log
26 | *.sql
27 | *.sqlite
28 |
29 | # OS generated files #
30 | ######################
31 | .DS_Store
32 | .DS_Store?
33 | ._*
34 | .Spotlight-V100
35 | .Trashes
36 | ehthumbs.db
37 | Thumbs.db
38 | __pycache__/
39 | .ipynb_checkpoints/
40 |
--------------------------------------------------------------------------------
/CNOT_SIMULATED.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import numpy as np\n",
10 | "import time\n",
11 | "from collections import namedtuple\n",
12 | "import matplotlib.pyplot as plt\n",
13 | "%matplotlib inline"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": 2,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "import qiskit as q\n",
23 | "import qiskit.tools.jupyter\n",
24 | "from qiskit.pulse import pulse_lib as _ # only want to call pulse_lib as q.pulse.pulse_lib\n",
25 | "from qiskit.test.mock import FakeAlmaden\n",
26 | "from qiskit.ignis.verification.tomography.data import marginal_counts"
27 | ]
28 | },
29 | {
30 | "cell_type": "code",
31 | "execution_count": 3,
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "import pulse_compiler_helper_fns"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": 4,
41 | "metadata": {},
42 | "outputs": [
43 | {
44 | "name": "stderr",
45 | "output_type": "stream",
46 | "text": [
47 | "/Users/pranavgokhale/Developer/qiskit/qiskit-terra/qiskit/pulse/channels/pulse_channel_spec.py:87: DeprecationWarning: The PulseChannelSpec is deprecated. Use backend.configuration() instead. The supported methods require some migrations; check out the release notes for the complete details.\n",
48 | " DeprecationWarning)\n"
49 | ]
50 | }
51 | ],
52 | "source": [
53 | "backend = FakeAlmaden()\n",
54 | "system = q.pulse.PulseChannelSpec.from_backend(backend)\n",
55 | "back_config = backend.configuration().to_dict()\n",
56 | "cmd_def = q.pulse.CmdDef.from_defaults(backend.defaults().cmd_def, backend.defaults().pulse_library)\n",
57 | "measure = cmd_def.get('measure', qubits=backend.configuration().meas_map[0])\n",
58 | "backend_sim = qiskit.Aer.get_backend('pulse_simulator')"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": 5,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "hamiltonian = {}\n",
68 | "hamiltonian['h_str'] = ['_SUM[i,0,1,wq{i}/2*(I{i}-Z{i})]', '_SUM[i,0,1,omegad{i}*X{i}||D{i}]',\n",
69 | " 'jq0q1*Sp0*Sm1', 'jq0q1*Sm0*Sp1', 'omegad1*X0||U0', 'omegad0*X1||U1']\n",
70 | "hamiltonian['qub'] = {'0': 2, '1': 2}\n",
71 | "hamiltonian['vars'] = {'wq0': 30.518812656662774, 'wq1': 31.238229295532093,\n",
72 | " 'omegad0': 0.1675, 'omegad1': 0.176,\n",
73 | " 'jq0q1': -0.0069}\n",
74 | "\n",
75 | "back_config['hamiltonian'] = hamiltonian\n",
76 | "back_config['noise'] = {}\n",
77 | "back_config['dt'] = 1.0\n",
78 | "back_config['ode_options'] = {}\n",
79 | "back_config['qubit_list'] = [0,1]"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {},
85 | "source": [
86 | "------"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": 6,
92 | "metadata": {},
93 | "outputs": [],
94 | "source": [
95 | "# first check |00>. CNOT should yield |00> again.\n",
96 | "circuit = q.QuantumCircuit(2)\n",
97 | "circuit.cx(0, 1)\n",
98 | "\n",
99 | "decomposed_circuit = circuit.decompose()\n",
100 | "#print(decomposed_circuit)\n",
101 | "\n",
102 | "pulse_compiler_helper_fns.update_basis_gates_and_cmd_def(decomposed_circuit, backend, system, cmd_def)\n",
103 | "transpiled_circuit = q.transpile(decomposed_circuit, backend, optimization_level=1)\n",
104 | "#print(transpiled_circuit)\n",
105 | "\n",
106 | "schedule = q.schedule(transpiled_circuit, backend=backend, cmd_def=cmd_def)\n",
107 | "schedule |= measure << schedule.duration"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": 7,
113 | "metadata": {},
114 | "outputs": [
115 | {
116 | "data": {
117 | "text/plain": [
118 | "array([0. , 4.85720941, 4.97172909, 9.82893851])"
119 | ]
120 | },
121 | "execution_count": 7,
122 | "metadata": {},
123 | "output_type": "execute_result"
124 | }
125 | ],
126 | "source": [
127 | "shots = 1000\n",
128 | "qobj = q.assemble(schedule, backend, \n",
129 | " meas_level=1, meas_return='avg', \n",
130 | " memory_slots=2,\n",
131 | " shots=shots, sim_config = back_config)\n",
132 | "evals, estates = backend_sim.get_dressed_energies(qobj)\n",
133 | "evals/2/np.pi"
134 | ]
135 | },
136 | {
137 | "cell_type": "code",
138 | "execution_count": 10,
139 | "metadata": {},
140 | "outputs": [
141 | {
142 | "name": "stdout",
143 | "output_type": "stream",
144 | "text": [
145 | "{'00000000000000000010': 5, '00000000000000000000': 9995}\n"
146 | ]
147 | }
148 | ],
149 | "source": [
150 | "shots = 10000\n",
151 | "\n",
152 | "qobj = q.assemble(schedule, backend, \n",
153 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[2]/2/np.pi],\n",
154 | " shots=shots, sim_config = back_config)\n",
155 | "result = backend_sim.run(qobj).result()\n",
156 | "print(result.get_counts())"
157 | ]
158 | },
159 | {
160 | "cell_type": "markdown",
161 | "metadata": {},
162 | "source": [
163 | "------"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": 11,
169 | "metadata": {},
170 | "outputs": [
171 | {
172 | "name": "stdout",
173 | "output_type": "stream",
174 | "text": [
175 | "{'00000000000000000010': 9982, '00000000000000000000': 18}\n"
176 | ]
177 | }
178 | ],
179 | "source": [
180 | "# now check |01>. CNOT should yield |01> again.\n",
181 | "circuit = q.QuantumCircuit(2)\n",
182 | "circuit.x(1)\n",
183 | "circuit.cx(0, 1)\n",
184 | "\n",
185 | "decomposed_circuit = circuit.decompose()\n",
186 | "#print(decomposed_circuit)\n",
187 | "\n",
188 | "pulse_compiler_helper_fns.update_basis_gates_and_cmd_def(decomposed_circuit, backend, system, cmd_def)\n",
189 | "transpiled_circuit = q.transpile(decomposed_circuit, backend, optimization_level=1)\n",
190 | "#print(transpiled_circuit)\n",
191 | "\n",
192 | "schedule = q.schedule(transpiled_circuit, backend=backend, cmd_def=cmd_def)\n",
193 | "schedule |= measure << schedule.duration\n",
194 | "\n",
195 | "\n",
196 | "qobj = q.assemble(schedule, backend, \n",
197 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[2]/2/np.pi],\n",
198 | " shots=shots, sim_config = back_config)\n",
199 | "result = backend_sim.run(qobj).result()\n",
200 | "print(result.get_counts())"
201 | ]
202 | },
203 | {
204 | "cell_type": "markdown",
205 | "metadata": {},
206 | "source": [
207 | "------"
208 | ]
209 | },
210 | {
211 | "cell_type": "code",
212 | "execution_count": 12,
213 | "metadata": {},
214 | "outputs": [
215 | {
216 | "name": "stdout",
217 | "output_type": "stream",
218 | "text": [
219 | "{'00000000000000000011': 9996, '00000000000000000001': 4}\n"
220 | ]
221 | }
222 | ],
223 | "source": [
224 | "# now check |10>. CNOT should yield |11>.\n",
225 | "circuit = q.QuantumCircuit(2)\n",
226 | "circuit.x(0)\n",
227 | "circuit.cx(0, 1)\n",
228 | "\n",
229 | "decomposed_circuit = circuit.decompose()\n",
230 | "#print(decomposed_circuit)\n",
231 | "\n",
232 | "pulse_compiler_helper_fns.update_basis_gates_and_cmd_def(decomposed_circuit, backend, system, cmd_def)\n",
233 | "transpiled_circuit = q.transpile(decomposed_circuit, backend, optimization_level=1)\n",
234 | "#print(transpiled_circuit)\n",
235 | "\n",
236 | "schedule = q.schedule(transpiled_circuit, backend=backend, cmd_def=cmd_def)\n",
237 | "schedule |= measure << schedule.duration\n",
238 | "\n",
239 | "\n",
240 | "qobj = q.assemble(schedule, backend, \n",
241 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[2]/2/np.pi],\n",
242 | " shots=shots, sim_config = back_config)\n",
243 | "result = backend_sim.run(qobj).result()\n",
244 | "print(result.get_counts())"
245 | ]
246 | },
247 | {
248 | "cell_type": "markdown",
249 | "metadata": {},
250 | "source": [
251 | "------"
252 | ]
253 | },
254 | {
255 | "cell_type": "code",
256 | "execution_count": 13,
257 | "metadata": {},
258 | "outputs": [
259 | {
260 | "name": "stdout",
261 | "output_type": "stream",
262 | "text": [
263 | "{'00000000000000000011': 11, '00000000000000000001': 9989}\n"
264 | ]
265 | }
266 | ],
267 | "source": [
268 | "# now check |11>. CNOT should yield |10>.\n",
269 | "circuit = q.QuantumCircuit(2)\n",
270 | "circuit.x(0)\n",
271 | "circuit.x(1)\n",
272 | "circuit.cx(0, 1)\n",
273 | "\n",
274 | "decomposed_circuit = circuit.decompose()\n",
275 | "#print(decomposed_circuit)\n",
276 | "\n",
277 | "pulse_compiler_helper_fns.update_basis_gates_and_cmd_def(decomposed_circuit, backend, system, cmd_def)\n",
278 | "transpiled_circuit = q.transpile(decomposed_circuit, backend, optimization_level=1)\n",
279 | "#print(transpiled_circuit)\n",
280 | "\n",
281 | "schedule = q.schedule(transpiled_circuit, backend=backend, cmd_def=cmd_def)\n",
282 | "schedule |= measure << schedule.duration\n",
283 | "\n",
284 | "\n",
285 | "qobj = q.assemble(schedule, backend, \n",
286 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[2]/2/np.pi],\n",
287 | " shots=shots, sim_config = back_config)\n",
288 | "result = backend_sim.run(qobj).result()\n",
289 | "print(result.get_counts())"
290 | ]
291 | }
292 | ],
293 | "metadata": {
294 | "kernelspec": {
295 | "display_name": "Python 3",
296 | "language": "python",
297 | "name": "python3"
298 | },
299 | "language_info": {
300 | "codemirror_mode": {
301 | "name": "ipython",
302 | "version": 3
303 | },
304 | "file_extension": ".py",
305 | "mimetype": "text/x-python",
306 | "name": "python",
307 | "nbconvert_exporter": "python",
308 | "pygments_lexer": "ipython3",
309 | "version": "3.7.3"
310 | }
311 | },
312 | "nbformat": 4,
313 | "nbformat_minor": 2
314 | }
315 |
--------------------------------------------------------------------------------
/DRAG_Dephasings_SIMULATED.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Setting up pulse simulator:\n",
8 | "\n",
9 | "1) switch to openpulse-sim branch of qiskit-aer, also include this pull request https://github.com/Qiskit/qiskit-aer/pull/451 and increase `nsteps` in qiskit-aer/qiskit/providers/aer/openpulse/solver/options.py (I upped 100x to 50000)\n",
10 | "\n",
11 | "2) run `python setup.py build_ext --inplace`\n",
12 | "\n",
13 | "3) `python ./setup.py bdist_wheel`\n",
14 | "\n",
15 | "4) `cd dist` and `pip install` the wheel\n",
16 | "\n",
17 | "5) `rm -rf /Users/pranavgokhale/anaconda3/envs/QiskitDevenv/lib/python3.7/site-packages/qiskit` (replace with your username / site-packages location)\n",
18 | "\n",
19 | "6) `ln -s /Users/pranavgokhale/Developer/qiskit/qiskit-aer/qiskit/ /Users/pranavgokhale/anaconda3/envs/QiskitDevenv/lib/python3.7/site-packages/qiskit` (tailor paths to your setup)"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": null,
25 | "metadata": {},
26 | "outputs": [],
27 | "source": [
28 | "import numpy as np\n",
29 | "import time\n",
30 | "from collections import namedtuple\n",
31 | "import matplotlib.pyplot as plt\n",
32 | "%matplotlib inline"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {},
39 | "outputs": [],
40 | "source": [
41 | "import qiskit as q\n",
42 | "import qiskit.tools.jupyter\n",
43 | "from qiskit.pulse import pulse_lib as _ # only want to call pulse_lib as q.pulse.pulse_lib\n",
44 | "from qiskit.test.mock import FakeAlmaden\n",
45 | "from qiskit.ignis.verification.tomography.data import marginal_counts"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "import pulse_compiler_helper_fns"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "backend = FakeAlmaden()\n",
64 | "system = q.pulse.PulseChannelSpec.from_backend(backend)\n",
65 | "back_config = backend.configuration().to_dict()\n",
66 | "cmd_def = q.pulse.CmdDef.from_defaults(backend.defaults().cmd_def, backend.defaults().pulse_library)\n",
67 | "measure = cmd_def.get('measure', qubits=backend.configuration().meas_map[0])\n",
68 | "backend_sim = qiskit.Aer.get_backend('pulse_simulator')"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": null,
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "hamiltonian = {}\n",
78 | "hamiltonian['h_str'] = ['_SUM[i,0,1,wq{i}/2*(I{i}-Z{i})]', '_SUM[i,0,1,omegad{i}*X{i}||D{i}]',\n",
79 | " 'jq0q1*Sp0*Sm1', 'jq0q1*Sm0*Sp1', 'omegad1*X0||U0', 'omegad0*X1||U1']\n",
80 | "hamiltonian['qub'] = {'0': 2, '1': 2}\n",
81 | "hamiltonian['vars'] = {'wq0': 30.518812656662774, 'wq1': 31.238229295532093,\n",
82 | " 'omegad0': 0.1675, 'omegad1': 0.176,\n",
83 | " 'jq0q1': -0.0069}\n",
84 | "\n",
85 | "back_config['hamiltonian'] = hamiltonian\n",
86 | "back_config['noise'] = {}\n",
87 | "back_config['dt'] = 1.0\n",
88 | "back_config['ode_options'] = {}\n",
89 | "back_config['qubit_list'] = [0,1]"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "schedules = []\n",
99 | "thetas = np.linspace(0, np.pi, 41)\n",
100 | "for theta in thetas:\n",
101 | " for basis in ['X', 'Y', 'Z']:\n",
102 | " circuit = q.QuantumCircuit(1)\n",
103 | " circuit.rx(theta, 0)\n",
104 | " decomposed_circuit = circuit.decompose()\n",
105 | " pulse_compiler_helper_fns.update_basis_gates_and_cmd_def(decomposed_circuit, backend, system, cmd_def)\n",
106 | " transpiled_circuit = q.transpile(circuit, backend, optimization_level=1)\n",
107 | " schedule = q.schedule(transpiled_circuit, backend=backend, cmd_def=cmd_def)\n",
108 | " if basis == 'Y': # apply H Sdag\n",
109 | " schedule |= cmd_def.get('u1', qubits=[0], P0=-np.pi/2) << schedule.duration\n",
110 | " schedule |= cmd_def.get('u2', qubits=[0], P0=0, P1=np.pi) << schedule.duration\n",
111 | " elif basis == 'X': # apply H\n",
112 | " schedule |= cmd_def.get('u2', qubits=[0], P0=0, P1=np.pi) << schedule.duration\n",
113 | " schedule |= measure << schedule.duration\n",
114 | " schedules.append(schedule)"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "metadata": {},
120 | "source": [
121 | "We have to do this step twice to get the dressed frequencies for setting the LO's. Note here that we set `meas_level=1` and `meas_return=avg` which will return the average probability for the qubit to be in the |1> state."
122 | ]
123 | },
124 | {
125 | "cell_type": "code",
126 | "execution_count": null,
127 | "metadata": {},
128 | "outputs": [],
129 | "source": [
130 | "shots = 10000"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "qobj = q.assemble(schedules, backend, \n",
140 | " meas_level=1, meas_return='avg', \n",
141 | " memory_slots=2,\n",
142 | " shots=shots, sim_config = back_config)"
143 | ]
144 | },
145 | {
146 | "cell_type": "code",
147 | "execution_count": null,
148 | "metadata": {},
149 | "outputs": [],
150 | "source": [
151 | "evals, estates = backend_sim.get_dressed_energies(rabi_qobj)\n",
152 | "evals/2/np.pi"
153 | ]
154 | },
155 | {
156 | "cell_type": "code",
157 | "execution_count": null,
158 | "metadata": {},
159 | "outputs": [],
160 | "source": [
161 | "qobj = q.assemble(schedules, backend, \n",
162 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[3]/2/np.pi],\n",
163 | " shots=shots, sim_config = back_config)"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": null,
169 | "metadata": {},
170 | "outputs": [],
171 | "source": [
172 | "sim_result = backend_sim.run(qobj).result()"
173 | ]
174 | },
175 | {
176 | "cell_type": "code",
177 | "execution_count": null,
178 | "metadata": {},
179 | "outputs": [],
180 | "source": [
181 | "\n",
182 | "xs, ys, zs = [], [], []\n",
183 | "for i in range(len(thetas)):\n",
184 | " x_counts = marginal_counts(sim_result.get_counts(3 * i), meas_qubits=[0])\n",
185 | " y_counts = marginal_counts(sim_result.get_counts(3 * i + 1), meas_qubits=[0])\n",
186 | " z_counts = marginal_counts(sim_result.get_counts(3 * i + 2), meas_qubits=[0])\n",
187 | " \n",
188 | " x = (x_counts.get('0', 0) / shots - 0.5) * 2\n",
189 | " y = (y_counts.get('0', 0) / shots - 0.5) * 2\n",
190 | " z = (z_counts.get('0', 0) / shots - 0.5) * 2\n",
191 | " print(thetas[i], x, y, z)"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": null,
197 | "metadata": {},
198 | "outputs": [],
199 | "source": [
200 | "import qutip\n",
201 | "from qutip import *\n",
202 | "from colour import Color\n",
203 | "green = Color(\"green\")\n",
204 | "colors = list(green.range_to(Color(\"#CC6600\"),41))\n",
205 | "colors = [color.get_hex_l() for color in colors]"
206 | ]
207 | },
208 | {
209 | "cell_type": "code",
210 | "execution_count": null,
211 | "metadata": {},
212 | "outputs": [],
213 | "source": [
214 | "data = \"\"\"0.0 0.022199999999999998 0.010399999999999965 1.0\n",
215 | "0.07853981633974483 0.019200000000000106 -0.07740000000000002 0.9974000000000001\n",
216 | "0.15707963267948966 0.008799999999999919 -0.14080000000000004 0.9872000000000001\n",
217 | "0.23561944901923448 0.011400000000000077 -0.22519999999999996 0.9734\n",
218 | "0.3141592653589793 0.012399999999999967 -0.30279999999999996 0.9530000000000001\n",
219 | "0.39269908169872414 0.0038000000000000256 -0.388 0.921\n",
220 | "0.47123889803846897 0.0041999999999999815 -0.4386 0.8839999999999999\n",
221 | "0.5497787143782138 0.02740000000000009 -0.5004 0.8575999999999999\n",
222 | "0.6283185307179586 -0.009600000000000053 -0.5636 0.808\n",
223 | "0.7068583470577035 0.02079999999999993 -0.628 0.75\n",
224 | "0.7853981633974483 0.017800000000000038 -0.6996 0.704\n",
225 | "0.8639379797371931 0.014399999999999968 -0.7424 0.6424000000000001\n",
226 | "0.9424777960769379 0.008199999999999985 -0.8068 0.5952\n",
227 | "1.0210176124166828 0.005800000000000027 -0.8513999999999999 0.5307999999999999\n",
228 | "1.0995574287564276 0.0129999999999999 -0.8878 0.4618\n",
229 | "1.1780972450961724 -0.012599999999999945 -0.9154 0.3817999999999999\n",
230 | "1.2566370614359172 0.006999999999999895 -0.9484 0.3062\n",
231 | "1.335176877775662 0.0036000000000000476 -0.966 0.23960000000000004\n",
232 | "1.413716694115407 0.012399999999999967 -0.9862 0.1581999999999999\n",
233 | "1.4922565104551517 -0.0011999999999999789 -0.996 0.06679999999999997\n",
234 | "1.5707963267948966 0.006599999999999939 -1.0 0.0041999999999999815\n",
235 | "1.6493361431346414 -0.0033999999999999586 -0.9988 -0.09919999999999995\n",
236 | "1.7278759594743862 -0.0031999999999999806 -0.9898 -0.15059999999999996\n",
237 | "1.806415775814131 -0.0036000000000000476 -0.9748 -0.2378\n",
238 | "1.8849555921538759 -0.010399999999999965 -0.9538 -0.3032\n",
239 | "1.9634954084936207 -0.0232 -0.9299999999999999 -0.38739999999999997\n",
240 | "2.0420352248333655 -0.01959999999999995 -0.8992 -0.45099999999999996\n",
241 | "2.1205750411731104 -0.03620000000000001 -0.8674 -0.5182\n",
242 | "2.199114857512855 -0.007800000000000029 -0.8212 -0.5964\n",
243 | "2.2776546738526 -0.010399999999999965 -0.7678 -0.6432\n",
244 | "2.356194490192345 -0.01980000000000004 -0.7206 -0.7090000000000001\n",
245 | "2.4347343065320897 -0.015599999999999947 -0.6502 -0.7604\n",
246 | "2.5132741228718345 -0.01639999999999997 -0.5920000000000001 -0.8058\n",
247 | "2.5918139392115793 -0.019000000000000017 -0.5376000000000001 -0.8504\n",
248 | "2.670353755551324 -0.013399999999999967 -0.46919999999999995 -0.8948\n",
249 | "2.748893571891069 -0.030399999999999983 -0.392 -0.9178\n",
250 | "2.827433388230814 -0.01319999999999999 -0.3104 -0.9518\n",
251 | "2.9059732045705586 -0.0050000000000000044 -0.24 -0.9724\n",
252 | "2.9845130209103035 -0.025399999999999978 -0.17320000000000002 -0.9872\n",
253 | "3.0630528372500483 -0.01539999999999997 -0.0776 -0.997\n",
254 | "3.141592653589793 -0.015199999999999991 -0.046599999999999975 -1.0\"\"\".split()\n",
255 | "\n",
256 | "b = Bloch()\n",
257 | "b.vector_color=colors\n",
258 | "xs, zs = [], []\n",
259 | "while len(data) > 0:\n",
260 | " data.pop(0)\n",
261 | " x, y, z = float(data.pop(0)), float(data.pop(0)), float(data.pop(0))\n",
262 | " norm = np.sqrt(x**2 + y**2 + z**2)\n",
263 | " x, y, z = x / norm, y / norm, z / norm\n",
264 | " xs.append(x); zs.append(z)\n",
265 | " b.add_vectors([x, y, z])\n",
266 | "b.show()"
267 | ]
268 | },
269 | {
270 | "cell_type": "code",
271 | "execution_count": null,
272 | "metadata": {},
273 | "outputs": [],
274 | "source": [
275 | "b.save('Figures/drag_trajectory_bloch_sphere_SIMULATED.svg')"
276 | ]
277 | },
278 | {
279 | "cell_type": "code",
280 | "execution_count": null,
281 | "metadata": {},
282 | "outputs": [],
283 | "source": [
284 | "from scipy.optimize import curve_fit\n",
285 | "fit_func = lambda z, A, w: A * np.sin((-1-z) * w)\n",
286 | "\n",
287 | "fitparams, conv = curve_fit(fit_func, zs, xs, [0.1, np.pi])\n",
288 | "fit_xs = [fit_func(z, *fitparams) for z in zs]"
289 | ]
290 | },
291 | {
292 | "cell_type": "code",
293 | "execution_count": null,
294 | "metadata": {},
295 | "outputs": [],
296 | "source": [
297 | "fig, ax = plt.subplots(figsize=(3.5, 5.27))\n",
298 | "plt.gcf().subplots_adjust(left=0.23)\n",
299 | "plt.scatter(xs, zs)\n",
300 | "plt.axis([-0.3, 0.3, -1, 1])\n",
301 | "plt.plot(fit_xs, zs)\n",
302 | "plt.xlabel('X Component', fontsize=12)\n",
303 | "plt.ylabel('Z Component', fontsize=12)\n",
304 | "plt.title('X-Z Plane Projection', fontsize=14)\n",
305 | "plt.xticks([-0.2, 0, .2])\n",
306 | "plt.yticks([-1, -.5, 0, .5, 1])\n",
307 | "\n",
308 | "plt.plot([0, 0], [-1, 1], 'g--')\n",
309 | "\n",
310 | "circle1 = plt.Circle((0, 0), 1, fill=False, linewidth=2)\n",
311 | "plt.gcf().gca().add_artist(circle1)\n",
312 | "plt.savefig('Figures/drag_trajectory_2d_SIMULATED.svg')"
313 | ]
314 | },
315 | {
316 | "cell_type": "code",
317 | "execution_count": null,
318 | "metadata": {},
319 | "outputs": [],
320 | "source": [
321 | "fig, ax = plt.subplots(figsize=(5, 2.5))\n",
322 | "plt.gcf().subplots_adjust(left=0.23)\n",
323 | "plt.scatter(xs, zs)\n",
324 | "plt.axis([-0.1, 0.1, -0.5, 0.5])\n",
325 | "plt.plot(fit_xs, zs)\n",
326 | "plt.xlabel('X Component', fontsize=12)\n",
327 | "plt.ylabel('Z Component', fontsize=12)\n",
328 | "plt.title('X-Z Plane Projection', fontsize=14)\n",
329 | "\n",
330 | "plt.plot([0, 0], [-1, 1], 'g--')\n",
331 | "\n",
332 | "circle1 = plt.Circle((0, 0), 1, fill=False, linewidth=2)\n",
333 | "plt.gcf().gca().add_artist(circle1)\n",
334 | "plt.savefig('Figures/drag_trajectory_2d_SIMULATED_inset.svg')"
335 | ]
336 | },
337 | {
338 | "cell_type": "markdown",
339 | "metadata": {},
340 | "source": [
341 | "---\n",
342 | "### Simulate for non-DRAG (so just Gaussian with no imaginary component)\n",
343 | "Unfortunately, results are not useful, probably because we only have qubits (not qutrits)"
344 | ]
345 | },
346 | {
347 | "cell_type": "code",
348 | "execution_count": null,
349 | "metadata": {},
350 | "outputs": [],
351 | "source": [
352 | "qubit = 0\n",
353 | "# exp configuration\n",
354 | "exps = 41\n",
355 | "\n",
356 | "# Rabi pulse\n",
357 | "drive_amps = np.linspace(0, 1.0, exps)\n",
358 | "drive_samples = 32\n",
359 | "drive_sigma = 3.8\n",
360 | "\n",
361 | "# Create schedule\n",
362 | "schedules = []\n",
363 | "for ii, drive_amp in enumerate(drive_amps):\n",
364 | " # drive pulse\n",
365 | " rabi_pulse = q.pulse.pulse_lib.gaussian(duration=drive_samples, \n",
366 | " amp=drive_amp, \n",
367 | " sigma=drive_sigma, name='rabi_pulse_%d' % ii)\n",
368 | " \n",
369 | " for basis in ['X', 'Y', 'Z']:\n",
370 | " # add commands to schedule\n",
371 | " schedule = q.pulse.Schedule(name='rabi_exp_amp_%s' % drive_amp)\n",
372 | " schedule += rabi_pulse(system.qubits[0].drive)\n",
373 | " if basis == 'Y': # apply H Sdag\n",
374 | " schedule |= cmd_def.get('u1', qubits=[0], P0=-np.pi/2) << schedule.duration\n",
375 | " schedule |= cmd_def.get('u2', qubits=[0], P0=0, P1=np.pi) << schedule.duration\n",
376 | " elif basis == 'X': # apply H\n",
377 | " schedule |= cmd_def.get('u2', qubits=[0], P0=0, P1=np.pi) << schedule.duration\n",
378 | " schedule |= measure << schedule.duration\n",
379 | " schedules.append(schedule)"
380 | ]
381 | },
382 | {
383 | "cell_type": "code",
384 | "execution_count": null,
385 | "metadata": {},
386 | "outputs": [],
387 | "source": [
388 | "qobj = q.assemble(schedules, backend, \n",
389 | " qubit_lo_freq = [evals[1]/2/np.pi, evals[3]/2/np.pi],\n",
390 | " shots=shots, sim_config = back_config)"
391 | ]
392 | },
393 | {
394 | "cell_type": "code",
395 | "execution_count": null,
396 | "metadata": {},
397 | "outputs": [],
398 | "source": [
399 | "sim_result = backend_sim.run(qobj).result()"
400 | ]
401 | },
402 | {
403 | "cell_type": "code",
404 | "execution_count": null,
405 | "metadata": {},
406 | "outputs": [],
407 | "source": [
408 | "from qiskit.ignis.verification.tomography.data import marginal_counts\n",
409 | "\n",
410 | "xs, ys, zs = [], [], []\n",
411 | "for i in range(len(thetas)):\n",
412 | " x_counts = marginal_counts(sim_result.get_counts(3 * i), meas_qubits=[0])\n",
413 | " y_counts = marginal_counts(sim_result.get_counts(3 * i + 1), meas_qubits=[0])\n",
414 | " z_counts = marginal_counts(sim_result.get_counts(3 * i + 2), meas_qubits=[0])\n",
415 | " \n",
416 | " x = (x_counts.get('0', 0) / shots - 0.5) * 2\n",
417 | " y = (y_counts.get('0', 0) / shots - 0.5) * 2\n",
418 | " z = (z_counts.get('0', 0) / shots - 0.5) * 2\n",
419 | " print(thetas[i], x, y, z)"
420 | ]
421 | },
422 | {
423 | "cell_type": "code",
424 | "execution_count": null,
425 | "metadata": {},
426 | "outputs": [],
427 | "source": [
428 | "data = \"\"\"0.0 0.02299999999999991 0.005600000000000049 1.0\n",
429 | "0.07853981633974483 0.007600000000000051 -0.07620000000000005 0.996\n",
430 | "0.15707963267948966 0.012399999999999967 -0.16279999999999994 0.99\n",
431 | "0.23561944901923448 -0.0016000000000000458 -0.23219999999999996 0.9712000000000001\n",
432 | "0.3141592653589793 0.008599999999999941 -0.2834 0.9536\n",
433 | "0.39269908169872414 0.01639999999999997 -0.36760000000000004 0.9164000000000001\n",
434 | "0.47123889803846897 0.007400000000000073 -0.44179999999999997 0.8897999999999999\n",
435 | "0.5497787143782138 0.01200000000000001 -0.5267999999999999 0.8544\n",
436 | "0.6283185307179586 0.00019999999999997797 -0.5831999999999999 0.8118000000000001\n",
437 | "0.7068583470577035 -0.0013999999999999568 -0.6352 0.7474000000000001\n",
438 | "0.7853981633974483 0.006399999999999961 -0.7032 0.718\n",
439 | "0.8639379797371931 0.010199999999999987 -0.7605999999999999 0.6504000000000001\n",
440 | "0.9424777960769379 0.014999999999999902 -0.8029999999999999 0.5724\n",
441 | "1.0210176124166828 -0.01759999999999995 -0.8616 0.5022\n",
442 | "1.0995574287564276 -0.010600000000000054 -0.8968 0.4161999999999999\n",
443 | "1.1780972450961724 0.0242 -0.9226 0.3668\n",
444 | "1.2566370614359172 0.033199999999999896 -0.9516 0.2876000000000001\n",
445 | "1.335176877775662 -0.005800000000000027 -0.9772 0.20520000000000005\n",
446 | "1.413716694115407 -0.012199999999999989 -0.9894 0.1277999999999999\n",
447 | "1.4922565104551517 -0.016000000000000014 -0.998 0.06719999999999993\n",
448 | "1.5707963267948966 -0.007800000000000029 -1.0 -0.021399999999999975\n",
449 | "1.6493361431346414 -0.0038000000000000256 -0.996 -0.11639999999999995\n",
450 | "1.7278759594743862 -0.008199999999999985 -0.9866 -0.18799999999999994\n",
451 | "1.806415775814131 -0.0050000000000000044 -0.9708 -0.24619999999999997\n",
452 | "1.8849555921538759 -0.012199999999999989 -0.9448 -0.3458\n",
453 | "1.9634954084936207 -0.0043999999999999595 -0.923 -0.40900000000000003\n",
454 | "2.0420352248333655 -0.0016000000000000458 -0.8902 -0.477\n",
455 | "2.1205750411731104 -0.014800000000000035 -0.8394 -0.5409999999999999\n",
456 | "2.199114857512855 -0.014599999999999946 -0.7856 -0.6138\n",
457 | "2.2776546738526 -0.0048000000000000265 -0.7445999999999999 -0.6722\n",
458 | "2.356194490192345 -0.012199999999999989 -0.6910000000000001 -0.7376\n",
459 | "2.4347343065320897 -0.03059999999999996 -0.6317999999999999 -0.781\n",
460 | "2.5132741228718345 -0.019399999999999973 -0.5820000000000001 -0.8358\n",
461 | "2.5918139392115793 -0.00880000000000003 -0.5184 -0.8812\n",
462 | "2.670353755551324 -0.020000000000000018 -0.4164 -0.9132\n",
463 | "2.748893571891069 -0.021199999999999997 -0.35519999999999996 -0.9402\n",
464 | "2.827433388230814 -0.0043999999999999595 -0.28680000000000005 -0.9606\n",
465 | "2.9059732045705586 -0.02300000000000002 -0.2016 -0.9798\n",
466 | "2.9845130209103035 -0.012199999999999989 -0.11880000000000002 -0.9926\n",
467 | "3.0630528372500483 -0.0010000000000000009 -0.03380000000000005 -1.0\n",
468 | "3.141592653589793 -0.018399999999999972 0.026799999999999935 -0.9988\n",
469 | "\"\"\".split()\n",
470 | "\n",
471 | "b = Bloch()\n",
472 | "b.vector_color=colors\n",
473 | "xs, zs = [], []\n",
474 | "while len(data) > 0:\n",
475 | " data.pop(0)\n",
476 | " x, y, z = float(data.pop(0)), float(data.pop(0)), float(data.pop(0))\n",
477 | " norm = np.sqrt(x**2 + y**2 + z**2)\n",
478 | " x, y, z = x / norm, y / norm, z / norm\n",
479 | " xs.append(x); zs.append(z)\n",
480 | " b.add_vectors([x, y, z])\n",
481 | "b.show()"
482 | ]
483 | },
484 | {
485 | "cell_type": "code",
486 | "execution_count": null,
487 | "metadata": {},
488 | "outputs": [],
489 | "source": [
490 | "fig, ax = plt.subplots(figsize=(5.15, 5.27))\n",
491 | "plt.gcf().subplots_adjust(left=0.13)\n",
492 | "plt.scatter(xs, zs)\n",
493 | "plt.axis([-0.45, 0.45, -1, 1])\n",
494 | "#plt.plot(fit_xs, zs)\n",
495 | "plt.xlabel('X Component', fontsize=12)\n",
496 | "plt.ylabel('Z Component', fontsize=12)\n",
497 | "plt.title('X-Z Plane Projection', fontsize=14)\n",
498 | "plt.xticks([-0.4, -0.2, 0, .2, .4])\n",
499 | "plt.yticks([-1, -.5, 0, .5, 1])\n",
500 | "\n",
501 | "plt.plot([0, 0], [-1, 1], 'g--')\n",
502 | "\n",
503 | "circle1 = plt.Circle((0, 0), 1, fill=False, linewidth=2)\n",
504 | "plt.gcf().gca().add_artist(circle1)"
505 | ]
506 | },
507 | {
508 | "cell_type": "code",
509 | "execution_count": null,
510 | "metadata": {},
511 | "outputs": [],
512 | "source": []
513 | }
514 | ],
515 | "metadata": {
516 | "kernelspec": {
517 | "display_name": "Python 3",
518 | "language": "python",
519 | "name": "python3"
520 | },
521 | "language_info": {
522 | "codemirror_mode": {
523 | "name": "ipython",
524 | "version": 3
525 | },
526 | "file_extension": ".py",
527 | "mimetype": "text/x-python",
528 | "name": "python",
529 | "nbconvert_exporter": "python",
530 | "pygments_lexer": "ipython3",
531 | "version": "3.7.3"
532 | }
533 | },
534 | "nbformat": 4,
535 | "nbformat_minor": 2
536 | }
537 |
--------------------------------------------------------------------------------
/Figures/CR_X.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_X.png
--------------------------------------------------------------------------------
/Figures/CR_X_SIMULATED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_X_SIMULATED.png
--------------------------------------------------------------------------------
/Figures/CR_Y.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_Y.png
--------------------------------------------------------------------------------
/Figures/CR_Y_SIMULATED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_Y_SIMULATED.png
--------------------------------------------------------------------------------
/Figures/CR_Y_SIMULATED.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
940 |
--------------------------------------------------------------------------------
/Figures/CR_Z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_Z.png
--------------------------------------------------------------------------------
/Figures/CR_Z_SIMULATED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/CR_Z_SIMULATED.png
--------------------------------------------------------------------------------
/Figures/Figures.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/Figures.pptx
--------------------------------------------------------------------------------
/Figures/RB.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/RB.png
--------------------------------------------------------------------------------
/Figures/bloch_states.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/bloch_states.png
--------------------------------------------------------------------------------
/Figures/compilation_flow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/compilation_flow.png
--------------------------------------------------------------------------------
/Figures/direct_x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/direct_x.png
--------------------------------------------------------------------------------
/Figures/drag_trajectory_2d.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/drag_trajectory_2d.png
--------------------------------------------------------------------------------
/Figures/drag_trajectory_2d.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
793 |
--------------------------------------------------------------------------------
/Figures/drag_trajectory_2d_SIMULATED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/drag_trajectory_2d_SIMULATED.png
--------------------------------------------------------------------------------
/Figures/drag_trajectory_2d_SIMULATED.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
793 |
--------------------------------------------------------------------------------
/Figures/drag_trajectory_bloch_sphere.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/drag_trajectory_bloch_sphere.png
--------------------------------------------------------------------------------
/Figures/drag_trajectory_bloch_sphere_SIMULATED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/drag_trajectory_bloch_sphere_SIMULATED.png
--------------------------------------------------------------------------------
/Figures/error_reduction.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/error_reduction.png
--------------------------------------------------------------------------------
/Figures/inline_pulse_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/inline_pulse_image.png
--------------------------------------------------------------------------------
/Figures/open_cnot_histogram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/open_cnot_histogram.png
--------------------------------------------------------------------------------
/Figures/optimized_open_cx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/optimized_open_cx.png
--------------------------------------------------------------------------------
/Figures/rx_standard_vs_direct.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/rx_standard_vs_direct.png
--------------------------------------------------------------------------------
/Figures/rx_standard_vs_direct_residuals.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/rx_standard_vs_direct_residuals.png
--------------------------------------------------------------------------------
/Figures/standard_open_cx.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/standard_open_cx.png
--------------------------------------------------------------------------------
/Figures/standard_vs_direct_x_gate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/standard_vs_direct_x_gate.png
--------------------------------------------------------------------------------
/Figures/standard_x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/standard_x.png
--------------------------------------------------------------------------------
/Figures/target_x_experimental.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_x_experimental.png
--------------------------------------------------------------------------------
/Figures/target_x_simulated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_x_simulated.png
--------------------------------------------------------------------------------
/Figures/target_y_experimental.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_y_experimental.png
--------------------------------------------------------------------------------
/Figures/target_y_simulated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_y_simulated.png
--------------------------------------------------------------------------------
/Figures/target_z_experimental.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_z_experimental.png
--------------------------------------------------------------------------------
/Figures/target_z_simulated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/target_z_simulated.png
--------------------------------------------------------------------------------
/Figures/zz_fidelity.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/singular-value/optimizations_via_openpulse/8d7b927ab4cb3efd5fc9b26eb255cfb2dd85f871/Figures/zz_fidelity.png
--------------------------------------------------------------------------------
/Qutrit Rabi_MeasurementLevel2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 8,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import numpy as np\n",
10 | "import time\n",
11 | "import matplotlib.pyplot as plt\n",
12 | "%matplotlib inline"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": 9,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "import qiskit as q\n",
22 | "import qiskit.tools.jupyter\n",
23 | "from qiskit.pulse import pulse_lib as _ # only want to call pulse_lib as q.pulse.pulse_lib"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": 10,
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "name": "stderr",
33 | "output_type": "stream",
34 | "text": [
35 | "Credentials are already in use. The existing account in the session will be replaced.\n"
36 | ]
37 | },
38 | {
39 | "data": {
40 | "text/plain": [
41 | "[,\n",
42 | " ]"
43 | ]
44 | },
45 | "execution_count": 10,
46 | "metadata": {},
47 | "output_type": "execute_result"
48 | }
49 | ],
50 | "source": [
51 | "q.IBMQ.load_account() # Load account from disk\n",
52 | "q.IBMQ.providers() # List all available providers"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 11,
58 | "metadata": {},
59 | "outputs": [],
60 | "source": [
61 | "provider = q.IBMQ.get_provider(group='bes-qis')\n",
62 | "backend = provider.get_backend('ibmq_boeblingen')\n",
63 | "system = q.pulse.PulseChannelSpec.from_backend(backend)\n",
64 | "config = backend.configuration()\n",
65 | "defaults = backend.defaults()\n",
66 | "cmd_def = q.pulse.CmdDef.from_defaults(backend.defaults().cmd_def, backend.defaults().pulse_library)\n",
67 | "measure = cmd_def.get('measure', qubits=config.meas_map[0])"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 12,
73 | "metadata": {},
74 | "outputs": [
75 | {
76 | "data": {
77 | "application/vnd.jupyter.widget-view+json": {
78 | "model_id": "19d8376e89804a1282f9cc2e38d9455b",
79 | "version_major": 2,
80 | "version_minor": 0
81 | },
82 | "text/plain": [
83 | "Accordion(children=(VBox(layout=Layout(max_width='710px', min_width='710px')),), layout=Layout(max_height='500…"
84 | ]
85 | },
86 | "metadata": {},
87 | "output_type": "display_data"
88 | },
89 | {
90 | "data": {
91 | "application/javascript": [
92 | "$('div.job_widget')\n",
93 | " .detach()\n",
94 | " .appendTo($('#header'))\n",
95 | " .css({\n",
96 | " 'z-index': 999,\n",
97 | " 'position': 'fixed',\n",
98 | " 'box-shadow': '5px 5px 5px -3px black',\n",
99 | " 'opacity': 0.95,\n",
100 | " 'float': 'left,'\n",
101 | " })\n",
102 | " "
103 | ],
104 | "text/plain": [
105 | ""
106 | ]
107 | },
108 | "metadata": {},
109 | "output_type": "display_data"
110 | }
111 | ],
112 | "source": [
113 | "%qiskit_job_watcher"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": 13,
119 | "metadata": {
120 | "scrolled": true
121 | },
122 | "outputs": [
123 | {
124 | "data": {
125 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcAAAAEvCAYAAADSNxEkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAY6UlEQVR4nO3dfZBd9X3f8fdnd5EwCAHiQWAQoMSyG9ym9obgtB48GQM2njiW/7BrktSjdJzRdCZu0oe0wfXU7pB2hkw6STNTTxsV45DUDnGwG2s81BTjJyaJHcmGYrBLEMIWUsSjQDzJklb32z/u3c4iraTdvZd77t3zfs3c2Xse73eOdM/nnt/5nXNSVUiS1DYTTRcgSVITDEBJUisZgJKkVjIAJUmtZABKklrJAJQktdJU0wUsxTnnnluXXnJJ02VIkkbEvffe+3RVnbeYZcYyAC+95BK+/o17mi5DkjQiVp+x6oeLXcYmUElSKxmAkqRWMg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wDgFoPqUZBXwOeCfV9XzTdczypK8G3iyqr7ddC1jaAqYBv5rVb0ZeIkFNEe1Xe+c1Ua6PyBeC5ye5B83W9V4qu7lDSe9xGGcAnAPsG7O8MW9cVqAJKfQDb9PV9Xnm65nDLwVeE+SH9Btbn97kv/RbEljYzewu6pmWxlupxuIOrFrgEer6qmqOgx8HviHDdc0Tp5IciFA7++TJ1tgnAJwG7AhyfokK+ieHN7acE1jIUnono/5flX9btP1jIOq+khVXVxVl9H9v/aVqvLX+AJU1ePAY0ne0Bt1NfC9BksaF7uAn0lyWu87ezV2HlqMrcCm3vtNwBdOtsDY3Ay7qmaSfBi4k27vqFuq6sGGyxoXbwU+CHw3yX29cf+2qu5osCYtb/8M+HTvx+pO4J80XM/Iq6pvJbkd+A7dntv34l1h5pXkT4CfBc5Nshv4OHAT8NkkHwJ+CPyjk67HO8FIktponJpAJUkaGANQktRKBqAkqZUMQElSKxmAkqRWMgAlSa1kAEqSWskAlCS10v8Dn5FuEMytDJUAAAAASUVORK5CYII=\n",
126 | "text/plain": [
127 | ""
128 | ]
129 | },
130 | "execution_count": 13,
131 | "metadata": {},
132 | "output_type": "execute_result"
133 | }
134 | ],
135 | "source": [
136 | "cmd_def.get('x', qubits=[0]).instructions[0][1].command.draw(scaling=0.18)"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": 14,
142 | "metadata": {},
143 | "outputs": [
144 | {
145 | "data": {
146 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcAAAAEvCAYAAADSNxEkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAXWUlEQVR4nO3dbYylZ33f8e9vZr0G22Bsr7HX6zU2YUnjtCpsHZMWgVJssFEilhfQmqRoUxGtKsVt+pA2pqggOa0EShXaFzTNFkzcFGK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VfXOqrqwqi5m+L/22ary1/giVNUjwENJfr6bdAVwT48lTYoHgV9Oclr3mb0CDx5ail3A9m54O/DJk60wMRfDrqqZJNcCtzI8OuqGqrq757ImxauBtwPfTHJnN+0/VtUtPdakte1fAh/pfqzuB/55z/WselX11SQ3A19neOT2HXhVmHkl+TPgV4ANSQ4A7wHeC3w8yTuAB4B/ctLteCUYSVKLJqkLVJKksTEAJUlNMgAlSU0yACVJTTIAJUlNMgAlSU0yACVJTTIAJUlN+v//vdRSOdWczQAAAABJRU5ErkJggg==\n",
147 | "text/plain": [
148 | ""
149 | ]
150 | },
151 | "execution_count": 14,
152 | "metadata": {},
153 | "output_type": "execute_result"
154 | }
155 | ],
156 | "source": [
157 | "# Approximate X as a gaussian pulse:\n",
158 | "DURATION = 10\n",
159 | "AMP = 0.15\n",
160 | "SIGMA = 2.6\n",
161 | "q.pulse.pulse_lib.gaussian(duration=DURATION, amp=AMP, sigma=SIGMA).draw(scaling=0.18)"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "------------"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": 15,
174 | "metadata": {},
175 | "outputs": [],
176 | "source": [
177 | "MEASUREMENT_START_TIMESTEP = 30"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": 16,
183 | "metadata": {},
184 | "outputs": [
185 | {
186 | "name": "stdout",
187 | "output_type": "stream",
188 | "text": [
189 | "5daf349524a011001959eea3\n"
190 | ]
191 | }
192 | ],
193 | "source": [
194 | "# just measure\n",
195 | "schedule = q.pulse.Schedule()\n",
196 | "schedule |= measure << MEASUREMENT_START_TIMESTEP\n",
197 | "\n",
198 | "job = q.execute(schedule, backend=backend, shots=1000)\n",
199 | "print(job.job_id())"
200 | ]
201 | },
202 | {
203 | "cell_type": "code",
204 | "execution_count": 17,
205 | "metadata": {},
206 | "outputs": [
207 | {
208 | "name": "stdout",
209 | "output_type": "stream",
210 | "text": [
211 | "5daf349a140f700018632a0a\n"
212 | ]
213 | }
214 | ],
215 | "source": [
216 | "# X, then measure\n",
217 | "schedule = q.pulse.Schedule()\n",
218 | "schedule |= cmd_def.get('x', qubits=[0])\n",
219 | "schedule |= measure << MEASUREMENT_START_TIMESTEP\n",
220 | "\n",
221 | "job = q.execute(schedule, backend=backend, shots=1000)\n",
222 | "print(job.job_id())"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": 18,
228 | "metadata": {},
229 | "outputs": [
230 | {
231 | "name": "stdout",
232 | "output_type": "stream",
233 | "text": [
234 | "5daf34a0140f700018632a0c\n"
235 | ]
236 | }
237 | ],
238 | "source": [
239 | "# X, X, then measure\n",
240 | "schedule = q.pulse.Schedule()\n",
241 | "schedule |= cmd_def.get('x', qubits=[0])\n",
242 | "schedule |= cmd_def.get('x', qubits=[0]) << schedule.duration\n",
243 | "schedule |= measure << MEASUREMENT_START_TIMESTEP\n",
244 | "\n",
245 | "job = q.execute(schedule, backend=backend, shots=1000)\n",
246 | "print(job.job_id())"
247 | ]
248 | },
249 | {
250 | "cell_type": "code",
251 | "execution_count": 19,
252 | "metadata": {},
253 | "outputs": [
254 | {
255 | "name": "stdout",
256 | "output_type": "stream",
257 | "text": [
258 | "5daf3502c1592500190bdced\n"
259 | ]
260 | }
261 | ],
262 | "source": [
263 | "schedules = []\n",
264 | "\n",
265 | "for scaling_factor in [0.2, 0.4, 0.6, 0.8, 1.0]:\n",
266 | " # X, then pulse at 1-2 frequency, then X, then measure\n",
267 | " schedule = q.pulse.Schedule()\n",
268 | " schedule |= cmd_def.get('x', qubits=[0])\n",
269 | "\n",
270 | " freq = config.dt * 0.304 # anharmonicity is 304 MHz. In units of dt, we have .304/ns * config.dt/ns\n",
271 | " wave_samples = q.pulse.pulse_lib.cos(duration=DURATION, amp=1, freq=freq).samples - 1j * q.pulse.pulse_lib.sin(\n",
272 | " duration=DURATION, amp=1, freq=freq).samples\n",
273 | " # use amplitude of AMP / sqrt(2) for 1->2 transition\n",
274 | " gaussian_samples = q.pulse.pulse_lib.gaussian(\n",
275 | " duration=DURATION, amp=AMP * scaling_factor / np.sqrt(2), sigma=SIGMA).samples\n",
276 | " schedule |= q.pulse.SamplePulse(gaussian_samples * wave_samples)(system.qubits[0].drive) << schedule.duration\n",
277 | "\n",
278 | " schedule |= cmd_def.get('x', qubits=[0]) << schedule.duration\n",
279 | "\n",
280 | " schedule |= measure << MEASUREMENT_START_TIMESTEP\n",
281 | " \n",
282 | " schedules.append(schedule)\n",
283 | "\n",
284 | "job = q.execute(schedules, backend=backend, shots=1000)\n",
285 | "print(job.job_id())"
286 | ]
287 | },
288 | {
289 | "cell_type": "code",
290 | "execution_count": 20,
291 | "metadata": {},
292 | "outputs": [],
293 | "source": [
294 | "job_ids = ['5daf349524a011001959eea3', '5daf349a140f700018632a0a', '5daf34a0140f700018632a0c', '5daf3502c1592500190bdced']\n",
295 | "jobs = [provider.backends.retrieve_job(job_id) for job_id in job_ids]"
296 | ]
297 | },
298 | {
299 | "cell_type": "code",
300 | "execution_count": 21,
301 | "metadata": {},
302 | "outputs": [
303 | {
304 | "name": "stdout",
305 | "output_type": "stream",
306 | "text": [
307 | "frac_ones is 0.092\n"
308 | ]
309 | }
310 | ],
311 | "source": [
312 | "# just measure\n",
313 | "job = jobs[0]\n",
314 | "counts = job.result().get_counts()\n",
315 | "frac_ones = sum([value for (key,value) in counts.items() if key[-1] == '1']) / 1000\n",
316 | "print('frac_ones is %s' % frac_ones)"
317 | ]
318 | },
319 | {
320 | "cell_type": "code",
321 | "execution_count": 22,
322 | "metadata": {},
323 | "outputs": [
324 | {
325 | "name": "stdout",
326 | "output_type": "stream",
327 | "text": [
328 | "frac_ones is 0.863\n"
329 | ]
330 | }
331 | ],
332 | "source": [
333 | "# X, then measure\n",
334 | "job = jobs[1]\n",
335 | "counts = job.result().get_counts()\n",
336 | "frac_ones = sum([value for (key,value) in counts.items() if key[-1] == '1']) / 1000\n",
337 | "print('frac_ones is %s' % frac_ones)"
338 | ]
339 | },
340 | {
341 | "cell_type": "code",
342 | "execution_count": 23,
343 | "metadata": {},
344 | "outputs": [
345 | {
346 | "name": "stdout",
347 | "output_type": "stream",
348 | "text": [
349 | "frac_ones is 0.226\n"
350 | ]
351 | }
352 | ],
353 | "source": [
354 | "# X, X, then measure:\n",
355 | "job = jobs[2]\n",
356 | "counts = job.result().get_counts()\n",
357 | "frac_ones = sum([value for (key,value) in counts.items() if key[-1] == '1']) / 1000\n",
358 | "print('frac_ones is %s' % frac_ones)"
359 | ]
360 | },
361 | {
362 | "cell_type": "code",
363 | "execution_count": 24,
364 | "metadata": {},
365 | "outputs": [
366 | {
367 | "name": "stdout",
368 | "output_type": "stream",
369 | "text": [
370 | "frac_ones is 0.106\n",
371 | "frac_ones is 0.084\n",
372 | "frac_ones is 0.078\n",
373 | "frac_ones is 0.106\n",
374 | "frac_ones is 0.151\n"
375 | ]
376 | }
377 | ],
378 | "source": [
379 | "# X, then pulse at 1-2 frequency, then X, then measure:\n",
380 | "job = jobs[3]\n",
381 | "\n",
382 | "for i in range(5):\n",
383 | " counts = job.result().get_counts(i)\n",
384 | " frac_ones = sum([value for (key,value) in counts.items() if key[-1] == '1']) / 1000\n",
385 | " print('frac_ones is %s' % frac_ones)"
386 | ]
387 | },
388 | {
389 | "cell_type": "code",
390 | "execution_count": null,
391 | "metadata": {},
392 | "outputs": [],
393 | "source": []
394 | }
395 | ],
396 | "metadata": {
397 | "kernelspec": {
398 | "display_name": "Python 3",
399 | "language": "python",
400 | "name": "python3"
401 | },
402 | "language_info": {
403 | "codemirror_mode": {
404 | "name": "ipython",
405 | "version": 3
406 | },
407 | "file_extension": ".py",
408 | "mimetype": "text/x-python",
409 | "name": "python",
410 | "nbconvert_exporter": "python",
411 | "pygments_lexer": "ipython3",
412 | "version": "3.7.3"
413 | }
414 | },
415 | "nbformat": 4,
416 | "nbformat_minor": 2
417 | }
418 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | Note that most of our experiments were run in November 2019. The pulse library for qiskit (as well as the backend support) has changed since then.
2 | However, it should be not be too difficult to migrate to the new APIs, for example: `cmd_def` -> `InstructionScheduleMap`.
3 | The most recent batch of experiments on Armonk were run in January 2020, when the pulse API was closer to the current form.
4 |
5 |
6 | Our compiler structural modifications are in qiskit-terra/ while most of the "business logic" is in pulse_compiler_helper_fns.py.
7 |
8 | Our custom simulator is in qiskit-aer/
9 |
10 | The Experiments/ directory has iPython notebooks demonstrating our results; Some representative notebooks:
11 | - ZZ_Interaction_EXPERIMENT.ipynb has our ZZ-interaction fidelity measurements (Fig 10)
12 | - Almaden Qutrit... has our results for qutrit control (Fig 11)
13 | - Randomized_Benchmarking_Armonk.ipynb has our RB-style experiments (Fig 13)
14 | - various tomography notebooks are included
15 |
16 | Also, the Figures/ subdirectory has notebooks used to generate Figures 2 and 4
17 |
18 |
--------------------------------------------------------------------------------
/Scratchpads/Proof_of_ZZ_Identity.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.0' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 10706, 328]
14 | NotebookOptionsPosition[ 9652, 302]
15 | NotebookOutlinePosition[ 9989, 317]
16 | CellTagsIndexPosition[ 9946, 314]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell[BoxData[
22 | RowBox[{
23 | RowBox[{"M", "=",
24 | RowBox[{
25 | RowBox[{"(", "\[NoBreak]", GridBox[{
26 | {
27 | RowBox[{"Cos", "[",
28 | RowBox[{"t", "/", "4"}], "]"}],
29 | RowBox[{"\[ImaginaryI]", " ",
30 | RowBox[{"Sin", "[",
31 | RowBox[{"t", "/", "4"}], "]"}]}], "0", "0"},
32 | {
33 | RowBox[{"\[ImaginaryI]", " ",
34 | RowBox[{"Sin", "[",
35 | RowBox[{"t", "/", "4"}], "]"}]}],
36 | RowBox[{"Cos", "[",
37 | RowBox[{"t", "/", "4"}], "]"}], "0", "0"},
38 | {"0", "0",
39 | RowBox[{"Cos", "[",
40 | RowBox[{"t", "/", "4"}], "]"}],
41 | RowBox[{
42 | RowBox[{"-", "\[ImaginaryI]"}], " ",
43 | RowBox[{"Sin", "[",
44 | RowBox[{"t", "/", "4"}], "]"}]}]},
45 | {"0", "0",
46 | RowBox[{
47 | RowBox[{"-", "\[ImaginaryI]"}], " ",
48 | RowBox[{"Sin", "[",
49 | RowBox[{"t", "/", "4"}], "]"}]}],
50 | RowBox[{"Cos", "[",
51 | RowBox[{"t", "/", "4"}], "]"}]}
52 | }], "\[NoBreak]", ")"}], ".",
53 | RowBox[{"KroneckerProduct", "[",
54 | RowBox[{
55 | RowBox[{"(", "\[NoBreak]", GridBox[{
56 | {"0", "1"},
57 | {"1", "0"}
58 | }], "\[NoBreak]", ")"}], ",",
59 | RowBox[{"(", "\[NoBreak]", GridBox[{
60 | {"1", "0"},
61 | {"0", "1"}
62 | }], "\[NoBreak]", ")"}]}], "]"}], ".",
63 | RowBox[{"(", "\[NoBreak]", GridBox[{
64 | {
65 | RowBox[{"Cos", "[",
66 | RowBox[{"t", "/", "4"}], "]"}],
67 | RowBox[{
68 | RowBox[{"-", "\[ImaginaryI]"}], " ",
69 | RowBox[{"Sin", "[",
70 | RowBox[{"t", "/", "4"}], "]"}]}], "0", "0"},
71 | {
72 | RowBox[{
73 | RowBox[{"-", "\[ImaginaryI]"}], " ",
74 | RowBox[{"Sin", "[",
75 | RowBox[{"t", "/", "4"}], "]"}]}],
76 | RowBox[{"Cos", "[",
77 | RowBox[{"t", "/", "4"}], "]"}], "0", "0"},
78 | {"0", "0",
79 | RowBox[{"Cos", "[",
80 | RowBox[{"t", "/", "4"}], "]"}],
81 | RowBox[{"\[ImaginaryI]", " ",
82 | RowBox[{"Sin", "[",
83 | RowBox[{"t", "/", "4"}], "]"}]}]},
84 | {"0", "0",
85 | RowBox[{"\[ImaginaryI]", " ",
86 | RowBox[{"Sin", "[",
87 | RowBox[{"t", "/", "4"}], "]"}]}],
88 | RowBox[{"Cos", "[",
89 | RowBox[{"t", "/", "4"}], "]"}]}
90 | }], "\[NoBreak]", ")"}]}]}], ";"}]], "Input",
91 | CellChangeTimes->{{3.783525272666464*^9, 3.78352546623217*^9}, {
92 | 3.783525497253254*^9, 3.7835255129555807`*^9}, {3.783526353552326*^9,
93 | 3.783526387143965*^9}},
94 | CellLabel->"In[19]:=",ExpressionUUID->"76d061f3-384e-4e49-9ea3-2f33760aa195"],
95 |
96 | Cell[CellGroupData[{
97 |
98 | Cell[BoxData[
99 | RowBox[{
100 | RowBox[{"M", " ", "=", " ",
101 | RowBox[{"Simplify", "[", "M", "]"}]}], ";", " ",
102 | RowBox[{"M", "//", "MatrixForm"}]}]], "Input",
103 | CellChangeTimes->{{3.783525514605503*^9, 3.7835255185916862`*^9}, {
104 | 3.783525665128105*^9, 3.7835256752642937`*^9}},
105 | CellLabel->"In[20]:=",ExpressionUUID->"72177ab0-5ac2-47ac-b01a-da838f975626"],
106 |
107 | Cell[BoxData[
108 | TagBox[
109 | RowBox[{"(", "\[NoBreak]", GridBox[{
110 | {"0", "0",
111 | RowBox[{"Cos", "[",
112 | FractionBox["t", "2"], "]"}],
113 | RowBox[{"\[ImaginaryI]", " ",
114 | RowBox[{"Sin", "[",
115 | FractionBox["t", "2"], "]"}]}]},
116 | {"0", "0",
117 | RowBox[{"\[ImaginaryI]", " ",
118 | RowBox[{"Sin", "[",
119 | FractionBox["t", "2"], "]"}]}],
120 | RowBox[{"Cos", "[",
121 | FractionBox["t", "2"], "]"}]},
122 | {
123 | RowBox[{"Cos", "[",
124 | FractionBox["t", "2"], "]"}],
125 | RowBox[{
126 | RowBox[{"-", "\[ImaginaryI]"}], " ",
127 | RowBox[{"Sin", "[",
128 | FractionBox["t", "2"], "]"}]}], "0", "0"},
129 | {
130 | RowBox[{
131 | RowBox[{"-", "\[ImaginaryI]"}], " ",
132 | RowBox[{"Sin", "[",
133 | FractionBox["t", "2"], "]"}]}],
134 | RowBox[{"Cos", "[",
135 | FractionBox["t", "2"], "]"}], "0", "0"}
136 | },
137 | GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
138 | GridBoxSpacings->{"Columns" -> {
139 | Offset[0.27999999999999997`], {
140 | Offset[0.7]},
141 | Offset[0.27999999999999997`]}, "Rows" -> {
142 | Offset[0.2], {
143 | Offset[0.4]},
144 | Offset[0.2]}}], "\[NoBreak]", ")"}],
145 | Function[BoxForm`e$,
146 | MatrixForm[BoxForm`e$]]]], "Output",
147 | CellChangeTimes->{
148 | 3.783525519586503*^9, {3.783525667192299*^9, 3.783525676127244*^9},
149 | 3.7835258927247458`*^9, 3.7835263970732822`*^9},
150 | CellLabel->
151 | "Out[20]//MatrixForm=",ExpressionUUID->"bfc82aa6-b33d-4648-8958-\
152 | 4506f08abb55"]
153 | }, Open ]],
154 |
155 | Cell[BoxData[
156 | RowBox[{
157 | RowBox[{"H", " ", "=",
158 | RowBox[{
159 | RowBox[{"(", "\[NoBreak]", GridBox[{
160 | {"1", "1"},
161 | {"1",
162 | RowBox[{"-", "1"}]}
163 | }], "\[NoBreak]", ")"}], "/",
164 | RowBox[{"Sqrt", "[", "2", "]"}]}]}], ";"}]], "Input",
165 | CellChangeTimes->{{3.783525556294353*^9, 3.783525616824547*^9}},
166 | CellLabel->"In[21]:=",ExpressionUUID->"9efed217-5df7-4034-97e7-4742da7d22ea"],
167 |
168 | Cell[CellGroupData[{
169 |
170 | Cell[BoxData[{
171 | RowBox[{
172 | RowBox[{"U", " ", "=", " ",
173 | RowBox[{"Simplify", "[",
174 | RowBox[{
175 | RowBox[{"KroneckerProduct", "[",
176 | RowBox[{
177 | RowBox[{"IdentityMatrix", "[", "2", "]"}], ",", " ", "H"}], "]"}], ".",
178 | "M", ".",
179 | RowBox[{"KroneckerProduct", "[",
180 | RowBox[{
181 | RowBox[{"IdentityMatrix", "[", "2", "]"}], ",", "H"}], "]"}]}],
182 | "]"}]}], " ", ";"}], "\[IndentingNewLine]",
183 | RowBox[{"U", "//", " ", "MatrixForm"}]}], "Input",
184 | CellChangeTimes->{{3.783525619021874*^9, 3.783525654662245*^9}, {
185 | 3.783525903350792*^9, 3.783525907529656*^9}, {3.7835265545485353`*^9,
186 | 3.783526560459776*^9}},
187 | CellLabel->"In[23]:=",ExpressionUUID->"ce7632d8-7670-4fff-bdcf-416ed22a11ed"],
188 |
189 | Cell[BoxData[
190 | TagBox[
191 | RowBox[{"(", "\[NoBreak]", GridBox[{
192 | {"0", "0",
193 | RowBox[{
194 | RowBox[{"Cos", "[",
195 | FractionBox["t", "2"], "]"}], "+",
196 | RowBox[{"\[ImaginaryI]", " ",
197 | RowBox[{"Sin", "[",
198 | FractionBox["t", "2"], "]"}]}]}], "0"},
199 | {"0", "0", "0",
200 | RowBox[{
201 | RowBox[{"Cos", "[",
202 | FractionBox["t", "2"], "]"}], "-",
203 | RowBox[{"\[ImaginaryI]", " ",
204 | RowBox[{"Sin", "[",
205 | FractionBox["t", "2"], "]"}]}]}]},
206 | {
207 | RowBox[{
208 | RowBox[{"Cos", "[",
209 | FractionBox["t", "2"], "]"}], "-",
210 | RowBox[{"\[ImaginaryI]", " ",
211 | RowBox[{"Sin", "[",
212 | FractionBox["t", "2"], "]"}]}]}], "0", "0", "0"},
213 | {"0",
214 | RowBox[{
215 | RowBox[{"Cos", "[",
216 | FractionBox["t", "2"], "]"}], "+",
217 | RowBox[{"\[ImaginaryI]", " ",
218 | RowBox[{"Sin", "[",
219 | FractionBox["t", "2"], "]"}]}]}], "0", "0"}
220 | },
221 | GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
222 | GridBoxSpacings->{"Columns" -> {
223 | Offset[0.27999999999999997`], {
224 | Offset[0.7]},
225 | Offset[0.27999999999999997`]}, "Rows" -> {
226 | Offset[0.2], {
227 | Offset[0.4]},
228 | Offset[0.2]}}], "\[NoBreak]", ")"}],
229 | Function[BoxForm`e$,
230 | MatrixForm[BoxForm`e$]]]], "Output",
231 | CellChangeTimes->{3.783526402732398*^9, 3.783526561149186*^9},
232 | CellLabel->
233 | "Out[24]//MatrixForm=",ExpressionUUID->"314fc87d-9c9b-4d6a-a368-\
234 | e257c41c6490"]
235 | }, Open ]],
236 |
237 | Cell[CellGroupData[{
238 |
239 | Cell[BoxData[
240 | RowBox[{
241 | RowBox[{"U", ".",
242 | RowBox[{"KroneckerProduct", "[",
243 | RowBox[{
244 | RowBox[{"(", "\[NoBreak]", GridBox[{
245 | {"0", "1"},
246 | {"1", "0"}
247 | }], "\[NoBreak]", ")"}], ",",
248 | RowBox[{"(", "\[NoBreak]", GridBox[{
249 | {"1", "0"},
250 | {"0", "1"}
251 | }], "\[NoBreak]", ")"}]}], "]"}]}], "//", "MatrixForm"}]], "Input",
252 | CellChangeTimes->{{3.7835265641078463`*^9, 3.783526594004549*^9}},
253 | CellLabel->"In[28]:=",ExpressionUUID->"1d518a70-7952-4c59-9391-c545e10e479e"],
254 |
255 | Cell[BoxData[
256 | TagBox[
257 | RowBox[{"(", "\[NoBreak]", GridBox[{
258 | {
259 | RowBox[{
260 | RowBox[{"Cos", "[",
261 | FractionBox["t", "2"], "]"}], "+",
262 | RowBox[{"\[ImaginaryI]", " ",
263 | RowBox[{"Sin", "[",
264 | FractionBox["t", "2"], "]"}]}]}], "0", "0", "0"},
265 | {"0",
266 | RowBox[{
267 | RowBox[{"Cos", "[",
268 | FractionBox["t", "2"], "]"}], "-",
269 | RowBox[{"\[ImaginaryI]", " ",
270 | RowBox[{"Sin", "[",
271 | FractionBox["t", "2"], "]"}]}]}], "0", "0"},
272 | {"0", "0",
273 | RowBox[{
274 | RowBox[{"Cos", "[",
275 | FractionBox["t", "2"], "]"}], "-",
276 | RowBox[{"\[ImaginaryI]", " ",
277 | RowBox[{"Sin", "[",
278 | FractionBox["t", "2"], "]"}]}]}], "0"},
279 | {"0", "0", "0",
280 | RowBox[{
281 | RowBox[{"Cos", "[",
282 | FractionBox["t", "2"], "]"}], "+",
283 | RowBox[{"\[ImaginaryI]", " ",
284 | RowBox[{"Sin", "[",
285 | FractionBox["t", "2"], "]"}]}]}]}
286 | },
287 | GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
288 | GridBoxSpacings->{"Columns" -> {
289 | Offset[0.27999999999999997`], {
290 | Offset[0.7]},
291 | Offset[0.27999999999999997`]}, "Rows" -> {
292 | Offset[0.2], {
293 | Offset[0.4]},
294 | Offset[0.2]}}], "\[NoBreak]", ")"}],
295 | Function[BoxForm`e$,
296 | MatrixForm[BoxForm`e$]]]], "Output",
297 | CellChangeTimes->{{3.7835265855696783`*^9, 3.7835266011857233`*^9}},
298 | CellLabel->
299 | "Out[28]//MatrixForm=",ExpressionUUID->"9216a578-3f19-405f-a76e-\
300 | 28e5eaca2bc3"]
301 | }, Open ]]
302 | },
303 | WindowSize->{1023, 755},
304 | WindowMargins->{{Automatic, 0}, {35, Automatic}},
305 | FrontEndVersion->"12.0 for Mac OS X x86 (64-bit) (April 8, 2019)",
306 | StyleDefinitions->"Default.nb"
307 | ]
308 | (* End of Notebook Content *)
309 |
310 | (* Internal cache information *)
311 | (*CellTagsOutline
312 | CellTagsIndex->{}
313 | *)
314 | (*CellTagsIndex
315 | CellTagsIndex->{}
316 | *)
317 | (*NotebookFileOutline
318 | Notebook[{
319 | Cell[558, 20, 2508, 73, 167, "Input",ExpressionUUID->"76d061f3-384e-4e49-9ea3-2f33760aa195"],
320 | Cell[CellGroupData[{
321 | Cell[3091, 97, 354, 7, 30, "Input",ExpressionUUID->"72177ab0-5ac2-47ac-b01a-da838f975626"],
322 | Cell[3448, 106, 1485, 45, 126, "Output",ExpressionUUID->"bfc82aa6-b33d-4648-8958-4506f08abb55"]
323 | }, Open ]],
324 | Cell[4948, 154, 403, 11, 45, "Input",ExpressionUUID->"9efed217-5df7-4034-97e7-4742da7d22ea"],
325 | Cell[CellGroupData[{
326 | Cell[5376, 169, 719, 17, 52, "Input",ExpressionUUID->"ce7632d8-7670-4fff-bdcf-416ed22a11ed"],
327 | Cell[6098, 188, 1488, 45, 126, "Output",ExpressionUUID->"314fc87d-9c9b-4d6a-a368-e257c41c6490"]
328 | }, Open ]],
329 | Cell[CellGroupData[{
330 | Cell[7623, 238, 516, 14, 45, "Input",ExpressionUUID->"1d518a70-7952-4c59-9391-c545e10e479e"],
331 | Cell[8142, 254, 1494, 45, 126, "Output",ExpressionUUID->"9216a578-3f19-405f-a76e-28e5eaca2bc3"]
332 | }, Open ]]
333 | }
334 | ]
335 | *)
336 |
337 | (* End of internal cache information *)
338 |
339 |
--------------------------------------------------------------------------------
/TwoQubitDecompositionsIntoNativeGates.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 51,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import numpy as np\n",
10 | "from scipy.optimize import minimize, NonlinearConstraint\n",
11 | "from scipy.linalg import fractional_matrix_power, expm\n",
12 | "from qiskit.quantum_info.synthesis.two_qubit_decompose import TwoQubitBasisDecomposer\n",
13 | "import qiskit as q\n",
14 | "\n",
15 | "CNOT_UNITARY = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])\n",
16 | "ISWAP_UNITARY = np.array([[1, 0, 0, 0], [0, 0, -1j, 0], [0, -1j, 0, 0], [0, 0, 0, 1]])\n",
17 | "CR90_UNITARY = np.array([[1, -1j, 0, 0], [-1j, 1, 0, 0], [0, 0, 1, 1j], [0, 0, 1j, 1]]) / np.sqrt(2)"
18 | ]
19 | },
20 | {
21 | "cell_type": "markdown",
22 | "metadata": {},
23 | "source": [
24 | "---\n",
25 | "## Define Native Two-Qubit Gates"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 58,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "class NativeTwoQubitGate(object):\n",
35 | " num_params = -1\n",
36 | "\n",
37 | " def get_unitary(self, params=[]):\n",
38 | " assert len(params) == self.num_params\n",
39 | " assert self.num_params != -1, 'Subclass should set num_params'\n",
40 | " assert self.num_params in [0, 1], 'Currently doesn\\'t handle multi-parameter native gates'\n",
41 | "\n",
42 | " return self._get_unitary(params)\n",
43 | " \n",
44 | " def _get_unitary(self, params=[]):\n",
45 | " raise NotImplemented('Subclass should implement')\n",
46 | " \n",
47 | " def __str__(self):\n",
48 | " return self.__class__.__name__\n",
49 | "\n",
50 | " \n",
51 | "class NativeCNOT(NativeTwoQubitGate):\n",
52 | " num_params = 0\n",
53 | " \n",
54 | " def _get_unitary(self, params=[]):\n",
55 | " return CNOT_UNITARY\n",
56 | "\n",
57 | "\n",
58 | "class NativeiSWAP(NativeTwoQubitGate):\n",
59 | " num_params = 0\n",
60 | " \n",
61 | " def _get_unitary(self, params=[]):\n",
62 | " return ISWAP_UNITARY\n",
63 | " \n",
64 | "\n",
65 | "class NativeRootiSWAP(NativeTwoQubitGate):\n",
66 | " num_params = 0\n",
67 | " \n",
68 | " def _get_unitary(self, params=[]):\n",
69 | " return fractional_matrix_power(ISWAP_UNITARY, 0.5)\n",
70 | "\n",
71 | "\n",
72 | "\n",
73 | "class NativeCR(NativeTwoQubitGate):\n",
74 | " num_params = 1\n",
75 | " \n",
76 | " def _get_unitary(self, params=[]):\n",
77 | " theta = params[0]\n",
78 | " return np.array([\n",
79 | " [np.cos(theta/2), -1j * np.sin(theta/2), 0, 0],\n",
80 | " [-1j * np.sin(theta/2), np.cos(theta/2), 0, 0],\n",
81 | " [0, 0, np.cos(theta/2), 1j * np.sin(theta/2)],\n",
82 | " [0, 0, 1j * np.sin(theta/2), np.cos(theta/2)]])\n",
83 | "\n",
84 | "\n",
85 | "class NativeCZ(NativeTwoQubitGate):\n",
86 | " num_params = 0\n",
87 | " \n",
88 | " def _get_unitary(self, params=[]):\n",
89 | " return np.diag([1,1,1,-1])\n",
90 | " \n",
91 | " \n",
92 | "class NativeCR90(NativeTwoQubitGate):\n",
93 | " num_params = 0\n",
94 | " \n",
95 | " def _get_unitary(self, params=[]):\n",
96 | " return CR90_UNITARY\n",
97 | "\n",
98 | "\n",
99 | "class NativeParametrizediSWAP(NativeTwoQubitGate):\n",
100 | " num_params = 1\n",
101 | " \n",
102 | " def _get_unitary(self, params=[]):\n",
103 | " theta = params[0]\n",
104 | " return np.array([\n",
105 | " [1, 0, 0, 0],\n",
106 | " [0, np.cos(theta), -1j*np.sin(theta), 0],\n",
107 | " [0, -1j*np.sin(theta), np.cos(theta), 0],\n",
108 | " [0, 0, 0, 1]])\n",
109 | " \n",
110 | " \n",
111 | "class NativeSWAPAlpha(NativeTwoQubitGate):\n",
112 | " num_params = 1\n",
113 | " \n",
114 | " def _get_unitary(self, params=[]):\n",
115 | " alpha = params[0]\n",
116 | " return np.array([\n",
117 | " [1, 0, 0, 0],\n",
118 | " [0, (1 + np.exp(1j*np.pi*alpha))/2, (1 - np.exp(1j*np.pi*alpha))/2, 0],\n",
119 | " [0, (1 - np.exp(1j*np.pi*alpha))/2, (1 + np.exp(1j*np.pi*alpha))/2, 0],\n",
120 | " [0, 0, 0, 1]\n",
121 | " ])\n",
122 | "\n",
123 | " \n",
124 | "class NativeBSWAP(NativeTwoQubitGate):\n",
125 | " num_params = 0\n",
126 | " \n",
127 | " def _get_unitary(self, params=[]):\n",
128 | " return np.array([\n",
129 | " [np.cos(np.pi/8), 0, 0, 1j * np.sin(np.pi/8)],\n",
130 | " [0, np.cos(3*np.pi/8), 1j * np.sin(3*np.pi/8), 0],\n",
131 | " [0, 1j * np.sin(3*np.pi/8), np.cos(3*np.pi/8), 0],\n",
132 | " [1j * np.sin(np.pi/8), 0, 0, np.cos(np.pi/8)]\n",
133 | " ])\n",
134 | "\n",
135 | "\n",
136 | "class NativeMAP(NativeTwoQubitGate):\n",
137 | " num_params = 0\n",
138 | "\n",
139 | " def _get_unitary(self, params=[]):\n",
140 | " return expm(-1j * np.pi/4 * np.diag([1, -1, -1, 1]))\n",
141 | "\n",
142 | " \n",
143 | "class NativeRIP(NativeTwoQubitGate):\n",
144 | " pass\n",
145 | "\n",
146 | "\n",
147 | "class NativeMS(NativeTwoQubitGate):\n",
148 | " num_params = 1\n",
149 | " \n",
150 | " def _get_unitary(self, params=[]):\n",
151 | " theta = params[0]\n",
152 | " return np.array([\n",
153 | " [np.cos(np.pi*theta/2), 0, 0, -1j * np.sin(np.pi*theta/2)],\n",
154 | " [0, np.cos(np.pi*theta/2), -1j*np.sin(np.pi*theta/2), 0],\n",
155 | " [0, -1j*np.sin(np.pi*theta/2), np.cos(np.pi*theta/2), 0],\n",
156 | " [-1j*np.sin(np.pi*theta/2), 0, 0, np.cos(np.pi*theta/2)]\n",
157 | " ])"
158 | ]
159 | },
160 | {
161 | "cell_type": "markdown",
162 | "metadata": {},
163 | "source": [
164 | "## Define Target Two-Qubit Operations"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": 79,
170 | "metadata": {},
171 | "outputs": [],
172 | "source": [
173 | "class TargetTwoQubitOperation(object):\n",
174 | " def get_unitaries(self, params=None):\n",
175 | " raise NotImplemented('Subclass should implement')\n",
176 | " \n",
177 | " def __str__(self):\n",
178 | " return self.__class__.__name__\n",
179 | "\n",
180 | "\n",
181 | "class TargetCNOT(TargetTwoQubitOperation):\n",
182 | " def get_unitaries(self):\n",
183 | " return [CNOT_UNITARY]\n",
184 | " \n",
185 | "\n",
186 | "class TargetSWAP(TargetTwoQubitOperation):\n",
187 | " def get_unitaries(self):\n",
188 | " return [np.array([[1, 0, 0, 0],\n",
189 | " [0, 0, 1, 0],\n",
190 | " [0, 1, 0 ,0],\n",
191 | " [0, 0, 0, 1]])]\n",
192 | "\n",
193 | " \n",
194 | "class TargetZZInteraction(TargetTwoQubitOperation):\n",
195 | " def get_unitaries(self, params=None):\n",
196 | " if params is None:\n",
197 | " params = np.random.random(10) * 2 * np.pi\n",
198 | " return [np.diag([1, np.exp(1j * param), np.exp(1j * param), 1]) for param in params]\n",
199 | " \n",
200 | " \n",
201 | "class TargetZZSWAP(TargetTwoQubitOperation):\n",
202 | " def get_unitaries(self, params=None):\n",
203 | " if params is None:\n",
204 | " params = np.random.random(10) * 2 * np.pi\n",
205 | " unitaries = []\n",
206 | " for param in params:\n",
207 | " unitaries.append(np.array([[0, 0, 0, 1],\n",
208 | " [0, np.exp(1j*param), 0, 0],\n",
209 | " [0, 0, np.exp(1j*param), 0],\n",
210 | " [1, 0, 0, 0]]))\n",
211 | " return unitaries\n",
212 | " \n",
213 | "\n",
214 | "class TargetFermionicSimulation(TargetTwoQubitOperation):\n",
215 | " def get_unitaries(self, params=None):\n",
216 | " params = [np.random.random(2) * 2 * np.pi for _ in range(20)]\n",
217 | " unitaries = []\n",
218 | " for T, V in params:\n",
219 | " unitaries.append(np.array([[1, 0, 0, 0],\n",
220 | " [0, -1j*np.sin(T), np.cos(T), 0],\n",
221 | " [0, np.cos(T), -1j*np.sin(T), 0],\n",
222 | " [0, 0, 0, -np.exp(-1j*V)]]))\n",
223 | " return unitaries\n",
224 | " \n",
225 | " \n",
226 | "class TargetFermionicFourierTransform(TargetTwoQubitOperation):\n",
227 | " def get_unitaries(self):\n",
228 | " return [np.array([\n",
229 | " [1, 0, 0, 0],\n",
230 | " [0, 1/np.sqrt(2), 1/np.sqrt(2), 0],\n",
231 | " [0, 1/np.sqrt(2), -1/np.sqrt(2), 0],\n",
232 | " [0, 0, 0, -1]\n",
233 | " ])]\n",
234 | " \n",
235 | "\n",
236 | "class TargetBogoliubovTransform(TargetTwoQubitOperation):\n",
237 | " def get_unitaries(self, params=None):\n",
238 | " if params is None:\n",
239 | " params = np.random.random(10) * 2 * np.pi\n",
240 | "\n",
241 | " def _get_unitary(expo): # adapted from Cirq\n",
242 | " # --X--S--|iSWAP^expo|--S^1.5--X--\n",
243 | " # --------|iSWAP^expo|------------\n",
244 | " U = np.kron(np.array([[0, 1], [1, 0]]), np.eye(2))\n",
245 | " U = np.kron(fractional_matrix_power(np.diag([1, -1]), 1.5), np.eye(2)) @ U\n",
246 | " U = fractional_matrix_power(ISWAP_UNITARY, expo) @ U\n",
247 | " U = np.kron(np.array(np.diag([1, -1])), np.eye(2)) @ U\n",
248 | " U = np.kron(np.array([[0, 1], [1, 0]]), np.eye(2)) @ U\n",
249 | " return U\n",
250 | "\n",
251 | " return [_get_unitary(param) for param in params]"
252 | ]
253 | },
254 | {
255 | "cell_type": "markdown",
256 | "metadata": {},
257 | "source": [
258 | "## Discrete Native Gates:"
259 | ]
260 | },
261 | {
262 | "cell_type": "code",
263 | "execution_count": 80,
264 | "metadata": {},
265 | "outputs": [],
266 | "source": [
267 | "native_two_qubit_gates = [NativeCNOT(), NativeCR90(), NativeCZ(), NativeiSWAP(), NativeBSWAP(), NativeMAP(), NativeRootiSWAP()]\n",
268 | "target_two_qubit_operations = [TargetCNOT(), TargetSWAP(),\n",
269 | " TargetZZInteraction(), TargetZZSWAP(),\n",
270 | " TargetFermionicSimulation(),\n",
271 | " TargetFermionicFourierTransform(), TargetBogoliubovTransform()]"
272 | ]
273 | },
274 | {
275 | "cell_type": "code",
276 | "execution_count": 83,
277 | "metadata": {},
278 | "outputs": [
279 | {
280 | "name": "stdout",
281 | "output_type": "stream",
282 | "text": [
283 | "With target operation of TargetCNOT, costs are:\n",
284 | "1 via NativeCNOT\n",
285 | "1 via NativeCR90\n",
286 | "1 via NativeCZ\n",
287 | "2 via NativeiSWAP\n",
288 | "2 via NativeBSWAP\n",
289 | "1 via NativeMAP\n",
290 | "1.0 via NativeRootiSWAP\n",
291 | "----------------------------\n",
292 | "With target operation of TargetSWAP, costs are:\n",
293 | "3 via NativeCNOT\n",
294 | "3 via NativeCR90\n",
295 | "3 via NativeCZ\n",
296 | "3 via NativeiSWAP\n",
297 | "3 via NativeBSWAP\n",
298 | "3 via NativeMAP\n",
299 | "1.5 via NativeRootiSWAP\n",
300 | "----------------------------\n",
301 | "With target operation of TargetZZInteraction, costs are:\n",
302 | "2 via NativeCNOT\n",
303 | "2 via NativeCR90\n",
304 | "2 via NativeCZ\n",
305 | "2 via NativeiSWAP\n",
306 | "2 via NativeBSWAP\n",
307 | "2 via NativeMAP\n",
308 | "1.0 via NativeRootiSWAP\n",
309 | "----------------------------\n",
310 | "With target operation of TargetZZSWAP, costs are:\n",
311 | "3 via NativeCNOT\n",
312 | "3 via NativeCR90\n",
313 | "3 via NativeCZ\n",
314 | "3 via NativeiSWAP\n",
315 | "3 via NativeBSWAP\n",
316 | "3 via NativeMAP\n",
317 | "1.5 via NativeRootiSWAP\n",
318 | "----------------------------\n",
319 | "With target operation of TargetFermionicSimulation, costs are:\n",
320 | "3 via NativeCNOT\n",
321 | "3 via NativeCR90\n",
322 | "3 via NativeCZ\n",
323 | "3 via NativeiSWAP\n",
324 | "3 via NativeBSWAP\n",
325 | "3 via NativeMAP\n",
326 | "1.5 via NativeRootiSWAP\n",
327 | "----------------------------\n",
328 | "With target operation of TargetFermionicFourierTransform, costs are:\n",
329 | "2 via NativeCNOT\n",
330 | "2 via NativeCR90\n",
331 | "2 via NativeCZ\n",
332 | "2 via NativeiSWAP\n",
333 | "2 via NativeBSWAP\n",
334 | "2 via NativeMAP\n",
335 | "1.0 via NativeRootiSWAP\n",
336 | "----------------------------\n",
337 | "With target operation of TargetBogoliubovTransform, costs are:\n",
338 | "2 via NativeCNOT\n",
339 | "2 via NativeCR90\n",
340 | "2 via NativeCZ\n",
341 | "2 via NativeiSWAP\n",
342 | "2 via NativeBSWAP\n",
343 | "2 via NativeMAP\n",
344 | "1.0 via NativeRootiSWAP\n",
345 | "----------------------------\n"
346 | ]
347 | }
348 | ],
349 | "source": [
350 | "for target_operation in target_two_qubit_operations:\n",
351 | " print('With target operation of %s, costs are:' % target_operation)\n",
352 | "\n",
353 | " for native_gate in native_two_qubit_gates:\n",
354 | " decomposer = TwoQubitBasisDecomposer(q.extensions.UnitaryGate(native_gate.get_unitary()))\n",
355 | " num_basis_gates = 0\n",
356 | " for unitary in target_operation.get_unitaries():\n",
357 | " num_basis_gates = max(num_basis_gates, decomposer.num_basis_gates(unitary))\n",
358 | " if type(native_gate) == NativeRootiSWAP:\n",
359 | " num_basis_gates *= 0.5 # sqrt(iSWAP) gate cost should be normalized to iSWAP cost\n",
360 | " print(num_basis_gates, 'via', native_gate)\n",
361 | " print('----------------------------')"
362 | ]
363 | },
364 | {
365 | "cell_type": "markdown",
366 | "metadata": {},
367 | "source": [
368 | "## Continuous Native Gates:\n",
369 | "First define minimization problem"
370 | ]
371 | },
372 | {
373 | "cell_type": "code",
374 | "execution_count": null,
375 | "metadata": {},
376 | "outputs": [],
377 | "source": [
378 | "def get_best_decomposition(target_two_qubit_operation, native_two_qubit_gate):\n",
379 | " for k in [1, 2, 3]:\n",
380 | " if has_k_step_decomposition(target_two_qubit_operation, native_two_qubit_gate, k):\n",
381 | " return k\n",
382 | " assert False, 'did not find any 3-step decomposition'\n",
383 | " \n",
384 | "\n",
385 | "def has_k_step_decomposition(target_two_qubit_operation, native_two_qubit_gate, k):\n",
386 | " for target_unitary in target_two_qubit_operation.get_unitaries():\n",
387 | " num_failures = 0\n",
388 | " while True:\n",
389 | " result = k_step_minimization(target_unitary, native_two_qubit_gate, k)\n",
390 | " if result.fun > -0.99:\n",
391 | " num_failures += 1 # retry up to 10 times before giving up\n",
392 | " if num_failures >= 10:\n",
393 | " return False\n",
394 | " else:\n",
395 | " break\n",
396 | " return True\n",
397 | "\n",
398 | "\n",
399 | "def k_step_minimization(target_unitary, native_two_qubit_gate, k):\n",
400 | " # there are k+1 single qubit layers and k two qubit layers\n",
401 | " # yielding a total of 2(k+1) single qubit gates and k two qubit gates\n",
402 | " # each single qubit gate has 3 parameters, so they contribute to 6k + 6 parameters\n",
403 | " num_params = (6 * k + 6) + k * (native_two_qubit_gate.num_params)\n",
404 | " params = [np.random.random() for _ in range(num_params)]\n",
405 | " \n",
406 | " from functools import partial\n",
407 | " foo = partial(get_fidelity, target_unitary=target_unitary, native_two_qubit_gate=native_two_qubit_gate, k=k)\n",
408 | " nonlinear_constraint= NonlinearConstraint(foo, lb=-np.inf, ub=-0.999);\n",
409 | " return minimize(two_qubit_duration, params,\n",
410 | " args=(target_unitary, native_two_qubit_gate, k),\n",
411 | " method='trust-constr', constraints=[nonlinear_constraint],\n",
412 | " options={'maxiter': 1000})\n",
413 | "\n",
414 | "\n",
415 | "def get_fidelity(params, target_unitary, native_two_qubit_gate, k):\n",
416 | " params = list(params) # so that we can call .pop()\n",
417 | " single_qubit_u = [] # list of 2(k+1) single qubit gates\n",
418 | " for i in range(2*(k + 1)):\n",
419 | " a, b, c = params[3*i], params[3*i + 1], params[3*i + 2] # generic single-qubit unitary has 3 params\n",
420 | " single_qubit_u.append(np.array([[np.exp(1j * a) * np.cos(b), np.exp(1j * c) * np.sin(b)],\n",
421 | " [-np.exp(-1j * c) * np.sin(b), np.exp(-1j * a) * np.cos(b)]]))\n",
422 | "\n",
423 | " two_qubit_u = [] # list of k two-qubit gates\n",
424 | " if native_two_qubit_gate.num_params == 0:\n",
425 | " for _ in range(k):\n",
426 | " two_qubit_u.append(native_two_qubit_gate.get_unitary())\n",
427 | " else:\n",
428 | " for i in range(6*k+6, 6*k+9):\n",
429 | " two_qubit_u.append(native_two_qubit_gate.get_unitary([params[i]]))\n",
430 | "\n",
431 | " actual_unitary = np.eye(4)\n",
432 | " for i in range(k):\n",
433 | " actual_unitary = actual_unitary @ np.kron(single_qubit_u.pop(), single_qubit_u.pop())\n",
434 | " actual_unitary = actual_unitary @ two_qubit_u.pop()\n",
435 | " actual_unitary = actual_unitary @ np.kron(single_qubit_u.pop(), single_qubit_u.pop())\n",
436 | "\n",
437 | " fidelity = np.abs(np.trace(actual_unitary @ np.linalg.inv(target_unitary))) / 4\n",
438 | " return -fidelity # return negative, since we will minimize\n",
439 | "\n",
440 | "\n",
441 | "def two_qubit_duration(params, target_unitary, native_two_qubit_gate, k):\n",
442 | " two_qubit_params = params[-k:]\n",
443 | " return sum(map(np.abs, two_qubit_params)) / (np.pi / 2)"
444 | ]
445 | },
446 | {
447 | "cell_type": "code",
448 | "execution_count": null,
449 | "metadata": {},
450 | "outputs": [],
451 | "source": [
452 | "k_step_minimization(TargetSWAP().get_unitaries()[0], NativeParametrizediSWAP(), 3)"
453 | ]
454 | },
455 | {
456 | "cell_type": "code",
457 | "execution_count": null,
458 | "metadata": {},
459 | "outputs": [],
460 | "source": [
461 | "sum(map(np.abs, [-0.77709967,0.78626331,1.56080778]))"
462 | ]
463 | },
464 | {
465 | "cell_type": "code",
466 | "execution_count": null,
467 | "metadata": {},
468 | "outputs": [],
469 | "source": []
470 | },
471 | {
472 | "cell_type": "code",
473 | "execution_count": null,
474 | "metadata": {},
475 | "outputs": [],
476 | "source": []
477 | },
478 | {
479 | "cell_type": "code",
480 | "execution_count": null,
481 | "metadata": {},
482 | "outputs": [],
483 | "source": []
484 | },
485 | {
486 | "cell_type": "markdown",
487 | "metadata": {},
488 | "source": [
489 | "---\n",
490 | "## Results"
491 | ]
492 | },
493 | {
494 | "cell_type": "code",
495 | "execution_count": null,
496 | "metadata": {},
497 | "outputs": [],
498 | "source": [
499 | "native_two_qubit_gates = [NativeCNOT(), NativeiSWAP(), NativeCR(), NativeParametrizediSWAP()]\n",
500 | "target_two_qubit_operations = [TargetCNOT(), TargetSWAP(),\n",
501 | " TargetZZInteraction(), TargetZZSWAP(),\n",
502 | " TargetFermionicSimulation(),\n",
503 | " TargetFermionicFourierTransform(), TargetBogoliubovTransform()]"
504 | ]
505 | },
506 | {
507 | "cell_type": "code",
508 | "execution_count": null,
509 | "metadata": {},
510 | "outputs": [],
511 | "source": [
512 | "results = {}\n",
513 | "for target_two_qubit_operation in target_two_qubit_operations:\n",
514 | " for native_two_qubit_gate in native_two_qubit_gates:\n",
515 | " k = get_best_decomposition(target_two_qubit_operation, native_two_qubit_gate)\n",
516 | " results[(target_two_qubit_operation, native_two_qubit_gate)] = k"
517 | ]
518 | },
519 | {
520 | "cell_type": "code",
521 | "execution_count": null,
522 | "metadata": {},
523 | "outputs": [],
524 | "source": [
525 | "row_format =\"{:>20}\" * (len(native_two_qubit_gates) + 1)\n",
526 | "print(row_format.format(\"\", *map(lambda s: str(s)[6:], native_two_qubit_gates)))\n",
527 | "for target_two_qubit_operation in target_two_qubit_operations:\n",
528 | " row = [results[target_two_qubit_operation, native_two_qubit_gate] for native_two_qubit_gate in native_two_qubit_gates]\n",
529 | " print(row_format.format(str(target_two_qubit_operation)[6:], *row))"
530 | ]
531 | },
532 | {
533 | "cell_type": "code",
534 | "execution_count": null,
535 | "metadata": {},
536 | "outputs": [],
537 | "source": []
538 | }
539 | ],
540 | "metadata": {
541 | "kernelspec": {
542 | "display_name": "Python 3",
543 | "language": "python",
544 | "name": "python3"
545 | },
546 | "language_info": {
547 | "codemirror_mode": {
548 | "name": "ipython",
549 | "version": 3
550 | },
551 | "file_extension": ".py",
552 | "mimetype": "text/x-python",
553 | "name": "python",
554 | "nbconvert_exporter": "python",
555 | "pygments_lexer": "ipython3",
556 | "version": "3.7.3"
557 | }
558 | },
559 | "nbformat": 4,
560 | "nbformat_minor": 2
561 | }
562 |
--------------------------------------------------------------------------------
/benchmarks.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | import qiskit as q
4 | import qiskit.tools.jupyter
5 | from qiskit.pulse import pulse_lib as _ # only want to call pulse_lib as q.pulse.pulse_lib
6 |
7 |
8 | def get_line_maxcut_qaoa_circuit(N, beta=np.pi/3, gamma=np.pi/3):
9 | circ = q.QuantumCircuit(N)
10 | for i in range(N):
11 | circ.h(i)
12 |
13 | for i in range(N - 1):
14 | circ.zz_interaction(gamma, i, i + 1)
15 |
16 | for i in range(N):
17 | circ.rx(beta, i)
18 |
19 | return circ
20 |
21 |
22 | def get_CH4_trotter_simulation_circuit(num_trotter_steps=1, superposition_start=True):
23 | """This circuit only applies phasing, so has no effect on |00> state.
24 | Use |++> instead, unless performing process tomography and phase effects can be measured.
25 |
26 | CH4_sto-3g_BK_grnd_AS1.txt
27 | Hamiltonian is -25.749885689311967 I0 + 1.8095454182113748 Z0 +
28 | 1.8095454182113748 Z0 Z1 + 0.8752795188418716Z1
29 | """
30 | N = 2
31 | circ = q.QuantumCircuit(N)
32 |
33 | if superposition_start:
34 | for i in range(N):
35 | circ.h(i)
36 |
37 | for _ in range(num_trotter_steps):
38 | circ.rz(1.8095454182113748 / num_trotter_steps, 0)
39 | circ.rz(0.8752795188418716 / num_trotter_steps, 1)
40 |
41 | circ.zz_interaction(1.8095454182113748 / num_trotter_steps, 0, 1)
42 |
43 |
44 | return circ
45 |
46 |
47 | def get_H2O_trotter_simulation_circuit(num_trotter_steps=1, superposition_start=True):
48 | """This circuit only applies phasing, so has no effect on |00> state.
49 | Use |++> instead, unless performing process tomography and phase effects can be measured.
50 |
51 | H2O_6-31g_BK_104_AS1.txt
52 | Hamiltonian is -93.72260987098602 I0 + 8.649346371694238 Z0
53 | 8.649346371694238 Z0 Z1 + 1.1849141858184884 Z1
54 | """
55 | N = 2
56 | circ = q.QuantumCircuit(N)
57 |
58 | if superposition_start:
59 | for i in range(N):
60 | circ.h(i)
61 |
62 |
63 | for _ in range(num_trotter_steps):
64 | circ.rz(8.649346371694238 / num_trotter_steps, 0)
65 | circ.rz(1.1849141858184884 / num_trotter_steps, 1)
66 | circ.zz_interaction(8.649346371694238 / num_trotter_steps, 0, 1)
67 |
68 |
69 | return circ
70 |
71 |
72 | def get_H2_trotter_simulation_circuit(num_trotter_steps=1, superposition_start=True):
73 | """This circuit only applies phasing, so has no effect on |00> state.
74 | Use |++> instead, unless performing process tomography and phase effects can be measured.
75 |
76 | H2_6-31g_JW_0.7_AS1.txt
77 | Hamiltonian is 12.990317523564187 I0 + -1.3462263309526756 Z0
78 | 0.1663920290097622 Z0 Z1 + -1.3462263309526756 Z1
79 | """
80 | N = 2
81 | circ = q.QuantumCircuit(N)
82 |
83 | if superposition_start:
84 | for i in range(N):
85 | circ.h(i)
86 |
87 | for _ in range(num_trotter_steps):
88 | circ.rz(-1.3462263309526756 / num_trotter_steps, 1)
89 | circ.zz_interaction(0.1663920290097622 / num_trotter_steps, 0, 1)
90 | circ.rz(-1.3462263309526756 / num_trotter_steps, 1)
91 |
92 | return circ
93 |
94 |
95 | def get_LiH_trotter_simulation_circuit(num_trotter_steps=1, superposition_start=True):
96 | """This circuit only applies phasing, so has no effect on |00> state.
97 | Use |++> instead, unless performing process tomography and phase effects can be measured.
98 |
99 | LiH_sto-3g_BK_1.45_AS1.txt
100 | Hamiltonian is 2.839189402302054 I0 - 0.767730045854766 Z0
101 | -0.767730045854766 Z0 Z1 + 0.4144660434569498 Z1
102 | """
103 | N = 2
104 | circ = q.QuantumCircuit(N)
105 |
106 | if superposition_start:
107 | for i in range(N):
108 | circ.h(i)
109 |
110 | for _ in range(num_trotter_steps):
111 | circ.rz(-0.767730045854766 / num_trotter_steps, 1)
112 | circ.zz_interaction(-0.767730045854766 / num_trotter_steps, 0, 1)
113 | circ.rz(0.4144660434569498 / num_trotter_steps, 1)
114 |
115 | return circ
116 |
117 |
118 | def get_LiH_VQE(alpha, beta):
119 | """LiH VQE UCCSD circuit from https://arxiv.org/pdf/1803.10238.pdf.
120 | Per eq. 8, and relabeling qubits {2, 4, 6} to {1, 0, 2}, we have
121 | U_UCCSD = exp(-i*alpha* Y_0 X_1) * exp(-i*beta* X_1 Y_2)
122 | applied to |111>.
123 | """
124 | N = 3
125 | circ = q.QuantumCircuit(N)
126 | circ.x(0); circ.x(1); circ.x(2); # start with |111>
127 |
128 | # note that two inner H's on qubit 1 cancel out
129 |
130 | # exp(-i*beta* X_1 Y_2)
131 | circ.h(1)
132 | circ.sdg(2); circ.h(2)
133 | circ.cx(1, 2); circ.rz(beta, 2); circ.cx(1, 2);
134 | circ.h(2); circ.s(2)
135 |
136 | # exp(-i*alpha* Y_0 X_1)
137 | circ.sdg(0); circ.h(0);
138 | circ.cx(0, 1); circ.rz(alpha, 1); circ.cx(0, 1);
139 | circ.h(0); circ.s(0);
140 | circ.h(1)
141 |
142 | return circ
143 |
144 |
145 | def get_H2_VQE(theta):
146 | """H2 VQE UCCSD from https://arxiv.org/pdf/1512.06860.pdf Fig 1.
147 |
148 | I am reversing the indices from the figure."""
149 | N = 2
150 | circ = q.QuantumCircuit(N)
151 | circ.ry(np.pi / 2, 0)
152 | circ.rx(np.pi / 2, 1)
153 | circ.cx(0, 1); circ.rz(theta, 1); circ.cx(0, 1)
154 | circ.ry(-np.pi / 2, 0)
155 | circ.rx(np.pi / 2, 1)
156 | return circ
157 |
158 |
159 | def get_deuteron_VQE(theta, eta):
160 | """Deueteron 3-qubit VQE UCCSD from https://arxiv.org/pdf/1801.03897.pdf Fig 1b.
161 |
162 | I shifted the qubits so that the top qubit moves to the bottom--this maps well.
163 | I also used the identity Ry(-eta) = Rx(-90deg) Rz(-eta) Rx(90deg)
164 | to recover the ZZ Interaction."""
165 | N = 3
166 | circ = q.QuantumCircuit(N)
167 | circ.ry(theta, 0)
168 | circ.x(1)
169 | circ.ry(eta, 2)
170 | circ.cx(0, 1)
171 | circ.rx(np.pi/2, 2)
172 | circ.cx(1, 2); circ.rz(-eta, 2); circ.cx(1, 2);
173 | circ.rx(-np.pi/2, 2)
174 | circ.cx(2, 1)
175 | return circ
176 |
177 |
178 | def main():
179 | # print(get_line_maxcut_qaoa_circuit(4))
180 | # print(get_H2O_trotter_simulation_circuit())
181 | # print(get_H2_trotter_simulation_circuit())
182 | # print(get_LiH_trotter_simulation_circuit())
183 | # print(get_CH4_trotter_simulation_circuit())
184 | # print(get_LiH_VQE(0.3, 0.4))
185 | # print(get_H2_VQE(0.3))
186 | print(get_deuteron_VQE(0.3, 0.4))
187 |
188 |
189 | if __name__ == "__main__":
190 | main()
191 |
--------------------------------------------------------------------------------
/pulse_compiler_helper_fns.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import qiskit as q
3 |
4 |
5 | def update_basis_gates_and_circ_inst_map(decomposed_circuit, backend, circ_inst_map):
6 | """While Parametrized Schedules are not supported, simply update basis gates and circ_inst_map."""
7 | basis_gates = backend.configuration().basis_gates
8 | for instruction, qargs, cargs in decomposed_circuit.data:
9 | if instruction.name.startswith('direct_rx'):
10 | if instruction.name not in basis_gates:
11 | basis_gates.append(instruction.name)
12 |
13 | if not circ_inst_map.has(instruction.name, qubits=[qargs[0].index]):
14 | theta = float(instruction.name[len('direct_rx_'):])
15 | schedule = get_direct_rx_schedule(theta, qargs[0].index, circ_inst_map, backend)
16 | circ_inst_map.add(instruction.name, qubits=[qargs[0].index], schedule=schedule)
17 |
18 | elif instruction.name.startswith('cr'):
19 | if instruction.name not in basis_gates:
20 | basis_gates.append(instruction.name)
21 |
22 | if not circ_inst_map.has(instruction.name, qubits=[qargs[0].index, qargs[1].index]):
23 | theta = float(instruction.name[len('cr_'):])
24 | schedule = get_cr_schedule(theta, qargs[0].index, qargs[1].index, circ_inst_map, backend)
25 | circ_inst_map.add(instruction.name,
26 | qubits=[qargs[0].index, qargs[1].index], schedule=schedule)
27 |
28 | elif instruction.name == 'open_cx':
29 | if instruction.name not in basis_gates:
30 | basis_gates.append(instruction.name)
31 |
32 |
33 | def rescale_samples(samples, scale_factor, method='rescale_height'):
34 | assert scale_factor <= 1, 'only tested for scaling down pulses'
35 |
36 | if method == 'rescale_height':
37 | return _rescale_height(samples, scale_factor)
38 | elif method == 'rescale_width':
39 | return _rescale_width(samples, scale_factor)
40 | elif method == 'rescale_height_and_width':
41 | return _rescale_height_and_width(samples, scale_factor)
42 |
43 |
44 | def _rescale_height(samples, scale_factor):
45 | return samples * scale_factor
46 |
47 |
48 | def _rescale_width(samples, scale_factor):
49 | assert False, 'still debugging implementation'
50 |
51 |
52 | def _rescale_height_and_width(samples, scale_factor):
53 | assert False, 'still debugging implementation'
54 |
55 | print('original real area under curve is %s' % sum(map(np.real, samples)))
56 |
57 | rescaled_length = int(0.5 + len(samples) * np.sqrt(scale_factor))
58 | rescaled_samples = [0] * rescaled_length
59 | width_scale_factor = rescaled_length / len(samples)
60 | height_scale_factor = scale_factor / width_scale_factor
61 | samples = samples * scale_factor
62 |
63 | for i in range(len(samples)):
64 | # split samples[i...i+1] into rescaled_samples[i/scale_factor...(i+1)/scale_factor]
65 | if int(i * width_scale_factor) == int((i + 1) * width_scale_factor):
66 | rescaled_samples[int(i * width_scale_factor)] += samples[i]
67 | else:
68 | fraction = int(1 + i * width_scale_factor) - int(i * width_scale_factor)
69 | rescaled_samples[int(i * width_scale_factor)] += samples[i] * fraction
70 | rescaled_samples[int(i * width_scale_factor)] += samples[i] * (1 - fraction)
71 | print('final real area under curve is %s' % sum(map(np.real, rescaled_samples)))
72 | return rescaled_samples
73 |
74 |
75 | def get_direct_rx_schedule(theta, qubit_index, circ_inst_map, backend):
76 | x_instructions = circ_inst_map.get('x', qubits=[qubit_index]).instructions
77 | assert len(x_instructions) == 1
78 | x_samples = x_instructions[0][1].command.samples
79 | area_under_curve = sum(map(np.real, x_samples))
80 |
81 | if theta > np.pi:
82 | theta -= 2 * np.pi
83 |
84 | direct_rx_samples = rescale_samples(x_samples, (theta / np.pi))
85 | direct_rx_samplepulse = q.pulse.SamplePulse(direct_rx_samples)
86 | direct_rx_command = direct_rx_samplepulse(backend.configuration().drive(qubit_index))
87 | return q.pulse.Schedule([0, direct_rx_command])
88 |
89 | return direct_rx_command
90 |
91 |
92 | def get_cr_schedule(theta, control, target, circ_inst_map, backend):
93 |
94 | """Returns schedule for a cross-resonance pulse between control and target.
95 | Does a RX(-theta) on target if control is |0> and a RX(theta) on target if
96 | control is |1>.
97 | Crashes if the backend does not support CR between control and target
98 | (either because no connectivity, or because the CR is between target and control)
99 | """
100 | cx_instructions = circ_inst_map.get('cx', qubits=[control, target]).instructions
101 | xc_instructions = circ_inst_map.get('cx', qubits=[target, control]).instructions
102 | assert len(cx_instructions) < len(xc_instructions), 'CR pulse is on flipped indices'
103 |
104 | cr_control_inst = [inst for (_, inst) in cx_instructions if 'CR90p' in inst.name and inst.channels[0].name.startswith('u')]
105 | cr_drive_inst = [inst for (_, inst) in cx_instructions if 'CR90p' in inst.name and inst.channels[0].name.startswith('d')]
106 |
107 | assert len(cr_drive_inst) == 1 and len(cr_control_inst) == 1
108 | cr_control_inst = cr_control_inst[0] # driving of control qubit at target's frequency
109 | cr_drive_inst = cr_drive_inst[0] # active cancellation tone
110 |
111 | flip = False
112 | if theta < 0:
113 | flip = True
114 | theta = -1 * theta
115 |
116 | if theta > 2 * np.pi:
117 | theta -= 2 * np.pi
118 |
119 | full_area_under_curve = sum(map(np.real, cr_control_inst.command.samples))
120 | target_area_under_curve = full_area_under_curve * (theta / (np.pi / 2))
121 |
122 | # CR pulse samples have gaussian rise, flattop, and then gaussian fall.
123 | # we want to find the start and end indices of the flattop
124 | flat_start = 0
125 | while cr_drive_inst.command.samples[flat_start] != cr_drive_inst.command.samples[flat_start + 1]:
126 | flat_start += 1
127 | assert cr_control_inst.command.samples[flat_start] == cr_control_inst.command.samples[flat_start + 1]
128 |
129 | flat_end = flat_start + 1
130 | while cr_drive_inst.command.samples[flat_end] == cr_drive_inst.command.samples[flat_end + 1]:
131 | flat_end += 1
132 | assert cr_control_inst.command.samples[flat_end] == cr_control_inst.command.samples[flat_end - 1]
133 |
134 | area_under_curve = sum(map(np.real, cr_control_inst.command.samples[:flat_start]))
135 | area_under_curve += sum(map(np.real, cr_control_inst.command.samples[flat_end+1:]))
136 | flat_duration = (target_area_under_curve - area_under_curve) / np.real(cr_control_inst.command.samples[flat_start])
137 | flat_duration = max(0, int(flat_duration + 0.5))
138 | duration = len(cr_drive_inst.command.samples[:flat_start]) + flat_duration + len(cr_drive_inst.command.samples[flat_end+1:])
139 | if duration % 16 <= 8 and flat_duration > 8:
140 | flat_duration -= duration % 16
141 | else:
142 | flat_duration += 16 - (duration % 16)
143 |
144 | cr_drive_samples = np.concatenate([
145 | cr_drive_inst.command.samples[:flat_start],
146 | [cr_drive_inst.command.samples[flat_start]] * flat_duration,
147 | cr_drive_inst.command.samples[flat_end+1:]
148 | ])
149 |
150 | cr_control_samples = np.concatenate([
151 | cr_control_inst.command.samples[:flat_start],
152 | [cr_control_inst.command.samples[flat_start]] * flat_duration,
153 | cr_control_inst.command.samples[flat_end+1:]
154 | ])
155 |
156 | assert len(cr_drive_samples) % 16 == 0
157 | assert len(cr_control_samples) % 16 == 0
158 |
159 | current_area_under_curve = sum(map(np.real, cr_control_samples))
160 | scaling_factor = target_area_under_curve / current_area_under_curve
161 |
162 | cr_drive_samples *= scaling_factor
163 | cr_control_samples *= scaling_factor
164 |
165 | cr_p_schedule = q.pulse.SamplePulse(cr_drive_samples)(cr_drive_inst.channels[0]) | q.pulse.SamplePulse(
166 | cr_control_samples)(cr_control_inst.channels[0])
167 | cr_m_schedule = q.pulse.SamplePulse(-1*cr_drive_samples)(cr_drive_inst.channels[0]) | q.pulse.SamplePulse(
168 | -1*cr_control_samples)(cr_control_inst.channels[0])
169 |
170 | if flip:
171 | schedule = cr_m_schedule
172 | schedule |= circ_inst_map.get('x', qubits=[control]) << schedule.duration
173 | schedule |= cr_p_schedule << schedule.duration
174 | else:
175 | schedule = cr_p_schedule
176 | schedule |= circ_inst_map.get('x', qubits=[control]) << schedule.duration
177 | schedule |= cr_m_schedule << schedule.duration
178 |
179 | return schedule
180 |
181 |
182 | def kl_divergence(ideal_counts, actual_counts):
183 | """Return KL divergence between two frequency dictionaries."""
184 | ideal_total = sum(ideal_counts.values())
185 | actual_total = sum(actual_counts.values())
186 | kl_div = 0
187 | for k, v in ideal_counts.items():
188 | p = v / ideal_total
189 | q = actual_counts.get(k, 0) / actual_total
190 | if q != 0:
191 | kl_div += p * np.log(p / q)
192 | return kl_div
193 |
194 |
195 | def cross_entropy(ideal_counts, actual_counts):
196 | """Return cross entropy between two frequency dictionaries."""
197 | ideal_total = sum(ideal_counts.values())
198 | actual_total = sum(actual_counts.values())
199 | cross_entropy = 0
200 | for k, v in ideal_counts.items():
201 | p = v / ideal_total
202 | q = actual_counts.get(k, 0) / actual_total
203 | if q != 0:
204 | cross_entropy += -p * np.log(q)
205 | return cross_entropy
206 |
--------------------------------------------------------------------------------