def spin_xyz(spin): if isinstance(spinor, np.ndarray): spinor = qt.Qobj(spinor) j = d_j(spin.shape[0]) return np.array([qt.expect(qt.jmat(j, 'x'), spinor),\ qt.expect(qt.jmat(j, 'y'), spinor),\ qt.expect(qt.jmat(j, 'z'), spinor)])
def __init__(self, dm, pos=[0, 0, 0]): self.pos = vp.vector(*pos) if dm.dims == [[1], [1]]: self.dm = dm z = self.dm.full()[0][0] self.vsphere = vp.sphere(color=vp.color.blue, opacity=dm.norm()/2,\ pos=self.pos) self.vspin_arrow = vp.arrow(pos=self.pos, shaftwidth=0.1, color=vp.color.magenta,\ axis=vp.vector(z.real, z.imag, 0)) else: self.dm = dm.unit() self.sL, self.sV = dm.eigenstates() self.vsphere = vp.sphere(color=vp.color.blue, opacity=dm.norm()/2,\ pos=self.pos) self.colors = [ vp.vector(*np.random.rand(3)) for i in range(len(self.sV)) ] self.vstars = [[vp.sphere(radius=0.2, pos=self.vsphere.pos+vp.vector(*xyz),\ opacity=self.sL[i].real,\ color=self.colors[i]) for xyz in spin_XYZ(v)]\ for i, v in enumerate(self.sV)] self.j = (dm.shape[0] - 1) / 2 self.vspin_arrow = vp.arrow(pos=self.pos, shaftwidth=0.1, color=vp.color.magenta,\ axis=vp.vector(qt.expect(qt.jmat(self.j, 'x'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'y'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'z'), self.dm).real))
def NV_allowed_transitions(ekets,threshold=.001): allowed_transitions=[] for ii in range(len(ekets)): for jj in range (ii+1,len(ekets)): if abs((ekets[ii].dag()*jmat(1,'x')*ekets[jj]).tr())+abs((jmat(1,'x').dag()*jmat(1,'y')*ekets[jj]).tr()) +abs((ekets[ii].dag()*jmat(1,'z')*ekets[jj]).tr())>threshold: allowed_transitions.append([ii,jj]) return allowed_transitions
def test_jmat_12(): spinhalf = qutip.jmat(1 / 2.) paulix = np.array([[0. + 0.j, 1. + 0.j], [1. + 0.j, 0. + 0.j]]) pauliy = np.array([[0. + 0.j, 0. - 1.j], [0. + 1.j, 0. + 0.j]]) pauliz = np.array([[1. + 0.j, 0. + 0.j], [0. + 0.j, -1. + 0.j]]) sigmap = np.array([[0. + 0.j, 1. + 0.j], [0. + 0.j, 0. + 0.j]]) sigmam = np.array([[0. + 0.j, 0. + 0.j], [1. + 0.j, 0. + 0.j]]) np.testing.assert_allclose(spinhalf[0].full() * 2, paulix) np.testing.assert_allclose(spinhalf[1].full() * 2, pauliy) np.testing.assert_allclose(spinhalf[2].full() * 2, pauliz) np.testing.assert_allclose(qutip.jmat(1 / 2., '+').full(), sigmap) np.testing.assert_allclose(qutip.jmat(1 / 2., '-').full(), sigmam) np.testing.assert_allclose(qutip.spin_Jx(1 / 2.).full() * 2, paulix) np.testing.assert_allclose(qutip.spin_Jy(1 / 2.).full() * 2, pauliy) np.testing.assert_allclose(qutip.spin_Jz(1 / 2.).full() * 2, pauliz) np.testing.assert_allclose(qutip.spin_Jp(1 / 2.).full(), sigmap) np.testing.assert_allclose(qutip.spin_Jm(1 / 2.).full(), sigmam) np.testing.assert_allclose(qutip.sigmax().full(), paulix) np.testing.assert_allclose(qutip.sigmay().full(), pauliy) np.testing.assert_allclose(qutip.sigmaz().full(), pauliz) np.testing.assert_allclose(qutip.sigmap().full(), sigmap) np.testing.assert_allclose(qutip.sigmam().full(), sigmam) spin_set = qutip.spin_J_set(0.5) for i in range(3): assert spinhalf[i] == spin_set[i]
def spin_operators(self): spin = (self.n-1.)/2. return {"X": qutip.jmat(spin, "x"),\ "Y": qutip.jmat(spin, "y"),\ "Z": qutip.jmat(spin, "z"),\ "+": qutip.jmat(spin, "+"),\ "-": qutip.jmat(spin, "-")}
def test_jmat_raise(): with pytest.raises(TypeError) as e: qutip.jmat(0.25) assert str(e.value) == 'j must be a non-negative integer or half-integer' with pytest.raises(TypeError) as e: qutip.jmat(0.5, 'zx+') assert str(e.value) == 'Invalid type'
def __init__(self): self.sx = qt.jmat(1, 'x') # spin 1 x operator of nv center self.sy = qt.jmat(1, 'y') # spin 1 y operator of nv center self.sz = qt.jmat(1, 'z') # spin 1 z operator of nv center self.ge = 28e9 # gyromagnetic ratio of nv center self.D = 2.87e9 # zero field splitting energy self.ms0 = 0 # energy (frequency) of ms=0 state. Initialized to 0. It is later changed by the code.
def spin_operators(self): if self.state.value != None: n = len(self.vector.value) spin = (n - 1.) / 2. return {"X": qutip.jmat(spin, "x"),\ "Y": qutip.jmat(spin, "y"),\ "Z": qutip.jmat(spin, "z"),\ "+": qutip.jmat(spin, "+"),\ "-": qutip.jmat(spin, "-")}
def pauli_S1(): '''Return the Pauli spin matrices for S=1''' identity = qutip.qeye(3) sx = qutip.jmat(1,'x') sy = qutip.jmat(1,'y') sz = qutip.jmat(1,'z') szPseudoHalf = qutip.Qobj(-1.0*sz[1:,1:]) # Take the effective two level system bit out of the S1 sz return identity, sx, sy, sz, szPseudoHalf
def dist_pieces_spin(self, pieces): arrows = [] for piece in pieces: j = dim_spin(piece.shape[0]) direction = np.array([qt.expect(qt.jmat(j, "x"), piece).real,\ -1*qt.expect(qt.jmat(j, "y"), piece).real,\ -1*qt.expect(qt.jmat(j, "z"), piece).real]) spin_squared = np.sqrt(np.sum(direction**2)) arrows.append([normalize(direction).tolist(), spin_squared]) return arrows
def P1H(B): P1muB = 0.0280427 / 2. * B A = [0.08133, 0.08133, 0.11403] muBH = tensor( P1muB[0] * sigmax() + P1muB[1] * sigmay() + P1muB[2] * sigmaz(), qeye(3)) ASIH = tensor(sigmax() / 2., A[0] * jmat(1, 'x')) + tensor( sigmay() / 2., A[1] * jmat(1, 'y')) + tensor(sigmaz() / 2., A[2] * jmat(1, 'z')) return muBH + ASIH
def NV_allowed_transitions(ekets, threshold=.001): allowed_transitions = [] for ii in range(len(ekets)): for jj in range(ii + 1, len(ekets)): if abs((ekets[ii].dag() * jmat(1, 'x') * ekets[jj]).tr()) + abs( (jmat(1, 'x').dag() * jmat(1, 'y') * ekets[jj]).tr()) + abs( (ekets[ii].dag() * jmat(1, 'z') * ekets[jj]).tr()) > threshold: allowed_transitions.append([ii, jj]) return allowed_transitions
def NVH(B): m0 = 0.0289 D = 2.873 EE = 0.0043 return D * dot(jmat(1, 'z'), jmat(1, 'z')) + EE * (dot( jmat(1, 'x'), jmat(1, 'x')) - dot(jmat(1, 'y'), jmat(1, 'y'))) + m0 * ( B[0] * jmat(1, 'x') + B[1] * jmat(1, 'y') + B[2] * jmat(1, 'z'))
def pauli_S1(): '''Define pauli spin matrices for spin 1''' identity = qutip.qeye(3) sx = qutip.jmat(1, 'x') sy = qutip.jmat(1, 'y') sz = qutip.jmat(1, 'z') szPseudoHalf = qutip.Qobj( -1.0 * sz[1:, 1:]) # Take the effective two level system bit out of the S1 sz return identity, sx, sy, sz, szPseudoHalf
def __init__(self, D, gamma_e=2.8e6): super().__init__() self.T = None self.D = D self.H0 = (2 * np.pi) * D * qutip.jmat(1, 'z')**2 self.Hi = { 'B' + axis: (2 * np.pi) * gamma_e * qutip.jmat(1, axis) for axis in ['x', 'y', 'z'] } self.labels = ['+1', ' 0', '-1']
def spin_axis(state): n = state.shape[0] spin = (n-1.)/2. if state.isket: state.dims = [[n], [1]] else: state.dims = [[n],[n]] spin_axis = np.array([[qt.expect(qt.jmat(spin,"x"), state)],\ [qt.expect(qt.jmat(spin,"y"), state)],\ [qt.expect(qt.jmat(spin,"z"), state)],\ [qt.expect(qt.identity(n), state)]]) return normalize(spin_axis[:-1])
def simple_check_states_e_ops( self, H, psi0, tlist, tol=1e-5, tol2=1e-4, krylov_dim=25, square_hamiltonian=True, ): """ Compare integrated evolution with sesolve and exactsolve result. """ options = Options(store_states=True) e_ops = [ jmat((H.shape[0] - 1) / 2.0, "x"), jmat((H.shape[0] - 1) / 2.0, "y"), jmat((H.shape[0] - 1) / 2.0, "z"), ] if not square_hamiltonian: _e_ops = [] for op in e_ops: op2 = op.copy() op2.dims = H.dims _e_ops.append(op2) e_ops = _e_ops output = krylovsolve( H, psi0, tlist, krylov_dim, e_ops=e_ops, options=options ) output_ss = sesolve(H, psi0, tlist, e_ops=e_ops, options=options) output_exact = exactsolve(H, psi0, tlist) assert_err_states_less_than_tol(res_1=output, res_2=output_ss, tol=tol) assert_err_states_less_than_tol(res_1=output, res_2=output_exact, tol=tol) # for the operators, test against exactsolve for accuracy for i in range(len(e_ops)): output_exact.expect = expect_value(e_ops[i], output_exact, tlist) assert_err_expect_less_than_tol(exp_1=output.expect[i], exp_2=output_exact.expect, tol=tol)
def __init__(self, spin, center=[0, 0, 0]): self.spin = spin self.j = (self.spin.shape[0] - 1) / 2 self.vcenter = vp.vector(*center) self.vsphere = vp.sphere(pos=self.vcenter, opacity=0.5, color=vp.color.blue) self.vstars = [vp.sphere(pos=self.vsphere.pos+vp.vector(*xyz), radius=0.2)\ for xyz in spin_XYZ(self.spin)] self.X, self.Y, self.Z = qt.jmat(self.j, 'x'), qt.jmat(self.j, 'y'), qt.jmat( self.j, 'z') self.varrow = vp.arrow(pos=self.vcenter, axis=vp.vector(qt.expect(self.X, spin),\ qt.expect(self.Y, spin),\ qt.expect(self.Z, spin)))
def test_jmat_12(): "Spin 1/2 operators" spinhalf = jmat(1 / 2.) paulix = np.array([[0.0 + 0.j, 0.5 + 0.j], [0.5 + 0.j, 0.0 + 0.j]]) pauliy = np.array([[0. + 0.j, 0. - 0.5j], [0. + 0.5j, 0. + 0.j]]) pauliz = np.array([[0.5 + 0.j, 0.0 + 0.j], [0.0 + 0.j, -0.5 + 0.j]]) sigmap = np.array([[0. + 0.j, 1. + 0.j], [0. + 0.j, 0. + 0.j]]) sigmam = np.array([[0. + 0.j, 0. + 0.j], [1. + 0.j, 0. + 0.j]]) assert_equal(np.allclose(spinhalf[0].full(), paulix), True) assert_equal(np.allclose(spinhalf[1].full(), pauliy), True) assert_equal(np.allclose(spinhalf[2].full(), pauliz), True) assert_equal(np.allclose(jmat(1 / 2., '+').full(), sigmap), True) assert_equal(np.allclose(jmat(1 / 2., '-').full(), sigmam), True)
def test_jmat_12(): "Spin 1/2 operators" spinhalf = jmat(1 / 2.) paulix = np.array([[0.0 + 0.j, 0.5 + 0.j], [0.5 + 0.j, 0.0 + 0.j]]) pauliy = np.array([[0. + 0.j, 0. + 0.5j], [0. - 0.5j, 0. + 0.j]]) pauliz = np.array([[0.5 + 0.j, 0.0 + 0.j], [0.0 + 0.j, -0.5 + 0.j]]) sigmap = np.array([[0. + 0.j, 1. + 0.j], [0. + 0.j, 0. + 0.j]]) sigmam = np.array([[0. + 0.j, 0. + 0.j], [1. + 0.j, 0. + 0.j]]) assert_equal(np.allclose(spinhalf[0].full(), paulix), True) assert_equal(np.allclose(spinhalf[1].full(), pauliy), True) assert_equal(np.allclose(spinhalf[2].full(), pauliz), True) assert_equal(np.allclose(jmat(1 / 2., '+').full(), sigmap), True) assert_equal(np.allclose(jmat(1 / 2., '-').full(), sigmam), True)
def distinguishable_collapse(self, i, direction): if self.dimensionality != None: j = dim_spin(self.dimensionality[i]) op = None if direction == "x" or direction == "y" or direction == "z": op = qt.jmat(j, direction) elif direction == "r": op = qt.rand_herm(self.dimensionality[i]) total_op = op if i == 0 else qt.identity(self.dimensionality[0]) for j in range(1, len(self.dimensionality)): if j == i: total_op = qt.tensor(total_op, op) else: total_op = qt.tensor(total_op, qt.identity(self.dimensionality[j])) total_op.dims = [[self.n()], [self.n()]] L, V = total_op.eigenstates() amplitudes = [self.state.overlap(v) for v in V] probabilities = np.array([(a * np.conjugate(a)).real for a in amplitudes]) probabilities = probabilities / probabilities.sum() pick = np.random.choice(list(range(len(V))), 1, p=probabilities)[0] vec = V[pick].full().T[0] projector = qt.Qobj(np.outer(vec, np.conjugate(vec))) self.state = (projector * self.state).unit() self.refresh() return L[pick], L, probabilities
def rotate_component(self, index, pole, dt=0.01, inverse=False, unitary=True): polynomial = self.polynomial() component = polynomial[index] component_xyz = c_xyz(component) component_state = SurfaceXYZ_q([component_xyz]) component_state = evolver(component_state, qt.jmat(0.5, pole), dt=self.dt, inverse=inverse) new_xyz = q_SurfaceXYZ(component_state)[0] new_component = xyz_c(new_xyz) if (new_component != float('Inf')): polynomial[index] = new_component else: return self.state new_vector = polynomial_v(polynomial) #if unitary: self.state = qt.Qobj(new_vector).unit() #else: # self.state = qt.Qobj(new_vector) #print("(") #print(self.state) #print(")") self.refresh() return self.state
def keyboard(event): global A global B global n key = event.key operator = None X, Y, Z = qutip.jmat((n-1.)/2.) if key == "a": #-x for A A.apply(X, True) elif key == "d": #+x for A A.apply(X, False) elif key == "s": #-z for A A.apply(Z, True) elif key == "w": #+z for A A.apply(Z, False) elif key == "z": #-y for A A.apply(Y, True) elif key == "x": #+y for A A.apply(Y, False) elif key == "j": #-x for B B.apply(X, True) elif key == "l": #+x for B B.apply(X, False) elif key == "k": #-z for B B.apply(Z, True) elif key == "i": #+z for B B.apply(Z, False) elif key == "m": #-y for B B.apply(Y, True) elif key == ",": #+y for B B.apply(Y, False)
def update(self, dm): if dm.dims == [[1], [1]]: self.dm = dm z = self.dm.full()[0][0] self.vsphere.opacity = dm.norm() / 2 self.vspin_arrow.axis = vp.vector(z.real, z.imag, 0) else: self.vsphere.opacity = dm.norm() / 2 self.dm = dm.unit() self.sL, self.sV = dm.eigenstates() for i, v in enumerate(self.sV): for j, xyz in enumerate(spin_XYZ(v)): self.vstars[i][j].pos = self.vsphere.pos + vp.vector(*xyz) self.vstars[i][j].opacity = self.sL[i].real self.vspin_arrow.axis = vp.vector(qt.expect(qt.jmat(self.j, 'x'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'y'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'z'), self.dm).real)
def spin_axis(self): spin = (self.n - 1.) / 2. X, Y, Z = qutip.jmat(spin) self.state.dims = [[self.n], [self.n]] spin_axis = [qutip.expect(X, self.state),\ qutip.expect(Y, self.state),\ qutip.expect(Z, self.state)] return spin_axis
def create_test_e_ops(e_ops_type, dim): """Creates e_ops used for testing give H and dim.""" if e_ops_type == "[c]": e_ops = [lambda t, psi: expect(num(dim), psi)] if e_ops_type == "[q]": e_ops = [jmat((dim - 1)/2, "x")] if e_ops_type == "[c, c]": e_ops = [lambda t, psi: expect(num(dim), psi), lambda t, psi: expect(num(dim)/2, psi)] if e_ops_type == "[c, q]": e_ops = [lambda t, psi: expect(num(dim), psi), jmat((dim - 1) / 2.0, "x")] if e_ops_type == "[q, q]": e_ops = [jmat((dim - 1) / 2.0, "x"), jmat((dim - 1) / 2.0, "y"), jmat((dim - 1) / 2.0, "z")] return e_ops
def _convert_local_operator_to_qutip(expr, full_space, mapping): """Convert a LocalOperator instance to qutip.""" n = full_space.dimension if full_space != expr.space: all_spaces = full_space.local_factors own_space_index = all_spaces.index(expr.space) return qutip.tensor( *([qutip.qeye(s.dimension) for s in all_spaces[:own_space_index]] + [convert_to_qutip(expr, expr.space, mapping=mapping)] + [ qutip.qeye(s.dimension) for s in all_spaces[own_space_index + 1:] ])) if isinstance(expr, Create): return qutip.create(n) elif isinstance(expr, Jz): return qutip.jmat((expr.space.dimension - 1) / 2.0, "z") elif isinstance(expr, Jplus): return qutip.jmat((expr.space.dimension - 1) / 2.0, "+") elif isinstance(expr, Jminus): return qutip.jmat((expr.space.dimension - 1) / 2.0, "-") elif isinstance(expr, Destroy): return qutip.destroy(n) elif isinstance(expr, Phase): arg = complex(expr.operands[1]) * arange(n) d = np_cos(arg) + 1j * np_sin(arg) return qutip.Qobj(np_diag(d)) elif isinstance(expr, Displace): alpha = expr.operands[1] return qutip.displace(n, alpha) elif isinstance(expr, Squeeze): eta = expr.operands[1] return qutip.displace(n, eta) elif isinstance(expr, LocalSigma): j = expr.j k = expr.k if isinstance(j, str): j = expr.space.basis_labels.index(j) if isinstance(k, str): k = expr.space.basis_labels.index(k) ket = qutip.basis(n, j) bra = qutip.basis(n, k).dag() return ket * bra else: raise ValueError("Cannot convert '%s' of type %s" % (str(expr), type(expr)))
def paulis(self, reset=False): if self.pure_sphere == None: if self.precalc_paulis == None or reset == True: ops = qt.jmat(self.spin()) eigs = [op.eigenstates() for op in ops] self.precalc_paulis = [ops, eigs] return self.precalc_paulis else: return self.pure_sphere.paulis()
def pauli(spin=0.5): '''Define pauli spin matrices''' ## Spin 1/2 if spin == 0.5: identity = qutip.qeye(2) sx = qutip.sigmax() / 2 sy = qutip.sigmay() / 2 sz = qutip.sigmaz() / 2 ## Spin 1 if spin == 1: identity = qutip.qeye(3) sx = qutip.jmat(1, 'x') sy = qutip.jmat(1, 'y') sz = qutip.jmat(1, 'z') return identity, sx, sy, sz
def make_total_spin(js): ns = [int(2 * j + 1) for j in js] X = [qt.tensor(*[qt.jmat(j, 'x') if k == i else qt.identity(ns[k])\ for k in range(len(js))])\ for i, j in enumerate(js)] Y = [qt.tensor(*[qt.jmat(j, 'y') if k == i else qt.identity(ns[k])\ for k in range(len(js))])\ for i, j in enumerate(js)] Z = [qt.tensor(*[qt.jmat(j, 'z') if k == i else qt.identity(ns[k])\ for k in range(len(js))])\ for i, j in enumerate(js)] X_total = sum(X) Y_total = sum(Y) Z_total = sum(Z) J2 = X_total * X_total + Y_total * Y_total + Z_total * Z_total return X, Y, Z, J2
def spin_axis(self): spin = (self.n - 1.) / 2. X, Y, Z = qutip.jmat(spin) self.state.dims = [[self.n], [1]] spin_axis = np.array([[qt.expect(X, self.state)],\ [qt.expect(Y, self.state)],\ [qt.expect(Z, self.state)],\ [qt.expect(qt.identity(self.n), self.state)]]) return normalize(spin_axis[:-1])
def spin_axis(self): n = 2**self.n_qubits spin = (n - 1.) / 2. X, Y, Z = qutip.jmat(spin) state_copy = self.state.copy() state_copy.dims = [[2**self.n_qubits], [1]] spin_axis = [qutip.expect(X, state_copy),\ qutip.expect(Y, state_copy),\ qutip.expect(Z, state_copy)] return spin_axis
def __init__(self, dm, pos): self.dm = dm self.pos = pos self.sL, self.sV = dm.eigenstates() self.vsphere = vp.sphere(color=vp.color.blue, opacity=0.6,\ pos=self.pos) self.vstars = [[vp.sphere(radius=0.1, pos=self.vsphere.pos+vp.vector(*xyz),\ opacity=self.sL[i].real,\ color=vp.color.hsv_to_rgb(vp.vector(i/len(self.sV),1,1))) for xyz in spin_XYZ(v)]\ for i, v in enumerate(self.sV)] self.j = (dm.shape[0] - 1) / 2 self.vspin_arrow = vp.arrow(color=vp.color.yellow,\ pos=self.pos, shaftwidth=0.05,\ axis=vp.vector(qt.expect(qt.jmat(self.j, 'x'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'y'), self.dm).real,\ qt.expect(qt.jmat(self.j, 'z'), self.dm).real))
def test_jmat_32(): "Spin 3/2 operators" spin32 = jmat(3 / 2.) paulix32 = np.array( [[0.0000000 + 0.j, 0.8660254 + 0.j, 0.0000000 + 0.j, 0.0000000 + 0.j], [0.8660254 + 0.j, 0.0000000 + 0.j, 1.0000000 + 0.j, 0.0000000 + 0.j], [0.0000000 + 0.j, 1.0000000 + 0.j, 0.0000000 + 0.j, 0.8660254 + 0.j], [0.0000000 + 0.j, 0.0000000 + 0.j, 0.8660254 + 0.j, 0.0000000 + 0.j]]) pauliy32 = np.array( [[0. + 0.j, 0. + 0.8660254j, 0. + 0.j, 0. + 0.j], [0. - 0.8660254j, 0. + 0.j, 0. + 1.j, 0. + 0.j], [0. + 0.j, 0. - 1.j, 0. + 0.j, 0. + 0.8660254j], [0. + 0.j, 0. + 0.j, 0. - 0.8660254j, 0. + 0.j]]) pauliz32 = np.array([[1.5 + 0.j, 0.0 + 0.j, 0.0 + 0.j, 0.0 + 0.j], [0.0 + 0.j, 0.5 + 0.j, 0.0 + 0.j, 0.0 + 0.j], [0.0 + 0.j, 0.0 + 0.j, -0.5 + 0.j, 0.0 + 0.j], [0.0 + 0.j, 0.0 + 0.j, 0.0 + 0.j, -1.5 + 0.j]]) assert_equal(np.allclose(spin32[0].full(), paulix32), True) assert_equal(np.allclose(spin32[1].full(), pauliy32), True) assert_equal(np.allclose(spin32[2].full(), pauliz32), True)
import qutip as qt import numpy as np import matplotlib.pyplot as plt import math as mt __author__ = 'Rakshit Jain' I2_x = qt.jmat(1, 'x')/2 I2_y = qt.jmat(1, 'y')/2 I2_z = qt.jmat(1, 'z')/2 I1_x = qt.sigmax()/2 I1_y = qt.sigmay()/2 I1_z = qt.sigmaz()/2 Sx = qt.sigmax()/2 Sy = qt.sigmay()/2 Sz = qt.sigmaz()/2 def Hamiltonian_toymodel(theta, phi): ## Defining Constants omega = 1.4 * 10**6 m_b = 5.7883818066*10**-5 par=m_b*2.417990504024*10**11 # s-1/mT a1 = np.array([-.0989, -.0989, 1.7569]) * par # /mT a2 = np.array([0.0,0.0,1.0812]) * par H_a_zeeman_nt = omega * (Sx * mt.sin(theta) * mt.cos(phi) + Sy * mt.sin(theta) * mt. sin(phi) + Sz * mt.cos(theta)) Ha_zeeman = qt.tensor(H_a_zeeman_nt, qt.identity(3)) H_a_hfi = a1[0] * qt.tensor(Sx, I2_x) + a1[1] * qt.tensor(Sy, I2_y) + a1[2] * qt.tensor(Sz, I2_z)
def test_jmat_42(): "Spin 2 operators" spin42 = jmat(4 / 2., '+') assert_equal(spin42.dims == [[5], [5]], True)
def test_jmat_52(): "Spin 5/2 operators" spin52 = jmat(5 / 2., '+') assert_equal(spin52.shape == [6, 6], True)
def test_jmat_type(): "Operator CSR Type: spin ops" for k in ['x', 'y', 'z', '+', '-']: op = jmat(1/2, k) assert_equal(isspmatrix_csr(op.data), True)
def NVH(B): m0=0.0289 D=2.873 EE=0.0043 return D*dot(jmat(1,'z'),jmat(1,'z'))+EE*(dot(jmat(1,'x'),jmat(1,'x'))-dot(jmat(1,'y'),jmat(1,'y')))+m0*(B[0]*jmat(1,'x')+B[1]*jmat(1,'y')+B[2]*jmat(1,'z'))
def P1H(B): P1muB=0.0280427/2.*B A=[0.08133, 0.08133, 0.11403] muBH=tensor(P1muB[0]*sigmax()+P1muB[1]*sigmay()+P1muB[2]*sigmaz(),qeye(3)) ASIH=tensor(sigmax()/2.,A[0]*jmat(1,'x'))+tensor(sigmay()/2.,A[1]*jmat(1,'y'))+tensor(sigmaz()/2.,A[2]*jmat(1,'z')) return muBH+ASIH
hbar = 1.05457173 * 10 ** (-34) h = hbar * 2 * np.pi mu0 = 4 * np.pi * 10 ** (-7) omega_larmor = -1 * gam_c * B_field tau = analysis.choose_tau_params(64) A, B, r, costheta, sintheta = 59891.5741878, 610776.610967, 6.67885843539e-10, 0.617213399848, 0.786795792469 print A/(2 * np.pi * 1e3), B/(2 * np.pi * 1e3), r # Spin 1/2 states for NV center S0 = qt.basis(2,0) S1 = qt.basis(2,1) # Spin 1/2 operators for c13 Ii = qt.qeye(2) Ix = qt.jmat(.5, 'x') Iy = qt.jmat(.5, 'y') Iz = qt.jmat(.5, 'z') # Hamiltonian in angular frequency units H = qt.tensor(S0 * S0.dag(), omega_larmor * Iz) + qt.tensor(S1 * S1.dag(), (A + omega_larmor) * Iz + B * Ix) # Pi pulse on NV spin between ms = 0 and ms = 1 states # I'm still assuming this is "infinitely" fast, only involves the NV, and is a complete population inversion # because I don't know what hamiltonian to use realistically for the microwave field pi_pulse = qt.tensor(-1j * qt.sigmax(), Ii) analytical_P = .5 * (1+analysis.calc_M_single(A, B, 64, omega_larmor, tau)) displayed_inds = np.where(np.logical_and(tau>=3*1e-6, tau<=5*1e-6))[0] res_ind = displayed_inds[np.argmin(analytical_P[displayed_inds])] t_step = tau[100]-tau[99]