def test_wigner_bell1_su2parity(): """wigner: testing the SU2 parity of the first Bell state. """ psi = bell_state('00') steps = 25 theta = np.tile(np.linspace(0, np.pi, steps), 2).reshape(2, steps) phi = np.tile(np.linspace(0, 2 * np.pi, steps), 2).reshape(2, steps) slicearray = ['l', 'l'] wigner_analyt = np.zeros((steps, steps)) for t in range(steps): for p in range(steps): wigner_analyt[t, p] = np.real( ((1 + np.sqrt(3) * np.cos(theta[0, t])) * (1 + np.sqrt(3) * np.cos(theta[1, t])) + 3 * (np.sin(theta[0, t]) * np.exp(-1j * phi[0, p]) * np.sin(theta[1, t]) * np.exp(-1j * phi[1, p]) + np.sin(theta[0, t]) * np.exp(1j * phi[0, p]) * np.sin(theta[1, t]) * np.exp(1j * phi[1, p])) + (1 - np.sqrt(3) * np.cos(theta[0, t])) * (1 - np.sqrt(3) * np.cos(theta[1, t]))) / 8.) wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray) assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
def test_wigner_bell1_su2parity(): """wigner: testing the SU2 parity of the first Bell state. """ psi = bell_state('00') steps = 25 theta = np.tile(np.linspace(0, np.pi, steps), 2).reshape(2, steps) phi = np.tile(np.linspace(0, 2 * np.pi, steps), 2).reshape(2, steps) slicearray = ['l', 'l'] wigner_analyt = np.zeros((steps, steps)) for t in range(steps): for p in range(steps): wigner_analyt[t, p] = np.real(((1 + np.sqrt(3) * np.cos(theta[0, t])) * (1 + np.sqrt(3) * np.cos(theta[1, t])) + 3 * (np.sin(theta[0, t]) * np.exp(-1j * phi[0, p]) * np.sin(theta[1, t]) * np.exp(-1j * phi[1, p]) + np.sin(theta[0, t]) * np.exp(1j * phi[0, p]) * np.sin(theta[1, t]) * np.exp(1j * phi[1, p])) + (1 - np.sqrt(3) * np.cos(theta[0, t])) * (1 - np.sqrt(3) * np.cos(theta[1, t]))) / 8.) wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray) assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
def test_angle_slicing(): """wigner: tests angle slicing. """ psi1 = bell_state('00') psi2 = bell_state('01') psi3 = bell_state('10') psi4 = bell_state('11') steps = 100 j = 0.5 wigner1 = wigner_transform(psi1, j, False, steps, ['l', 'l']) wigner2 = wigner_transform(psi2, j, False, steps, ['l', 'z']) wigner3 = wigner_transform(psi3, j, False, steps, ['l', 'x']) wigner4 = wigner_transform(psi4, j, False, steps, ['l', 'y']) assert_(np.sum(np.abs(wigner2 - wigner1)) < 1e-11) assert_(np.sum(np.abs(wigner3 - wigner2)) < 1e-11) assert_(np.sum(np.abs(wigner4 - wigner3)) < 1e-11) assert_(np.sum(np.abs(wigner4 - wigner1)) < 1e-11)
def test_wigner_bell4_su2parity(): """wigner: testing the SU2 parity of the fourth Bell state. """ psi = bell_state('11') steps = 100 slicearray = ['l', 'l'] wigner_analyt = np.zeros((steps, steps)) for t in range(steps): for p in range(steps): wigner_analyt[t, p] = -0.5 wigner_theo = wigner_transform(psi, 0.5, False, steps, slicearray) assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-11)
def test_wigner_bell4_fullparity(): """wigner: testing the parity of the fourth Bell state using the parity of the full space. """ psi = bell_state('11') steps = 100 slicearray = ['l', 'l'] wigner_analyt = np.zeros((steps, steps)) for t in range(steps): for p in range(steps): wigner_analyt[t, p] = -0.30901699 print("wigner anal: ", wigner_analyt) wigner_theo = wigner_transform(psi, 0.5, True, steps, slicearray) print("wigner theo: ", wigner_theo) assert_(np.sum(np.abs(wigner_analyt - wigner_theo)) < 1e-4)
import pytest import numpy as np from variational_circuit.measure import * from variational_circuit.vcirc import * from qutip.states import bell_state from qutip.qip.qubits import qubit_states from qutip.metrics import fidelity zero_state = qubit_states(2) zero_qubit = qubit_states(1) bell = bell_state() vc = vcirc(2) def test_add_ansatz(): vc.add_ansatz([0, 0, 0, 0, 0, 0]) vc.add_ansatz([0, 0, 0, 0, 0, 0]) assert vc.structures == [('regular', None, {}), ('regular', None, {})] assert (vc.ansatzes[0].para == np.array([0, 0, 0, 0, 0, 0])).all() assert (vc.ansatzes[1].para == np.array([0, 0, 0, 0, 0, 0])).all() def test_update_circuit(): vc.update_ansatzes([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) assert (vc.ansatzes[0].para == np.array([1, 1, 1, 1, 1, 1])).all() assert (vc.ansatzes[1].para == np.array([1, 1, 1, 1, 1, 1])).all()