Skip to content

Commit

Permalink
Standardize rpe estimate arg order, fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegulshen committed Jul 23, 2019
1 parent 29c2e2b commit 14acb19
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
24 changes: 12 additions & 12 deletions examples/robust_phase_estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"rpe.robust_phase_estimate([qubit], rz_results)"
"rpe.robust_phase_estimate(rz_results, [qubit])"
]
},
{
Expand Down Expand Up @@ -127,7 +127,7 @@
"source": [
"rx_results = rpe.acquire_rpe_data(qc, rx_experiments)\n",
"# we hope this is close to rx_angle = pi\n",
"rpe.robust_phase_estimate([qubit], rx_results)"
"rpe.robust_phase_estimate(rx_results, [qubit])"
]
},
{
Expand Down Expand Up @@ -170,7 +170,7 @@
"rh_results = rpe.acquire_rpe_data(qc, rh_experiments, multiplicative_factor=2)\n",
"\n",
"# the result should be close to our input rh_angle=1.5\n",
"rpe.robust_phase_estimate([qubit], rh_results)"
"rpe.robust_phase_estimate(rh_results, [qubit])"
]
},
{
Expand Down Expand Up @@ -225,8 +225,8 @@
"outputs": [],
"source": [
"# we expect 2 for qubit 0 and pi for qubit 1\n",
"print(rpe.robust_phase_estimate([0], results))\n",
"print(rpe.robust_phase_estimate([1], results))"
"print(rpe.robust_phase_estimate(results, [0]))\n",
"print(rpe.robust_phase_estimate(results, [1]))"
]
},
{
Expand All @@ -243,7 +243,7 @@
"outputs": [],
"source": [
"var = rpe.get_variance_upper_bound(num_depths=6)\n",
"rx_estimate = rpe.robust_phase_estimate([1], results)\n",
"rx_estimate = rpe.robust_phase_estimate(results, [1])\n",
"\n",
"# difference between obs and actual should be less than predicted error \n",
"print(np.abs(rx_estimate - rx_angle), ' <? ', np.sqrt(var))"
Expand Down Expand Up @@ -277,7 +277,7 @@
"\n",
"expts = rpe.generate_rpe_experiments(RZ(angle,q), *args, num_depths=num_depths)\n",
"expt_res = rpe.acquire_rpe_data(qc, expts, multiplicative_factor = 100, additive_error = .1)\n",
"observed = rpe.robust_phase_estimate([q], expt_res)\n",
"observed = rpe.robust_phase_estimate(expt_res, [q])\n",
"print(\"Expected: \", angle)\n",
"print(\"Observed: \", observed)\n",
"\n",
Expand Down Expand Up @@ -331,7 +331,7 @@
"cob = Program() # CZ is diagonal in computational basis, i.e. no need to change basis\n",
"cz_expts = rpe.generate_rpe_experiments(rotation, *rpe.all_eigenvector_prep_meas_settings(qubits, cob), num_depths=7)\n",
"cz_res = rpe.acquire_rpe_data(qc, cz_expts, multiplicative_factor = 50.0, additive_error=.1)\n",
"results = rpe.robust_phase_estimate(qubits, cz_res)\n",
"results = rpe.robust_phase_estimate(cz_res, qubits)\n",
"# we hope to match the ideal results (0, pi, 0, pi)\n",
"print(results)"
]
Expand All @@ -355,7 +355,7 @@
"post_select_args = rpe.pick_two_eigenvecs_prep_meas_settings((fixed_qubit, fixed_qubit_state), free_rotation_qubit)\n",
"cz_single_phase = rpe.generate_rpe_experiments(rotation, *post_select_args, num_depths=7)\n",
"cz_res = rpe.acquire_rpe_data(qc, cz_single_phase, multiplicative_factor = 50.0)\n",
"single_result = rpe.robust_phase_estimate([0, 1], cz_res)\n",
"single_result = rpe.robust_phase_estimate(cz_res, [0, 1])\n",
"# we hope the result is close to pi\n",
"print(single_result)"
]
Expand Down Expand Up @@ -431,7 +431,7 @@
"\n",
"results = []\n",
"for ress in expts_results:\n",
" result = rpe.robust_phase_estimate([q], ress)\n",
" result = rpe.robust_phase_estimate(ress, [q])\n",
" results += [result]\n",
" \n",
"print(\"Expected Alpha: \" + str(alpha))\n",
Expand Down Expand Up @@ -494,7 +494,7 @@
"res = rpe.acquire_rpe_data(qc, expts, multiplicative_factor=5., additive_error=.15)\n",
"\n",
"# we hope this is close to angle=1\n",
"rpe.robust_phase_estimate([q], res)"
"rpe.robust_phase_estimate(res, [q])"
]
},
{
Expand Down Expand Up @@ -522,7 +522,7 @@
"\n",
"decohere_expts = rpe.generate_rpe_experiments(RH, *rpe.all_eigenvector_prep_meas_settings([q], cob), num_depths=7)\n",
"res = rpe.acquire_rpe_data(qc, decohere_expts, multiplicative_factor=5., additive_error=.15)\n",
"rpe.robust_phase_estimate([q], res)"
"rpe.robust_phase_estimate(res, [q])"
]
},
{
Expand Down
5 changes: 4 additions & 1 deletion forest/benchmarking/robust_phase_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def estimate_phase_from_moments(xs: List, ys: List, x_stds: List, y_stds: List,
return theta_est % (2 * pi) # return value between 0 and 2pi


def robust_phase_estimate(qubits: Sequence[int], results: List[List[ExperimentResult]]) \
def robust_phase_estimate(results: List[List[ExperimentResult]], qubits: Sequence[int]) \
-> Union[float, Sequence[float]]:
"""
Provides the estimate of the phase for an RPE experiment with results.
Expand Down Expand Up @@ -591,6 +591,9 @@ def do_rpe(qc: QuantumComputer, rotation: Program, changes_of_basis: List[Progra
rb decay. Each decay should be interpreted as a 'simultaneous rb decay' as the sequences
on each group of qubits will be run concurrently.
:param num_depths: the number of depths in the experiment
:param multiplicative_factor: ad-hoc factor to multiply the number of shots per iteration. See
num_trials() which computes the optimal number of shots per iteration.
:param additive_error: estimate of the max additive error in the experiment, see num_trials()
:param active_reset: Boolean flag indicating whether experiments should begin with an
active reset instruction (this can make the collection of experiments run a lot faster).
:param mitigate_readout_errors: Boolean flag indicating whether bias due to imperfect
Expand Down
2 changes: 1 addition & 1 deletion forest/benchmarking/tests/test_process_tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ def test_do_tomography(qvm):
process = Program(H(qubit))
est, _, _ = do_tomography(qvm, process, qubits=[qubit], kind='process')

np.testing.assert_allclose(est, kraus2choi(mat.H), atol=.01)
np.testing.assert_allclose(est, kraus2choi(mat.H), atol=.1)
4 changes: 2 additions & 2 deletions forest/benchmarking/tests/test_robust_phase_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_noiseless_rpe(qvm):
*rpe.all_eigenvector_prep_meas_settings([q], I(q)),
num_depths=num_depths)
results = rpe.acquire_rpe_data(qvm, expts, multiplicative_factor=mult_factor)
est = rpe.robust_phase_estimate([q], results)
est = rpe.robust_phase_estimate(results, [q])
assert np.abs(angle - est) < 2 * np.sqrt(rpe.get_variance_upper_bound(num_depths, mult_factor))


Expand Down Expand Up @@ -79,7 +79,7 @@ def add_noise_to_experiments(expts, t1, t2, p00, p11, q):
add_noise_to_experiments(expts, 25 * 10 ** (-6.), 20 * 10 ** (-6.), .92, .87, q)
results = rpe.acquire_rpe_data(qvm, expts, multiplicative_factor=5.,
additive_error=add_error)
phase_estimate = rpe.robust_phase_estimate([q], results)
phase_estimate = rpe.robust_phase_estimate(results, [q])
assert np.allclose(phase_estimate, angle, atol=tolerance)


Expand Down

0 comments on commit 14acb19

Please sign in to comment.