Skip to main content

AiiDA Python

Project description

AiiDA Python

This package is an AiiDA plugin allowing you to run python code as CalcJob on a remote computer. Usage is easy one has to inherit CalcJobPython class and instead of prepare_for_submition method one ahs to overload run_python. Parser is generated automatically one does not have to write its own.

from aiida.plugins import CalculationFactory

CalcJobPython = CalculationFactory("aiida_python.calc")

class ClassThatCannotStartWithTestExample(CalcJobPython):

    @classmethod
    def define(cls, spec):
        super().define(spec)

        spec.input('inputarray', valid_type=ArrayData)
        spec.input('repeats', valid_type=Int)
        spec.output('value', valid_type=Float)

    def run_python(self):
        import numpy as np

        a = self.inputs.inputarray
        repeats = self.inputs.repeats
        a_inv = np.linalg.inv(a)

        for ii in range(repeats):
            a_inv = np.matmul(a_inv, a_inv)
            a_inv = a_inv/sum(a_inv)

        a = np.linalg.inv(a)

        c = float(np.sum(a))
        self.outputs.value = c

Here is a test case example

def test_example(aiida_local_code_factory, clear_database):
    from aiida.plugins import CalculationFactory
    from aiida.engine import run
    import numpy as np

    executable = 'python3'
    entry_point = 'test.calc_example'

    code = aiida_local_code_factory(entry_point=entry_point, executable=executable)
    calculation = CalculationFactory(entry_point)

    np_a = np.array([[1,2,1],[3,4,3],[0,1,1]])
    a = ArrayData()
    a.set_array("only_one", np_a)

    inputs = { 'code': code,
               'inputarray': a,
               'repeats': Int(10)}

    result = run(calculation, **inputs)

For more information look at this link.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiida-python-0.0.6.tar.gz (10.0 kB view details)

Uploaded Source

File details

Details for the file aiida-python-0.0.6.tar.gz.

File metadata

  • Download URL: aiida-python-0.0.6.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for aiida-python-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1c366a4d98b2ba185cbb32c8629873e84ec973bba1858bbe3c98218cc14a2b8c
MD5 6fcac778edc97faaa56bc800d9d8e73c
BLAKE2b-256 bc80040f0698f350c732fd23530b750df2be6229e02ba817f8378c42db2e1f0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page