Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_driven_tls(datadir):
hs = LocalSpace('tls', basis=('g', 'e'))
w = symbols(r'\omega', real=True)
pi = sympy.pi
cos = sympy.cos
t, T, E0 = symbols('t, T, E_0', real=True)
a = 0.16
blackman = 0.5 * (1 - a - cos(2*pi * t/T) + a*cos(4*pi*t/T))
H0 = Destroy(hs=hs).dag() * Destroy(hs=hs)
H1 = LocalSigma('g', 'e', hs=hs) + LocalSigma('e', 'g', hs=hs)
H = w*H0 + 0.5 * E0 * blackman * H1
circuit = SLH(identity_matrix(0), [], H)
num_vals = {w: 1.0, T:10.0, E0:1.0*2*np.pi}
# test qutip conversion
num_circuit = circuit.substitute(num_vals)
H_qutip, Ls = SLH_to_qutip(num_circuit, time_symbol=t)
assert len(Ls) == 0
assert len(H_qutip) == 3
times = np.linspace(0, num_vals[T], 201)
psi0 = qutip.basis(2, 1)
def rhs(x):
z = pi/2 * (x[0]**2 + x[1]**2 + x[2]**2)
return 2*pi * (1.5 * sin(z) + z * cos(z)) + cos(z)
def primitive_post_shock_conditions(self, freestream_velocity):
wave, wedge = Symbol('wave_angle'), Symbol('wedge_angle')
rho2rho1, p2p1 = Symbol('rho2rho1'), Symbol('p2p1')
M1, gamma = Symbol('M_1'), Symbol('gamma')
free_stream = freestream_velocity
u = (free_stream*cos(0.5*pi - wave)*tan(wave - wedge)/tan(wave)).subs(self.subs_dict).evalf()
v = (free_stream*cos(0.5*pi - wave)/tan(wave)).subs(self.subs_dict).evalf()
u_out = (sqrt(u*u+v*v)*cos(wedge)).subs(self.subs_dict)
v_out = (-1.0*sqrt(u*u+v*v)*sin(wedge)).subs(self.subs_dict)
# Calculate post-shock pressure
# Freestream pressure for this normalisation.
p1 = 1.0/(gamma*M1**2)
p2 = (p2p1*p1).subs(self.subs_dict)
# Calculate post-shock total energy
rho = rho2rho1.subs(self.subs_dict)
print "primitive values post shock: rho, u, v, p"
print rho, u_out, v_out, p2
return [rho, u_out, v_out, p2]
pprint( sin(x)**cos(x) )
print('\n')
pprint( sin(x)/(cos(x)**2 * x**x + (2*y)) )
print('\n')
pprint( sin(x**2 + exp(x)) )
print('\n')
pprint( sqrt(exp(x)) )
print('\n')
pprint( sqrt(sqrt(exp(x))) )
print('\n')
pprint( (1/cos(x)).series(x, 0, 10) )
print('\n')
pprint(a*(KroneckerProduct(b, c)))
print('\n')
def __create_tf_matrix(alpha, a, d, q):
"""Method to calculate transform matrix of Denavit-Hartenberg Method.
Args:
alpha: The twist angle. Axis angle between consecutive two axes.
a: The limb length between consecutive two axis.
d: link offset. The displacement along the same axis.
q: The rotation theta angle about the joint axis.
Returns:
object: The Denavit-Hartenberg transform matrix object.
"""
tf_matrix = Matrix([[cos(q), -sin(q), 0., a],
[sin(q) * cos(alpha), cos(q) * cos(alpha), -sin(alpha), -sin(alpha) * d],
[sin(q) * sin(alpha), cos(q) * sin(alpha), cos(alpha), cos(alpha) * d],
[0., 0., 0., 1.]])
return tf_matrix
def rotation_to_matrix(w):
wx,wy,wz = w
theta = sp.sqrt(wx**2 + wy**2 + wz**2 + wy**2 + wz**2) + EPS
omega = sp.Matrix([[0,-wz,wy],
[wz,0,-wx],
[-wy,wx,0]])
R = sp.eye(3) +\
omega*(sp.sin(theta)/theta) +\
(omega*omega)*((1-sp.cos(theta))/(theta*theta))
return R
if d.is_Relational and isinstance(d, (Ge, Gt)):
d = d.reversedsign
for pat in patterns:
m = d.match(pat)
if m:
break
if m:
if m[q].is_positive and m[w2]/m[p] == pi/2:
d = -re(s + m[w3]) < 0
m = d.match(p - cos(w1*abs(arg(s*w5))*w2)*abs(s**w3)**w4 < 0)
if not m:
m = d.match(
cos(p - abs(arg_(s**w1*w5, q))*w2)*abs(s**w3)**w4 < 0)
if not m:
m = d.match(
p - cos(abs(arg_(polar_lift(s)**w1*w5, q))*w2
)*abs(s**w3)**w4 < 0)
if m and all(m[wild].is_positive for wild in [w1, w2, w3, w4, w5]):
d = re(s) > m[p]
d_ = d.replace(
re, lambda x: x.expand().as_real_imag()[0]).subs(re(s), t)
if not d.is_Relational or \
d.rel_op in ('==', '!=') \
or d_.has(s) or not d_.has(t):
aux_ += [d]
continue
soln = _solve_inequality(d_, t)
if not soln.is_Relational or \
soln.rel_op in ('==', '!='):
aux_ += [d]
continue
if soln.lts == t:
"""Declare the generalized coordinates and their time derivatives.
"""
q_list, qdot_list = gcs(string, number, list)
self.q_list = q_list
self.qdot_list = qdot_list
# Generate lists of Symbol objects instead of Function objects
self.csqrd_dict = {}
self.tan_dict = {}
self.cot_dict = {}
for q in q_list:
self.csqrd_dict[cos(q)**2] = 1 - sin(q)**2
self.tan_dict[sin(q)/cos(q)] = tan(q)
self.cot_dict[cos(q)/sin(q)] = cot(q)
self.q_list_s = [Symbol(str(q.func)) for q in q_list]
sin_q_list = [sin(qs) for qs in self.q_list]
cos_q_list = [cos(qs) for qs in self.q_list]
tan_q_list = [tan(qs) for qs in self.q_list]
trig_q_list = sin_q_list + cos_q_list + tan_q_list
sin_q_list_s = [Symbol('s'+str(qs)[1:]) for qs in self.q_list_s]
cos_q_list_s = [Symbol('c'+str(qs)[1:]) for qs in self.q_list_s]
tan_q_list_s = [Symbol('t'+str(qs)[1:]) for qs in self.q_list_s]
trig_q_list_s = sin_q_list_s + cos_q_list_s + tan_q_list_s
self.qdot_list_s = [Symbol(str(q.func)+'d') for q in q_list]
self.q_list_dict = dict(zip(q_list, self.q_list_s))
self.q_list_dict_back = dict(zip(self.q_list_s, q_list))
trig_q_dict = dict(zip(trig_q_list, trig_q_list_s))
trig_q_dict_back = dict(zip(trig_q_list_s, trig_q_list))
self.qdot_list_dict = dict(zip(qdot_list, self.qdot_list_s))
self.qdot_list_dict_back = dict(zip(self.qdot_list_s, qdot_list))
# Update the comprehensive symbol dictionaries
for d in (self.q_list_dict, self.qdot_list_dict):
Ts = sp.zeros(5)
Td[1,1] = l_1
Ts[1,1] = sp.sin(th_2)
Td[1,2] = l_2
Ts[1,2] = sp.cos(th_3)
Td[2,0] = l_6
Ts[2,0] = l_1*sp.sin(th_1) + l_2*sp.cos(th_1)
Td[2,1] = l_2+5
Ts[2,1] = l_3*sp.cos(th_3) + l_3*sp.sin(th_3) + l_4 # match!!
Td[2,2] = l_2
Ts[2,2] = l_3*sp.cos(th_6) + l_1*sp.sin(th_6) + l_4*sp.sin(th_6)
Td[3,3] = l_2 + l_1
Ts[3,3] = sp.sin(th_3)*sp.sin(th_4) + l_1*sp.cos(th_4) # should only match if test repeats and th_3 becomes known
testm = matrix_equation(Td,Ts)
R.mequation_list = [testm]
uth1 = unknown(th_1)
uth2 = unknown(th_2)
uth3 = unknown(th_3)
uth4 = unknown(th_4)
uth5 = unknown(th_5)
uth6 = unknown(th_6)
variables = [uth1, uth2, uth3, uth4, uth5, uth6]
N3 = tr[z]
N3 = symo.replace(trigsimp(N3), 'N3', qk)
N4 = G[x]**2 + G[y]**2
N4 = symo.replace(trigsimp(N4), 'N4', qk)
a4 = sin(robo.alpha[j])**2
a3 = 2*(sin(robo.alpha[j])**2)*N1
a2 = (sin(robo.alpha[j])**2)*(2*N0 + N1**2) + 4*(robo.d[j]**2)*(N3**2)
a1 = 2*(sin(robo.alpha[j])**2)*N1*N0 + 8*(robo.d[j]**2)*N3*N2
a0 = (sin(robo.alpha[j])**2)*(N0**2) + 4*(robo.d[j]**2)*(N2**2) - 4*(robo.d[j]**2)*(sin(robo.alpha[j])**2)*N4
coef = [a0,a1,a2,a3,a4]
_equation_solve(symo,coef,eq_type,qk,offsetk)
if robo.sigma[k] == 0:
F = tc*cos(qk) + ts*sin(qk) + t1
else:
F = tr*qk + t2
F = symo.replace(trigsimp(F), 'F', qk)
# Solve qj
qj = robo.theta[j]
eq_type = 4
el1 = sin(robo.alpha[j])*F[y]
el2 = sin(robo.alpha[j])*F[x]
el3 = cos(robo.alpha[j])*F[z] - G[z]
el4 = 2*robo.d[j]*F[x]
el5 = -2*robo.d[j]*F[y]
el6 = robo.d[j]**2 + F[x]**2 + F[y]**2 + F[z]**2 - (G[x]**2 + G[y]**2 + G[z]**2)
coef = [el1,el2,el3,el4,el5,el6]
_equation_solve(symo,coef,eq_type,qj,offsetj)