-
Notifications
You must be signed in to change notification settings - Fork 92
RGD optimization method for quantum state tomography #1485
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
Draft
HuberyMing
wants to merge
31
commits into
qiboteam:master
Choose a base branch
from
HuberyMing:QST
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3b78faf
QST-RGD
50a4739
Merge branch 'qiboteam:master' into QST
HuberyMing 13ab8f2
Run_example
7a54d8f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8e1af29
Update src/qibo/tomography_RGD/Run_Tomo.py
HuberyMing cca0e2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 489f617
Merge branch 'qiboteam:master' into QST
HuberyMing 49caa21
Update src/qibo/tomography_RGD/Run_Tomo.py
HuberyMing 6e3e066
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1ac3eec
Update src/qibo/tomography_RGD/qibo_states.py
HuberyMing f532834
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1e6e7fd
update random_density_matrix usage
16c1670
Update src/qibo/tomography_RGD/BasicTools.py
HuberyMing 75f1234
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a69251c
update Generate_All_labels fun
659dc63
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 506fde5
Merge branch 'qiboteam:master' into QST
HuberyMing b979ca7
shot measure to Pauli coef
2435060
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5d95113
ghz_state usage
b6b2bd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a410932
methodsRGD New
7a24711
simplify projectors and measurements
e543754
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] de22899
Merge branch 'qiboteam:master' into QST
HuberyMing 5ff1a5a
remove old file
16c6430
add jupyter notebook
d3130b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b664443
Merge branch 'qiboteam:master' into QST
HuberyMing 17cfbb5
2025 update
HuberyMing a204788
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| src/qibo/tomography_RGD/testData/ | ||
|
|
||
| # C extensions | ||
| *.so | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # | ||
| # some tools | ||
| # 1. generate all labels | ||
| # 2. plot the results | ||
| # | ||
|
|
||
| import matplotlib.pyplot as plt | ||
|
|
||
|
|
||
| # --------------------------------- # | ||
| # to generate all symbols # | ||
| # --------------------------------- # | ||
| def Generate_All_labels(Nk, symbols=["I", "X", "Y", "Z"]): | ||
| """generate all possible labels | ||
|
|
||
| Args: | ||
| Nk (int): number of qubits | ||
| symbols (list, optional): the possible choice of each qubit site. Defaults to ['I', 'X', 'Y', 'Z']. | ||
|
|
||
| Returns: | ||
| list: list of all possible labels | ||
| """ | ||
|
|
||
| symList = symbols | ||
|
|
||
| for i in range(1, Nk): | ||
| print(" the {}-th qubit".format(i)) | ||
|
|
||
| sym_Generated = [] | ||
| for symNow in symList: | ||
| sym_Generated = sym_Generated + ["".join([symNow, s]) for s in symbols] | ||
| # print(sym_Generated) | ||
| symList = sym_Generated | ||
| print(" totol number of labels {}".format(len(symList))) | ||
|
|
||
| return symList | ||
|
|
||
|
|
||
| def Plt_Err_Time(worker): | ||
| """plot the Error w.r.t. optimization run time | ||
|
|
||
| Args: | ||
| worker (class): the optimization class instance | ||
| """ | ||
|
|
||
| Target_Err_Xk = worker.Target_Err_Xk | ||
| step_Time = worker.step_Time | ||
|
|
||
| RunT = [] | ||
| Ttot = 0 | ||
| for ti in range(-1, len(step_Time) - 1): | ||
| Each_Step = step_Time[ti] | ||
| Ttot += Each_Step | ||
| RunT.append(Ttot) | ||
|
|
||
| mk_list = ["+", "^", "o", "x", ">", "<", 2, 3] | ||
| ln_list = ["-", "-.", "--", "--", ":", "-"] | ||
|
|
||
| fig, axNow = plt.subplots(1, 1, figsize=(8, 6)) | ||
|
|
||
| info = "{} qubits with sampling {} labels".format(worker.n, worker.num_labels) | ||
| axNow.plot( | ||
| RunT, | ||
| Target_Err_Xk, | ||
| marker=mk_list[0], | ||
| linestyle=ln_list[0], | ||
| label="{}".format(info), | ||
| ) | ||
|
|
||
| axNow.set_xlabel(" Run time (sec)", fontsize=14) | ||
| axNow.set_ylabel(r"$\left\Vert X_k -\rho \right\Vert_F$", fontsize=14) | ||
|
|
||
| axNow.set_title("Error w.r.t. run time", y=1.0, fontsize=14) | ||
|
|
||
| plt.legend(loc="upper left") | ||
| plt.show() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,196 @@ | ||||||
| # | ||||||
| # prepare the state, do the measurements | ||||||
| # and directly do the tomography | ||||||
| # | ||||||
| # | ||||||
|
|
||||||
| import measurements | ||||||
| import methodsMiFGD_core | ||||||
| import methodsRGD_core | ||||||
| import numpy as np | ||||||
| import projectors | ||||||
| import qutip as qu | ||||||
renatomello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| from BasicTools import Generate_All_labels, Plt_Err_Time | ||||||
|
|
||||||
| # from states import GHZState, HadamardState, RandomState | ||||||
| from qibo_states import GHZState, HadamardState, RandomState | ||||||
|
|
||||||
| from qibo import quantum_info | ||||||
HuberyMing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| if __name__ == "__main__": | ||||||
|
|
||||||
| ############################################################ | ||||||
| ### Example of creating and running an experiment | ||||||
| ############################################################ | ||||||
|
|
||||||
| # n = 3; labels = projectors.generate_random_label_list(50, n) | ||||||
| n = 4 | ||||||
| labels = projectors.generate_random_label_list(120, n) | ||||||
|
|
||||||
| # labels = ['YXY', 'IXX', 'ZYI', 'XXX', 'YZZ'] | ||||||
| # labels = ['YZYX', 'ZZIX', 'XXIZ', 'XZIY', 'YXYI', 'ZYYX', 'YXXX', 'IIYY', 'ZIXZ', 'IXXI', 'YZXI', 'ZZYI', 'YZXY', 'XYZI', 'XZXI', 'XZYX', 'YIXI', 'IZYY', 'ZIZX', 'YXXY'] | ||||||
| # labels = ['IIIX', 'IYIY', 'YYXI', 'ZZYY', 'ZYIX', 'XIII', 'XXZI', 'YXZI', 'IZXX', 'YYIZ', 'XXIY', 'XXZY', 'ZZIY', 'YIYX', 'YYZZ', 'YZXZ', 'YZYZ', 'ZXYY', 'IXIZ', 'XZII'] | ||||||
| # labels = Generate_All_labels(n) | ||||||
|
|
||||||
| num_labels = len(labels) | ||||||
|
|
||||||
| circuit_Choice = 1 | ||||||
| if circuit_Choice == 1: # generate from circuit | ||||||
| Nr = 1 | ||||||
|
|
||||||
| # state = GHZState(n) | ||||||
| # state = HadamardState(n) | ||||||
| state = RandomState(n) | ||||||
|
|
||||||
| target_density_matrix = state.get_state_matrix() | ||||||
| target_state = state.get_state_vector() | ||||||
| # print(state.get_state_vector()) | ||||||
|
|
||||||
| # | ||||||
| # DO the shot measurement | ||||||
| # | ||||||
|
|
||||||
| state.create_circuit() | ||||||
| data_dict_list = state.execute_measurement_circuits(labels) | ||||||
| # print(data_dict_list) | ||||||
|
|
||||||
| # | ||||||
| # shot measurement results --> coefficient for each Pauli operator | ||||||
| # | ||||||
|
|
||||||
| data_dict = {} | ||||||
| for ii in range(num_labels): | ||||||
| label = data_dict_list[ii]["label"] | ||||||
| data_dict[label] = data_dict_list[ii]["count_dict"] | ||||||
|
|
||||||
| measurement_list = measurements.MeasurementStore.calc_measurement_list( | ||||||
| labels, data_dict | ||||||
| ) | ||||||
|
|
||||||
| elif circuit_Choice == 2: # directly generate density matrix via qutip | ||||||
| Nr = 1 | ||||||
| rho = qu.rand_dm_ginibre(2**n, dims=[[2] * n, [2] * n], rank=Nr) | ||||||
|
||||||
| rho = qu.rand_dm_ginibre(2**n, dims=[[2] * n, [2] * n], rank=Nr) | |
| rho = random_density_matrix(2**n, rank=Nr, metric="ginibre") |
HuberyMing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
HuberyMing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.