From c8f46a71741d7be74bcaeb24c68a32c6abf40c66 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Sat, 28 Mar 2020 10:41:37 +0100 Subject: [PATCH] define common bases --- 10_krisi_3qubits_game.py | 6 +++--- lib.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/10_krisi_3qubits_game.py b/10_krisi_3qubits_game.py index 2a918c9..9f0912a 100644 --- a/10_krisi_3qubits_game.py +++ b/10_krisi_3qubits_game.py @@ -3,7 +3,7 @@ from collections import defaultdict import numpy as np -from lib import State, b_phi_p, b_phi_m, b_psi_p, b_psi_m, s, generate_bins +from lib import State, bell_basis, s, generate_bins def test_krisi_measurement_2(): @@ -33,7 +33,7 @@ def test_krisi_measurement_2(): # Measure in the Bell's basis st = State(q0 * q1) - meas = st.measure(basis=[b_phi_p, b_phi_m, b_psi_p, b_psi_m]) + meas = st.measure(basis=bell_basis) return meas correct = 0 @@ -115,7 +115,7 @@ def test_krisi_measurement_3(): if MEASURE_FIRST_BELL: # Measure in the Bell's basis st = State(q0 * q1) - meas = st.measure(basis=[b_phi_p, b_phi_m, b_psi_p, b_psi_m]) + meas = st.measure(basis=bell_basis) new_st = s("|" + meas + ">") st = State(new_st * q2) else: diff --git a/lib.py b/lib.py index 12f776f..0f69938 100644 --- a/lib.py +++ b/lib.py @@ -393,6 +393,12 @@ class State(Vector): return [x, y, z] +class Ket(State): + def __init__(self, *args, **kwargs): + """Alias: Ket is a state""" + State.__init__(self, *args, **kwargs) + + def test_measure_partial(): state = b_phi_p state.measure_partial(1) @@ -753,6 +759,11 @@ b_psi_m = State([[0], [0]], name="{}-".format(REPR_GREEK_PSI)) +# define common bases: +computational_basis = [_0, _1] +plus_minus_basis = [_p, _m] +bell_basis = [b_phi_p, b_psi_p, b_phi_m, b_psi_m] + well_known_states = [_p, _m, b_phi_p, b_psi_p, b_phi_m, b_psi_m] _ = I = Gate([[1, 0],