Example #1
0
def check_unitarity(nw):
    with pt.Environment(num_t=1, freqdomain=True):
        nw.initialize()
        I = np.array(np.eye(nw.num_sources) + 0j, dtype=np.complex64)
        T = torch.tensor(np.stack([np.real(I), np.imag(I)], 0), names=["c", "s", "b"])
        R = nw(T, power=False)[:, 0, 0, :, :].data.cpu().numpy()
        R = R[0] + 1j * R[1]
        J = np.dot(R, R.T.conj())
        np.testing.assert_array_almost_equal(I, J)
Example #2
0
def test_agrawal_soa():
    # fmt: off
    # single delay too many in buffermask:
    # target = np.array([0.00000, 0.00814, 0.10276, 0.04285, 0.02142, 0.12841, 0.03331, 0.04192, 0.14501, 0.02096])
    # delay compensated in buffermask:
    target = np.array([
        0.00000, 0.01252, 0.10493, 0.03503, 0.02863, 0.12833, 0.02530, 0.05175,
        0.14189, 0.01401
    ])
    # fmt: on
    with pt.Network() as nw:
        nw.src = pt.Source()
        nw.soa = pt.AgrawalSoa()
        nw.det = pt.Detector()
        nw.link("src:0", "0:soa:1", "0:det")
    env = pt.Environment(dt=6e-13, num_t=150)
    src = torch.tensor(
        0.3 * np.sin(0.0001 * 2 * np.pi * env.t * env.c / env.wl),
        dtype=torch.get_default_dtype(),
    )[:, None, None, None]
    with env:
        det = nw(src)[:, 0, 0, 0].detach().cpu().numpy()
    np.testing.assert_almost_equal(target, det[::15], decimal=5)
Example #3
0
def fenv():
    """ default frequency domain environment """
    return pt.Environment(wl=np.linspace(1.5, 1.6, 100), freqdomain=True)
Example #4
0
def tenv():
    """ default time domain environment """
    return pt.Environment(num_t=7, num_wl=2)
def test_environment_with_many_timesteps():
    env = pt.Environment(t0=0, t1=1e-9, dt=1e-13, f=198e12)
    assert env.num_t == 10000
    assert env.t0 == pytest.approx(0)
    assert env.t1 == pytest.approx(1e-9)
def test_environment_with_many_wavelengths():
    env = pt.Environment(wl0=1500e-9, wl1=1600e-9, num_wl=10000)
    assert env.num_wl == 10000
    assert env.wl0 == pytest.approx(1500e-9)
    assert env.wl1 == pytest.approx(1600e-9)
def test_environment_with_many_frequencies():
    env = pt.Environment(f0=200e12, f1=198e12, num_wl=10000)
    assert env.num_f == 10000
    assert env.f0 == pytest.approx(200e12)
    assert env.f1 == pytest.approx(198e12)
def test_env_copy():
    env1 = pt.Environment(dt=1e-14)
    env2 = env1.copy(dt=1e-16)
    assert env1 is not env2
    assert env1.dt == approx(1e-14)
    assert env2.dt == approx(1e-16)
def test_env_with_extra_arguments_creation():
    env = pt.Environment(test_attribute="hello")
    assert env.test_attribute == "hello"
Example #10
0
def test_env_with_no_delays_creation():
    env = pt.Environment(freqdomain=True)
Example #11
0
def test_env_with_wl_specified_creation():
    env = pt.Environment(wl=1.55e-6)
Example #12
0
def test_env_with_multiple_wavelengths_creation():
    env = pt.Environment(num_wl=3)