multi-pbar threading
This commit is contained in:
0
examples/Optica_PM2000D/Optica_PM2000D.toml
Executable file → Normal file
0
examples/Optica_PM2000D/Optica_PM2000D.toml
Executable file → Normal file
0
examples/Travers/Travers.toml
Executable file → Normal file
0
examples/Travers/Travers.toml
Executable file → Normal file
@@ -31,6 +31,22 @@ def propagate_all(n):
|
||||
return spec, props
|
||||
|
||||
|
||||
def quick_test():
|
||||
t = sc.tspace(dt=1e-15, t_num=2048)
|
||||
spec_0 = np.fft.fft(10e3 * np.exp(-((t / 70e-15) ** 2)))
|
||||
spec = sc.Spectrum(
|
||||
[np.exp(2j * np.pi * np.random.rand()) + spec_0 for _ in range(20)],
|
||||
sc.wspace(t) + sc.units.nm_rads(800),
|
||||
t,
|
||||
)
|
||||
_, (top, bot) = plt.subplots(2, 1, constrained_layout=True, height_ratios=[1, 5], sharex=True)
|
||||
bot.plot(spec.wl_disp * 1e9, spec[0].wl_int)
|
||||
top.plot(spec.wl_disp * 1e9, spec.coherence())
|
||||
top.set_xlim(750, 850)
|
||||
bot.set_yscale("log")
|
||||
plt.show()
|
||||
|
||||
|
||||
def main():
|
||||
n = 1
|
||||
spec, props = propagate_all(n)
|
||||
@@ -52,4 +68,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
quick_test()
|
||||
# main()
|
||||
|
||||
22
examples/show_multi_bar.py
Normal file
22
examples/show_multi_bar.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import random
|
||||
import time
|
||||
|
||||
import scgenerator as sc
|
||||
|
||||
SIZE = 100
|
||||
|
||||
|
||||
def compute_stuff(num: int, pbar: sc.threading.Multibar):
|
||||
speed = random.random() * 5
|
||||
for i in pbar(range(SIZE), desc=f"num {num}"):
|
||||
time.sleep(0.05 * speed * random.random())
|
||||
if random.random() > 0.98:
|
||||
print(f"some text {i}")
|
||||
|
||||
|
||||
def main():
|
||||
sc.threading.apply_with_progress(compute_stuff, range(12), n_cpu=4, unpack=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user