From 5adb4755e6954104445726451737bbdc8f197360 Mon Sep 17 00:00:00 2001 From: Greg Meyer Date: Wed, 4 May 2022 16:49:29 -0700 Subject: [PATCH] change some variable names to match notation in manuscript --- analysis/count_gates.py | 10 ++++----- analysis/error_analysis.py | 42 +++++++++++++++++------------------ circuits/digital_circuits.py | 3 +-- circuits/phase_circuits.py | 6 ++--- tests/check_phase_circuits.py | 4 ++-- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/analysis/count_gates.py b/analysis/count_gates.py index 98c6a5c..a4e461f 100644 --- a/analysis/count_gates.py +++ b/analysis/count_gates.py @@ -40,9 +40,9 @@ def parse_args(): args = p.parse_args() - for m in args.methods: - if m not in all_methods: - raise ValueError(f"unrecognized method '{m}'") + for method in args.methods: + if method not in all_methods: + raise ValueError(f"unrecognized method '{method}'") if args.p == 'depth' and not args.d: raise ValueError("Pass the -d flag to plot circuit depth.") @@ -60,9 +60,9 @@ def describe(c, decompose=True): depth = 0 tot_gates = 0 t_gates = 0 - for m in c: + for moment in c: has_tof = False - for op in m: + for op in moment: if isinstance(op, int): tot_gates += op continue diff --git a/analysis/error_analysis.py b/analysis/error_analysis.py index 7e1d963..ceeb436 100644 --- a/analysis/error_analysis.py +++ b/analysis/error_analysis.py @@ -68,8 +68,8 @@ def test_circuit(circuit, regs, error_rate, iters, p, q, R, factor, fidelity): post_data = { 'total' : 0, 'good_x': 0, - 'good_mz': 0, - 'good_mx': 0, + 'good_chsh_z': 0, + 'good_chsh_x': 0, } all_data = deepcopy(post_data) @@ -125,20 +125,20 @@ def test_circuit(circuit, regs, error_rate, iters, p, q, R, factor, fidelity): d['total'] += 1 if correct: d['good_x'] += 1 # every x case - d['good_mz'] += 1 # Z polarized + d['good_chsh_z'] += 1 # Z polarized else: - d['good_mz'] += 0.5 # Z polarized and lucky + d['good_chsh_z'] += 0.5 # Z polarized and lucky - # finally, handle the case of m branch, X polarized + # finally, handle the case of CHSH branch, X polarized # first case: both y and x were correct! # only possible error is a phase error if n_correct == 2: # either neither flipped, or they both did! if combined_phase == 1: - all_data['good_mx'] += 2 + all_data['good_chsh_x'] += 2 if n_pass == 2: - post_data['good_mx'] += 2 + post_data['good_chsh_x'] += 2 # otherwise, at least one y or x was wrong. in this case we will # never get a correct superposition, and the single-qubit state @@ -148,8 +148,8 @@ def test_circuit(circuit, regs, error_rate, iters, p, q, R, factor, fidelity): # also putting a dent into the probability is the fact that if you # don't provide a valid y you auto-fail. else: - all_data['good_mx'] += n_pass*0.5 - post_data['good_mx'] += n_pass*0.5 + all_data['good_chsh_x'] += n_pass*0.5 + post_data['good_chsh_x'] += n_pass*0.5 bar.update(i+1) @@ -160,13 +160,13 @@ def test_circuit(circuit, regs, error_rate, iters, p, q, R, factor, fidelity): # add measurement factor to the CHSH ones for d in (all_data, post_data): - pz = d['good_mz']/d['total'] - px = d['good_mx']/d['total'] + pz = d['good_chsh_z']/d['total'] + px = d['good_chsh_x']/d['total'] if d is post_data: print() - print(f'Good mz: {pz:0.5f}') - print(f'Good mx: {px:0.5f}') + print(f'Good CHSH z: {pz:0.5f}') + print(f'Good CHSH x: {px:0.5f}') theta = compute_optimal_theta(fidelity, factor) @@ -178,8 +178,8 @@ def test_circuit(circuit, regs, error_rate, iters, p, q, R, factor, fidelity): cz = cos(theta)**2 cx = cos(theta-pi/4)**2 - d['good_m'] = cz*pz + (1-cz)*(1-pz) + cx*px + (1-cx)*(1-px) - d['good_m'] *= d['total']/2 + d['good_chsh'] = cz*pz + (1-cz)*(1-pz) + cx*px + (1-cx)*(1-px) + d['good_chsh'] *= d['total']/2 return all_data, post_data @@ -332,13 +332,13 @@ def main(): def print_results(data, use_stderr=False): - px = data['good_x'] / data['total'] - pm = data['good_m'] / data['total'] - result = px + 4*pm - 4 + p_x = data['good_x'] / data['total'] + p_chsh = data['good_chsh'] / data['total'] + result = p_x + 4*p_chsh - 4 - print(f' px = {px:0.4f}') - print(f' pm = {pm:0.4f}') - print(' px + 4*pm - 4 = ', end='', flush=True) + print(f' p_x = {p_x:0.4f}') + print(f' p_chsh = {p_chsh:0.4f}') + print(' p_x + 4*p_chsh - 4 = ', end='', flush=True) result_str = f'{result:0.4f}' if use_stderr: diff --git a/circuits/digital_circuits.py b/circuits/digital_circuits.py index addbd73..0e447fb 100644 --- a/circuits/digital_circuits.py +++ b/circuits/digital_circuits.py @@ -550,12 +550,11 @@ def montgomery_reduce(T, ancillas, N, mult=None): R = 1 << r _, Np = extended_gcd(R, N) - m = ancillas.new_register(r) - # need to put all the generators in a list so we can return R also ops = [] # m = Np*T + m = ancillas.new_register(r) ops.append(mult(Np, T[:r], m, ancillas, allow_overflow=True, C_zero=True)) # T += Nm diff --git a/circuits/phase_circuits.py b/circuits/phase_circuits.py index d3288e7..186e695 100644 --- a/circuits/phase_circuits.py +++ b/circuits/phase_circuits.py @@ -59,14 +59,14 @@ def x2modN_fast(x, y, ancillas, N): for q in counter: yield cirq.H(q) - for m in range(2*n-1): - qubit_pairs = [(i, m-i) for i in range(max(0, m-n+1), m//2 + 1)] + for l in range(2*n-1): + qubit_pairs = [(i, l-i) for i in range(max(0, l-n+1), l//2 + 1)] yield count(x, counter, qubit_pairs, sign=+1) yield iqft(counter) for k, ck in enumerate(counter): - phase = 2*2**(k+m) / N + phase = 2*2**(k+l) / N yield phase_add(phase, y, [ck]) # uncompute diff --git a/tests/check_phase_circuits.py b/tests/check_phase_circuits.py index aacaac9..8160cda 100644 --- a/tests/check_phase_circuits.py +++ b/tests/check_phase_circuits.py @@ -38,9 +38,9 @@ def parse_args(): def parse_results(results, N, registers): rtn = {} - m = results.state_vector() + result_vec = results.state_vector() - for i,v in enumerate(m): + for i,v in enumerate(result_vec): x, y, anc = idx_to_vals(i, registers) true_y = round(y/(2**len(registers[1])) * N) prob = (v*v.conj()).real