Skip to content

IonQ and Quantinuum notebooks #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1752954
This branch aims to run boostvqe on IonQ simulators and QPU
Sam-XiaoyueLi Aug 15, 2024
3ae816e
Run boostvqe 3qubit, initial commit on running IonQ
Sam-XiaoyueLi Aug 20, 2024
c2796ec
Successfully run 1 step dbqa on ionQ simulator
Sam-XiaoyueLi Aug 29, 2024
36f04b2
Add add qci synthesis notebook
Sam-XiaoyueLi Nov 5, 2024
07c8eb6
Move results to correct folder
Sam-XiaoyueLi Nov 5, 2024
bcf39a2
Add load quantinuum notebook
Sam-XiaoyueLi Nov 5, 2024
a758433
Error in quantinuum hamiltonian; load quantinuum results locally
Sam-XiaoyueLi Nov 6, 2024
84d67bb
Update report
Sam-XiaoyueLi Nov 6, 2024
9905fe7
Add noise emulation result and report
Sam-XiaoyueLi Nov 6, 2024
c1f94aa
Add more results for emulation with noise
Sam-XiaoyueLi Nov 6, 2024
195c1d2
Merge branch 'fix-93' of https://github.com/qiboteam/boostvqe into IonQ
Sam-XiaoyueLi Nov 9, 2024
99e4382
Merge https://github.com/qiboteam/boostvqe into IonQ
Sam-XiaoyueLi Nov 9, 2024
cd7a0bd
Merge branch 'quantinuum_boostvqe-demo' of https://github.com/qibotea…
Sam-XiaoyueLi Nov 9, 2024
c79a5c9
Ionq notebook
Sam-XiaoyueLi Nov 9, 2024
9e72f1f
Complete ionq notebook
Sam-XiaoyueLi Nov 9, 2024
ebe5d51
Clean branch
Sam-XiaoyueLi Nov 11, 2024
a60df40
Move synthesis notebook out from quantinuum folder
Sam-XiaoyueLi Nov 11, 2024
2f59d0c
Corret file paths
Sam-XiaoyueLi Nov 11, 2024
c99cca9
Modify vqe training files storage option
Sam-XiaoyueLi Nov 13, 2024
abb9542
Update vqe and gci circuit strorage options
Sam-XiaoyueLi Nov 13, 2024
17718f4
Updated synthesis notebook
Sam-XiaoyueLi Nov 13, 2024
3b0c9ea
Relocate quantinuum job ref; add quantinuum_utils
Sam-XiaoyueLi Nov 17, 2024
d4e84dd
Add quantinuum load notebook for users without quantinuum access.
Sam-XiaoyueLi Nov 17, 2024
5e01746
save and load ionq results
Sam-XiaoyueLi Nov 17, 2024
5aee07b
Run different levels of optimisation and analyze gates
Sam-XiaoyueLi Nov 19, 2024
d04c37d
Exploration on optimisation level and run with optimisation level 2
Sam-XiaoyueLi Nov 19, 2024
e0e6d87
Changed settings for GCI>VQE
Sam-XiaoyueLi Nov 19, 2024
11bad8e
Multiple realisations and updated analytics
Sam-XiaoyueLi Nov 20, 2024
5c3df11
Updated notebooks to handle multiple results
Sam-XiaoyueLi Nov 20, 2024
2af83d5
Add reproducibility caption to report df
Sam-XiaoyueLi Nov 20, 2024
0b70d41
Clean out redundant function definition
Sam-XiaoyueLi Nov 20, 2024
3bf176e
Correct space typo
Sam-XiaoyueLi Nov 20, 2024
3457f0d
reorder cell
Sam-XiaoyueLi Nov 28, 2024
922cf64
optimization method
Sam-XiaoyueLi Nov 28, 2024
9cf4c21
Markdown typo
Sam-XiaoyueLi Nov 28, 2024
868f360
test 2 vqe
Sam-XiaoyueLi Jan 9, 2025
44e969e
Add nqubits=8 2 VQE results
Sam-XiaoyueLi Jan 10, 2025
fd25716
Native gate decomposition for XXZ model
Sam-XiaoyueLi Jan 14, 2025
a670691
Merge branch 'main' of https://github.com/qiboteam/boostvqe into ionq…
Sam-XiaoyueLi Jan 14, 2025
0f0d293
Trotter test XXZ model using native gates
Sam-XiaoyueLi Jan 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
616 changes: 616 additions & 0 deletions notebooks/gci_2vqe.ipynb

Large diffs are not rendered by default.

933 changes: 933 additions & 0 deletions notebooks/gci_boostvqe_circuit_synthesis.ipynb

Large diffs are not rendered by default.

672 changes: 672 additions & 0 deletions notebooks/ionq_demo/ionq_demo.ipynb

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions notebooks/ionq_demo/ionq_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
from qiskit.quantum_info import Pauli, SparsePauliOp
import numpy as np
from copy import deepcopy
import pandas as pd

def xxz_hamiltonian(n, delta=0.5, select=None):
"""Returns the XXZ model Hamiltonian for n qubits and a given delta in Qiskit.
select = "XX", "YY", "ZZ" or None. None (default) returns XXZ, while the others select
only the corresponding Pauli terms.
"""

# Initialize lists to store the Pauli strings and coefficients
pauli_strings = []
coefficients = []

for i in range(n):
# XX term (X_i * X_{i+1})
x_term = ['I'] * n
x_term[i] = 'X'
x_term[(i + 1)%n] = 'X'
if select == None or select == 'XX':
pauli_strings.append(''.join(x_term))
coefficients.append(1.0)

# YY term (Y_i * Y_{i+1})
y_term = ['I'] * n
y_term[i] = 'Y'
y_term[(i + 1)%n] = 'Y'
if select == None or select == 'YY':
pauli_strings.append(''.join(y_term))
coefficients.append(1.0)

# ZZ term (Z_i * Z_{i+1})
z_term = ['I'] * n
z_term[i] = 'Z'
z_term[(i + 1)%n] = 'Z'
if select == None or select == 'ZZ':
pauli_strings.append(''.join(z_term))
coefficients.append(delta)

# Create the SparsePauliOp object
paulis = [Pauli(p) for p in pauli_strings]
hamiltonian = SparsePauliOp(paulis, np.array(coefficients))

return hamiltonian

def binary_code_to_index(key):
index = 0
size = len(key)
for i in range(size):
index += int(key[i])* 2 ** (size - 1 - i)
return index

def sample_to_expectation(obs, distribution):
# check observable diagonal
# if (
# np.count_nonzero(
# obs - np.diag(np.diagonal(obs))
# )
# != 0
# ):
# print( "Observable is not diagonal.")
keys = list(distribution.keys())
freq = list(distribution.values())
expval = 0
for i, k in enumerate(keys):
index = binary_code_to_index(k)
expval += obs[index, index] * freq[i]
return np.real(expval)

def rotate_circuit_XYZ(qc):
"""Generate
Args:
qc: qiskit circuit
Returns: modified circuits for measuring in computational, 'X', and 'Y' basis.
"""
nqubits = qc.num_qubits
# X
qc_x = deepcopy(qc)
for i in range(nqubits):
qc_x.h(i)
qc_x.measure_all()
# Y
qc_y = deepcopy(qc)
for i in range(nqubits):
qc_y.sdg(i)
qc_y.h(i)
qc_y.measure_all()
# Z
qc_z = deepcopy(qc)
qc_z.measure_all()
return [qc_x, qc_y, qc_z]

def report_ionq(vqe_analytical, gci_analytical, ham_matrix, expval_vqe, expval_gci, expval_vqe_noise, expval_gci_noise):
eigenvalues, eigenstates = eigh(ham_matrix)
ground_state_energy = eigenvalues[0]
vqe_energy = vqe_analytical
gci_energy = gci_analytical
gap = float(eigenvalues[1] - eigenvalues[0])
return (
dict(
nqubits = int(np.log(len(ham_matrix))/np.log(2)),
gci_energy=float(gci_energy),
vqe_energy=float(vqe_energy),
vqe_energy_emulator=float(expval_vqe),
gci_energy_emulator=float(expval_gci),
vqe_energy_emulator_noise=float(expval_vqe_noise),
gci_energy_emulator_noise=float(expval_gci_noise),
target_energy=ground_state_energy,
diff_vqe_target=vqe_energy - ground_state_energy,
diff_gci_target=gci_energy - ground_state_energy,
diff_vqe_target_emulator=expval_vqe - ground_state_energy,
diff_gci_target_emulator=expval_gci - ground_state_energy,
diff_vqe_target_emulator_noise=expval_vqe_noise - ground_state_energy,
diff_gci_target_emulator_noise=expval_gci_noise - ground_state_energy,
gap=gap,
diff_vqe_target_perc=abs(vqe_energy - ground_state_energy)
/ abs(ground_state_energy)
* 100,
diff_gci_target_perc=abs(gci_energy - ground_state_energy)
/ abs(ground_state_energy)
* 100,
diff_vqe_target_perc_emulator=abs(expval_vqe - ground_state_energy)
/ abs(ground_state_energy)
* 100,
diff_gci_target_perc_emulator=abs(expval_gci - ground_state_energy)
/ abs(ground_state_energy)
* 100,
diff_vqe_target_perc_emulator_noise=abs(expval_vqe_noise - ground_state_energy)
/ abs(ground_state_energy)
* 100,
diff_gci_target_perc_emulator_noise=abs(expval_gci_noise - ground_state_energy)
/ abs(ground_state_energy)
* 100,
fidelity_witness_vqe=1 - (vqe_energy - ground_state_energy) / gap,
fidelity_witness_gci=1 - (gci_energy - ground_state_energy) / gap,
fidelity_witness_vqe_emulator=1 - (expval_vqe - ground_state_energy) / gap,
fidelity_witness_gci_emulator=1 - (expval_gci - ground_state_energy) / gap,
fidelity_witness_vqe_emulator_noise=1 - (expval_vqe_noise - ground_state_energy) / gap,
fidelity_witness_gci_emulator_noise=1 - (expval_gci_noise - ground_state_energy) / gap,
)
)

def report_table(report):
df = pd.DataFrame({
"Analytical": [
report['vqe_energy'],
report['gci_energy'],
report['diff_vqe_target'],
report['diff_gci_target'],
report['diff_vqe_target_perc'],
report['diff_gci_target_perc'],
report['fidelity_witness_vqe'],
report['fidelity_witness_gci']
],
"Emulator": [
report['vqe_energy_emulator'],
report['gci_energy_emulator'],
report['diff_vqe_target_emulator'],
report['diff_gci_target_emulator'],
report['diff_vqe_target_perc_emulator'],
report['diff_gci_target_perc_emulator'],
report['fidelity_witness_vqe_emulator'],
report['fidelity_witness_gci_emulator']
],
"Emulator with Noise": [
report['vqe_energy_emulator_noise'],
report['gci_energy_emulator_noise'],
report['diff_vqe_target_emulator_noise'],
report['diff_gci_target_emulator_noise'],
report['diff_vqe_target_perc_emulator_noise'],
report['diff_gci_target_perc_emulator_noise'],
report['fidelity_witness_vqe_emulator_noise'],
report['fidelity_witness_gci_emulator_noise']
]
}, index=[
"VQE energy",
"GCI energy",
"Difference to target (VQE)",
"Difference to target (GCI)",
"Percentage difference to target (VQE)",
"Percentage difference to target (GCI)",
"Fidelity witness (VQE)",
"Fidelity witness (GCI)"
])
return df
Loading