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_programmatic_name():
"""
Test makes sure that all literals defined in particle.shared_literals
match what is returned by Particle.programmatic_name.
"""
for literal_name, pid in common_particles.items():
if literal_name in ("photon", "proton", "antiproton", "neutron", "antineutron"):
continue
try: # some particles in the literals may not be in the table (e.g the neutrinos as of 2018)
p = Particle.from_pdgid(pid)
assert Particle.from_pdgid(pid).programmatic_name == literal_name
except ParticleNotFound:
pass
def test_programmatic_name():
"""
Test makes sure that all literals defined in particle.shared_literals
match what is returned by Particle.programmatic_name.
"""
for literal_name, pid in common_particles.items():
if literal_name in ("photon", "proton", "antiproton", "neutron", "antineutron"):
continue
try: # some particles in the literals may not be in the table (e.g the neutrinos as of 2018)
p = Particle.from_pdgid(pid)
assert Particle.from_pdgid(pid).programmatic_name == literal_name
except ParticleNotFound:
pass
from particle import Particle
# A subclass of Particle
class CrazyParticle(Particle):
# Just adding one variable to a CrazyParticle.
# It inherits all other fields from "Particle", and we don't have to
# retype them!
# The CrazyParticle constructor can call the parent class (super class)
# constructor.
def __init__(self, l):
# "super" means do everything from the constructor in Particle.
super(CrazyParticle, self).__init__(l)
# One more line of code to deal with the variable, theta.
self.theta = 0.0
# Notice we don't have the method run() here, it is inherited from Particle.
# This update() method overrides the parent class update().
def update(self):
super(CrazyParticle, self).update()
#print map(len, scaffold.border)
self.T = len(self.scaffold.border)
T = self.T
P = self.P
# assert T == 1 # TODO temporary
rhoDBs = [None for t in range(T)]
rhoWeights = [None for t in range(T)]
for t in reversed(range(T)):
rhoWeights[t],rhoDBs[t] = detachAndExtractAtBorder(trace,scaffold.border[t],scaffold)
assertTorus(scaffold)
particles = [Particle(trace) for p in range(P+1)]
self.particles = particles
particleWeights = [None for p in range(P+1)]
# Simulate and calculate initial xiWeights
for p in range(P):
particleWeights[p] = regenAndAttachAtBorder(particles[p],scaffold.border[0],scaffold,False,OmegaDB(),{})
particleWeights[P] = regenAndAttachAtBorder(particles[P],scaffold.border[0],scaffold,True,rhoDBs[0],{})
# assert_almost_equal(particleWeights[P],rhoWeights[0])
# for every time step,
for t in range(1,T):
newParticles = [None for p in range(P+1)]
def __init__(self, x, y, orien, particle_size = 50):
self.world = World()
self.particles = [Particle(x, y, random.random()* 2.*math.pi) for i in xrange(particle_size)]
self.robot = Particle(x, y, orien, is_robot=True)
self.particle_size = particle_size
def __init__(self, num, v, img):
self.particles = [] # Initialize the list.
self.origin = v.get() # Store the origin.
self.img = img
for i in range(num):
# Add "num" amount of particles to the arraylist.
self.particles.append(Particle(self.origin, img))
def f(x):
with fixed_randomness:
scaffold.lkernels[pnode] = DeterministicLKernel(psp,VentureNumber(x))
# The particle is a way to regen without clobbering the underlying trace
# TODO Do repeated regens along the same scaffold actually work?
return regenAndAttach(Particle(trace),scaffold,False,OmegaDB(),{})
return f
def __init__(self, maxParticles=5000):
self.maxParticles = maxParticles
self.curIndex = 0
self.particles = [Particle() for _ in range(self.maxParticles)]
for p in range(P):
particleWeights[p] = regenAndAttachAtBorder(particles[p],scaffold.border[0],scaffold,False,OmegaDB(),{})
particleWeights[P] = regenAndAttachAtBorder(particles[P],scaffold.border[0],scaffold,True,rhoDBs[0],{})
# assert_almost_equal(particleWeights[P],rhoWeights[0])
# for every time step,
for t in range(1,T):
newParticles = [None for p in range(P+1)]
newParticleWeights = [None for p in range(P+1)]
# Sample new particle and propagate
for p in range(P):
parent = sampleLogCategorical(particleWeights)
newParticles[p] = Particle(particles[parent])
newParticleWeights[p] = regenAndAttachAtBorder(newParticles[p],self.scaffold.border[t],self.scaffold,False,OmegaDB(),{})
newParticles[P] = Particle(particles[P])
newParticleWeights[P] = regenAndAttachAtBorder(newParticles[P],self.scaffold.border[t],self.scaffold,True,rhoDBs[t],{})
# assert_almost_equal(newParticleWeights[P],rhoWeights[t])
particles = newParticles
particleWeights = newParticleWeights
# Now sample a NEW particle in proportion to its weight
finalIndex = sampleLogCategorical(particleWeights[0:-1])
assert finalIndex < P
self.finalIndex = finalIndex
self.particles = particles
return particles[finalIndex],self._compute_alpha(particleWeights, finalIndex)
def SpawnParticle(position, colour, life = 2, magnitude = 1, size = 5, angle = None, spread = math.pi / 4, GRAV = 0.25, velocity = None, outline = True):
particles.append(Particle(position, colour, life, magnitude, size, angle, spread, GRAV, velocity, outline));