Skip to content

Make katscript compiler accept python class names for elements and analyses,...

See #554 (closed)

Changes

  • KatScript compiler accepts python class names of elements and commands (mostly camelcase)
  • Renamed the Beamsplitter component to BeamSplitter (since it was not camel case)
  • Added suggestions in the error message for unknown directives (Not technically related but found it useful during testing. Could be removed again.)

Apologies for mixing the beamsplitter rename in the same commit, but relevant changes are in spec.py and compiler.py

Best explained with the test I wrote:

def test_pythonic_names(model):
    """Test that defining elements and analyses via their python class names is
    identical to using their katscript names"""
    m_kat = Model()
    m_pythonic = Model()
    m_kat.parse("""
        laser laser1 P=1
        space s1 laser1.p1 bs1.p1 L=1
        beamsplitter bs1 R=0.5 T=0.5
        pd pow_t bs1.p3.o
    """)
    m_pythonic.parse("""
        Laser laser1 P=1
        Space s1 laser1.p1 bs1.p1 L=1
        Beamsplitter bs1 R=0.5 T=0.5
        PowerDetector pow_t bs1.p3.o
    """)
    assert_models_equivalent(m_kat, m_pythonic)
    out_kat = m_kat.run("xaxis(laser1.P, lin, 0, 1, 10)")
    out_pythonic = m_pythonic.run("Xaxis(laser1.P, lin, 0, 1, 10)")
    np.testing.assert_equal(out_kat.data, out_pythonic.data)
Edited by Miron van der Kolk

Merge request reports