C-Accel-CRIPT / sdk-archive

CRIPT Python SDK
MIT License
11 stars 0 forks source link

Adding computation with Algorithms #63

Closed InnocentBug closed 1 year ago

InnocentBug commented 1 year ago

Adding a software with algorithms does not work.

This code:

    host = "criptapp.org"
    token = argv[0]
    cript.API(host, token)

    proj = cript.Project.get(name="Monomeric sidechain dipole orientation and its effect on microphase separation: experiment and simulation via structural isomer variation")

    coll = cript.Collection.get(name="3-mer simulations")

    try:
        expt = cript.Experiment.get(name="testasdf")
    except ValueError as e:
        expt = cript.Experiment(collection=coll, name="testasdf")
        expt.save()

    try:
        packmol = cript.Software.get(name = "Packmol", source = "http://m3g.iqm.unicamp.br/packmol", version = None)
    except ValueError:
        packmol = cript.Software(name = "Packmol", source = "http://m3g.iqm.unicamp.br/packmol", version = None, group=proj.group)
        packmol.save()

    alg = cript.Algorithm(key="MD", type="initialization",parameters = [
        cript.Parameter(key="+maxit", value=50),
        cript.Parameter(key="+nloop", value=10),
        cript.Parameter(key="+tolerance", value=4.0, unit="angstrom"),
    ])
    packmol_config = cript.SoftwareConfiguration(software = packmol )
    packmol_config.add_algorithm(alg)

    try:
        init = cript.Computation.get(name="Test Comp")
    except ValueError:
        init = cript.Computation.create(experiment=expt, name="Test Comp", type="initialization")
        init.save()
    init.add_software_configuration(packmol_config)
    init.save()

Errors with:

Traceback (most recent call last):
  File "/media/data/elwood/chimad/hongbo4/la.py", line 48, in <module>
    main(sys.argv[1:])
  File "/media/data/elwood/chimad/hongbo4/la.py", line 44, in main
    init.save()
  File "<@beartype(cript.data_model.nodes.base_node.BaseNode.save) at 0x7faae0d100d0>", line 47, in save
  File "/home/ludwig/.local/lib/python3.9/site-packages/cript/data_model/nodes/base_node.py", line 81, in save
    self._generate_nested_nodes(get_level=get_level)
  File "/home/ludwig/.local/lib/python3.9/site-packages/cript/data_model/base.py", line 134, in _generate_nested_nodes
    subobject = node_class(**value[i])
  File "<@beartype(cript.data_model.subobjects.software_configuration.SoftwareConfiguration.__init__) at 0x7faae0673e50>", line 117, in __init__
TypeError: __init__() missing 1 required positional argument: 'software'

Note, that not adding the algorithm with line:

 packmol_config.add_algorithm(alg)

The code works just fine.

InnocentBug commented 1 year ago

This might be related to #50

InnocentBug commented 1 year ago

Ok, I figured it out. But yes, the error message handling is a problem. The error message exists (it is in value[i] of base._generate_nested_nodes), but it is not displayed to the user. So a better error handling with message could improve this dramatically.

For anyone interested. Fixing the algorithm vocab was key here.

    token = argv[0]
    cript.API(host, token)

    proj = cript.Project.get(name="Monomeric sidechain dipole orientation and its effect on microphase separation: experiment and simulation via structural isomer variation")

    coll = cript.Collection.get(name="3-mer simulations")

    try:
        expt = cript.Experiment.get(name="testasdf")
    except ValueError as e:
        expt = cript.Experiment(collection=coll, name="testasdf")
        expt.save()

    try:
        packmol = cript.Software.get(name = "Packmol", source = "http://m3g.iqm.unicamp.br/packmol", version = None)
    except ValueError:
        packmol = cript.Software(name = "Packmol", source = "http://m3g.iqm.unicamp.br/packmol", version = None, group=proj.group)
        packmol.save()

    alg = cript.Algorithm(key="DPD", type="initialization",parameters = [
        cript.Parameter(key="update_frequency", value=50, unit="1/s")])
    packmol_config = cript.SoftwareConfiguration(software = packmol )
    packmol_config.add_algorithm(alg)

    try:
        init = cript.Computation.get(name="Test Comp")
    except ValueError:
        init = cript.Computation.create(experiment=expt, name="Test Comp", type="initialization")
        init.save()
    init.add_software_configuration(packmol_config)
    init.save()