def teleport(state, mres): q0, q1 = map(int, twoQ_basis[mres]) s0_name = twoQ_basis[mres] + '0' s1_name = twoQ_basis[mres] + '1' s0 = qt.bra(s0_name) s1 = qt.bra(s1_name) a = (s0 * state).tr() b = (s1 * state).tr() red_state = (a * qt.ket([0], 2) + b * qt.ket([1], 2)).unit() H = Gate('SNOT', targets=0) sqrtX = Gate('SQRTNOT', targets=0) qc = QubitCircuit(N=1) if q1 == 1: qc.add_gate(sqrtX) qc.add_gate(sqrtX) if q0 == 1: qc.add_gate(H) qc.add_gate(sqrtX) qc.add_gate(sqrtX) qc.add_gate(H) gates_sequence = qc.propagators() scheme = oper.gate_sequence_product(gates_sequence) return scheme * red_state
def test_rho_or_sigma_not_oper(self): rho = qutip.bra("00") sigma = qutip.bra("01") with pytest.raises(TypeError) as exc: qutip.entropy_relative(rho.dag(), sigma) assert str(exc.value) == "Inputs must be density matrices." with pytest.raises(TypeError) as exc: qutip.entropy_relative(rho, sigma.dag()) assert str(exc.value) == "Inputs must be density matrices." with pytest.raises(TypeError) as exc: qutip.entropy_relative(rho, sigma) assert str(exc.value) == "Inputs must be density matrices."
def test_bra_type(): "State CSR Type: bra" st = bra('10') assert_equal(isspmatrix_csr(st.data), True)
def quantize_SHO(K, U, p, x, dims=[], taylor_order=4, x0=None, t_symbol=None): """A function that can quantize a sympy hamiltonian. Currently only in SHO/fock basis Parameters ---------- K : sympy expression Sympy expression for the kinetic term U : sympy expression sympy expression for the potential p : iterable of sympy symbols Symbols representing the canonical momenta of the system x : iterable of sympy symbols Symbols representing the canonical position variables of the system dims : list of integers Specifies the desired dimension of each mode. Must be same length as x and p taylor_order : integer Specifies the order to which the taylor expansion will be carried out if the quantization method utilises, such an expansion. x0 : list of floats The point around which the taylor expansion of the potential wil be carried out. Returns ------- operator_generator An operator generator that when called as instance(*params) return the hamiltonian for the system with given params. A parameter is defined as a symbol that appears in K or U but not in x or p. """ # Preliminaries if not dims: dims = len(x) * [4] if x0 == None: x0 = np.zeros(len(x)) # Taylor expansion T_U = au.taylor.taylor_sympy(f=U, x=x, x0=x0, N=taylor_order) T_K = au.taylor.taylor_sympy(f=K, x=p, x0=np.zeros(len(p)), N=2) # Effective mass and "spring constant" m = len(x) * [0] k = len(x) * [0] for coeff, powers in T_K: inds = np.nonzero(np.array(powers) == 2)[0] if len(inds) == 1: m[inds[0]] = 1 / (2 * coeff) for coeff, powers in T_U: inds = np.nonzero(np.array(powers) == 2)[0] if len(inds) == 1: k[inds[0]] = 2 * coeff # Constructing position and momentum operator x_ops = [] p_ops = [] padded_dims = [d + int(np.floor(taylor_order / 2)) for d in dims] for j, d in zip(range(len(k)), padded_dims): op = [qt.qeye(d) for d in padded_dims] op[j] = 1j * (qt.create(d) - qt.destroy(d)) / np.sqrt(2) p_ops.append(qt.tensor(op)) op[j] = (qt.create(d) + qt.destroy(d)) / np.sqrt(2) x_ops.append(qt.tensor(op)) terms = [] # Calculating qutip operator and symbolic coefficient for each term P = 0 # This will be the projection operator that projects onto the subspace defined by dims for state in qt.state_number_enumerate(dims): P += qt.ket(state, dims) * qt.bra(state, padded_dims) for coeff, powers in T_K: op = qt.qeye(padded_dims) for kj, mj, p_op, pow in zip(k, m, p_ops, powers): if pow > 0: coeff *= (kj * mj)**(pow / 4) op *= p_op**pow terms.append((coeff, P * op * P.dag())) for coeff, powers in T_U: op = qt.qeye(padded_dims) for kj, mj, x_op, pow in zip(k, m, x_ops, powers): if pow > 0: coeff *= (kj * mj)**(-pow / 4) op *= x_op**pow terms.append((coeff, P * op * P.dag())) # Constructing opgen instance return au.td_symopgen(sym_terms=terms, t_symbol=t_symbol)
def test_bra_ket(state): from_basis = qutip.basis([2, 2, 2, 2, 2], [1, 1, 0, 0, 0]) from_ket = qutip.ket(state) from_bra = qutip.bra(state).dag() assert from_basis == from_ket assert from_basis == from_bra
def projection_operator(subspace_basis, subspace_dims): d = len(subspace_basis) for j, ket in enumerate(subspace_basis): ket_subspace = qt.basis(d, j) if j == 0: P = ket_subspace * ket.dag() else: P += ket_subspace * ket.dag() P.dims[0] = subspace_dims return P subspace_basis = [qt.ket([0], 3), qt.ket([1], 3)] P = projection_operator(subspace_basis, [2]) U_target = P.dag() * (-1j * qt.sigmax()) * P H = qt.create(3) + qt.destroy(3) + 20 * qt.ket([2], [3]) * qt.bra([2], [3]) def process(rho, tlist): res = qt.mesolve(H, rho, tlist, c_ops=[0.1 * qt.destroy(3)]) return [ transform_state_unitary(rho, U_target, inverse=True) for rho in res.states ] tlist = np.linspace(0, np.pi / 2, 10) F_av = average_fidelity(process, subspace_basis, tlist) print(F_av, '\n') # One qudit with four states [1,2] comp basis subspace_basis = [qt.ket([1], 4), qt.ket([2], 4)]