Esempio n. 1
0
 def apply_operator_C2T2(self, operator: sp.Matrix):
     self.swapC2T1()
     I2 = sp.eye(4)
     operator = sp.kronecker_product(I2, operator)
     self._dm = operator @ self.density_matrix() @ operator.adjoint()
     self.swapC2T1()
Esempio n. 2
0
    qc.append(cirq.ZPowGate(exponent=t/π).on(T2))  # Z(t)
    qc.append(U_pi.on(C1,C2,T1,T2))

    # Simulate
    res = sim.simulate(qc,qubit_order=qubit_order)
    print(f'|C1 C2 T1 T2> = |{int(i), int(j), int(k), int(l)}>')
    print(res)

# --- Now with SymPy ---
from sympy_diamond import *
from sympy import *

π = pi

t1, t2, t3, t4 = sympy.symbols('t1 t2 t3 t4', real=True)
Z_C1 = sympy.kronecker_product(U3(0,0,t1), eye(2), eye(2), eye(2))
Z_C2 = sympy.kronecker_product(eye(2), U3(0,0,t2), eye(2), eye(2))
Z_T1 = sympy.kronecker_product(eye(2), eye(2), U3(0,0,t3), eye(2))
Z_T2 = sympy.kronecker_product(eye(2), eye(2), eye(2), U3(0,0,t4))

oper = (U(π) @ Z_T2 @ U(π)).simplify()
print('With sympy')
pprint(oper)

oper = (U(π) @ Z_C1 @ Z_C2 @ Z_T1 @ Z_T2 @ U(π)).simplify()
print('Phases on all qubits:')
pprint(oper)

oper_noU = (Z_C1 @ Z_C2 @ Z_T1 @ Z_T2).simplify()
print('Phases on all qubits (NO U):')
pprint(oper_noU)
Esempio n. 3
0
 def dm_C2T2(self, dm_C2T2):
     self._dm = sp.kronecker_product(self.dm_C1T1, dm_C2T2)
     self.swapC2T1()
π = sp.pi
I = sp.I

I1 = sp.eye(2)

print('--- 1-qubit state creation ---')
s0 = sp.ImmutableDenseMatrix([[1], [0]])
state = s0
a = sp.symbols('a:20')
o1 = U3(a[0], a[1], a[2])
state = o1 @ state
pprint(state)

print('--- Two 1-qubit tensor state creation ---')
s0 = sp.ImmutableDenseMatrix([[1], [0]])
state = sp.kronecker_product(s0, s0)
a = sp.symbols('a:20')
o1 = sp.kronecker_product(U3(a[0], a[1], a[2]), U3(a[3], a[4], a[5]))
state = o1 @ state
pprint(state)

print('--- 2-qubit state preparation ---')
s00 = sp.kronecker_product(s0, s0)
state = s00
a = sp.symbols('a:20')
b = sp.symbols('b:15')
x, y, z = map(sp.Wild, 'xyz')
I_coscos = (z * sp.cos(x) * sp.cos(y), z * (sp.cos(x - y) + sp.cos(x + y)) / 2)
I_sinsin = (z * sp.sin(x) * sp.sin(y), z * (sp.cos(x - y) - sp.cos(x + y)) / 2)
I_sincos = (z * sp.sin(x) * sp.cos(y), z * (sp.sin(x + y) + sp.sin(x - y)) / 2)
I_cossin = (z * sp.cos(x) * sp.sin(y), z * (sp.sin(x + y) - sp.sin(x - y)) / 2)
Esempio n. 5
0
state = sp.ImmutableDenseMatrix([[x1], [x2 * sp.exp(1j * phi2)],
                                 [x3 * sp.exp(1j * phi3)],
                                 [x4 * sp.exp(1j * phi4)]])

ws = sp.symbols('w:2:2', real=True, nonnegative=True)
omegas = sp.symbols('omega:2:2', real=True)
ws_conj = (sp.conjugate(w) for w in ws)
w1, w2, w3, w4 = ws
_, omega2, omega3, omega4 = omegas
init_w_state = sp.ImmutableDenseMatrix([[w1], [w2 * sp.exp(1j * omega2)],
                                        [w3 * sp.exp(1j * omega3)],
                                        [w4 * sp.exp(1j * omega4)]])
xs2_sum = sum([1.0 * xs[i]**2 for i in range(4)])
ws2_sum = sum([1.0 * ws[i]**2 for i in range(4)])

state = sp.kronecker_product(state, init_w_state)
state = swap(4, [1, 2]) @ state
norm_factor = normalization_factor(state)
state2_sum = 1 / norm_factor**2
# state = norm_factor * state
# state = normalize_state(state)
state = Ut @ state
state = state.subs(1.0, 1).expand(basic=True, complex=True).simplify()

dm = density_matrix(
    state)  #.subs(xs[0]*sp.conjugate(xs[0]), sp.abs xs[0].norm()**2)
# Measurement of C2
dm_C2 = partial_trace(dm, 4, [0, 2, 3])
P0_C2 = dm_C2[0, 0].simplify()
P1_C2 = dm_C2[1, 1].simplify()
P01_C2 = (P0_C2 + P1_C2).simplify()
Esempio n. 6
0
import sympy as sp
from sympy.physics.quantum.gate import H
from sympy import pprint
from sympy_diamond import *
from scipy.stats import unitary_group
import  scipy.linalg.special_matrices as sm

sm.

def rand_SU(n):
    unitary_group.rvs(n)

I = sp.I
H = H().get_target_matrix()
HH = sp.kronecker_product(H, H)
a = sp.symbols('a:10')
U3U3 = sp.kronecker_product(U3(a[0], a[1], a[2]), U3(a[3], a[4], a[5]))
pprint(U3U3 @ HH @ s00)
Esempio n. 7
0
def _bitstring_to_sympy_dense_vector(state):
    """Construct sympy matrix representation of a state given by a bitstring."""
    basis = [sympy.Matrix([1, 0]), sympy.Matrix([0, 1])]
    return sympy.kronecker_product(*[basis[bit] for bit in state])