Skip to content

Commit

Permalink
change some variable names to match notation in manuscript
Browse files Browse the repository at this point in the history
  • Loading branch information
GregDMeyer committed May 4, 2022
1 parent 3155c5a commit 5adb475
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
10 changes: 5 additions & 5 deletions analysis/count_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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
Expand Down
42 changes: 21 additions & 21 deletions analysis/error_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions circuits/digital_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions circuits/phase_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/check_phase_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5adb475

Please sign in to comment.