Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRIPT Python SDK 2.0 First Release #272

Merged
merged 240 commits into from
Aug 12, 2023
Merged

CRIPT Python SDK 2.0 First Release #272

merged 240 commits into from
Aug 12, 2023

Conversation

nh916
Copy link
Contributor

@nh916 nh916 commented Aug 12, 2023

No description provided.

* added CRIPT logo
* updated python badge to python 3.7 instead of python 3.9
* added a section that "we invite contribution"
ignoring common files and directories that are unneeded
added mypy cache to be ignored
brought it over from the old sdk docs
Create pull_request_template.md
moved pyproject.toml from src/ to the project root directory
* file.py
* group.py
* user.py
nh916 and others added 19 commits August 2, 2023 16:30
* changed conftest.py to get storage token from env variable

* updated CI to have `CRIPT_STORAGE_TOKEN`

* updated CI to have `CRIPT_STORAGE_TOKEN`
* wrote docs for `load_nodes_from_json`

* update docs for `load_nodes_from_json`

* added type hinting to `load_nodes_from_json`

* update `load_nodes_from_json` function to work correctly without errors

* updated docs fore `load_from_json` return type

* updated docs fore `load_from_json` return type

* optimized imports
* added documentation for `_NodeDecoderHook`

* fixed `_NodeDecoderHook` `def __init__()` notes

* fixed `_NodeDecoderHook` `def __call__()` returns documentation
* simplified tests and got rid of `deep_copy`

* optimized imports

* passed tests
adding `None` in header escapes the html and looks weird on the right side navigation
* updated tests for staging

* trunk spelling

---------

Co-authored-by: Ludwig Schneider <ludwigschneider@uchicago.edu>
* wrote documentation for `NodeEncoder`

* updated documentation for `NodeEncoder`

* updated documentation for `NodeEncoder`

* formatted with black

* added typing for mypy

* formatted with trunk

* ignoring mypy static type error

* updated documentation return type

* formatted with black

* adjust type description for condense_uuid

---------

Co-authored-by: Ludwig Schneider <ludwigschneider@uchicago.edu>
* add default args to JSON if not present

* fix collection integration, by surpressing the right default args in JSON

* trunk fixes

* found some more

* adjust tests

* missing test fix
* change the representation of UID

* fix the two tests that were missing

* this should work now

* missing test fix

* conftest get integration test var from env var with exception handling (#253)

* updated CI to have `CRIPT_STORAGE_TOKEN`

* if no env var then integration tests are true

* pass empty identifier list too

* uuidfy experiment/data

* thx mypy

---------

Co-authored-by: nh916 <navidhariri25@gmail.com>
@trunk-io
Copy link

trunk-io bot commented Aug 12, 2023

Merging to develop in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@bearmit
Copy link

bearmit commented Aug 12, 2023

I'm following the instructions from https://c-accel-cript.github.io/Python-SDK/tutorial/cript_installation_guide/

Installing the package like that:
pip install git+https://github.com/C-Accel-CRIPT/Python-SDK@develop

Win11, Python 3.10.6

Install went well.

Now following https://c-accel-cript.github.io/Python-SDK/tutorial/how_to_get_api_token/

Not clear where I should paste my tokens, but I assume I need to create a *.py script file.

image

Now following https://c-accel-cript.github.io/Python-SDK/examples/synthesis/

I successfully setup my script to create a new project

(venv) PS C:\Users\berenger\sdktest> python synthesis.py
INFO: Validating Project graph...
(venv) PS C:\Users\berenger\sdktest>

I copy/pasted all the instructions, the project was generated but rejected by the server because of duplicates. My project name was changed, but I assume there are duplicates in the materials (maybe on experiments too).

Not easy to guess which node has a duplicate name, I assume this will happend to every user trying this.

The log looks like:

INFO: Validating Project graph...
Traceback (most recent call last):
  File "C:\Users\berenger\sdktest\synthesis.py", line 115, in <module>
    api.save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 625, in save
    raise exc from exc
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 619, in save
    self._internal_save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 706, in _internal_save
    raise CRIPTAPISaveError(api_host_domain=self._host, http_code=response["code"], api_response=response["error"], patch_request=patch_request, pre_saved_nodes=save_values.saved_uuid, json_data=json_data)  # type: ignore
cript.api.exceptions.CRIPTAPISaveError: API responded to POST with 'http:400 Duplicate names                          ['Anionic Polymerization of Styrene with SecBuLi'] in Experiment' data: {"node": ["Project"], "uid": "_:e0f40836-c32c-4ef3-b197-31204285cd05", "uuid": "e0f40836-c32c-4ef3-b197-31204285cd05", "name": "My first project created with the WebSDK develop", "collection": [{"node": ["Collection"], "uid": "_:2022575c-6275-49ab-bf01-0a1b381d82b0", "uuid": "2022575c-6275-49ab-bf01-0a1b381d82b0", "name": "Initial screening", "experiment": [{"node": ["Experiment"], "uid": "_:1d9a45a5-9996-487b-a007-998703454ec6", "uuid": "1d9a45a5-9996-487b-a007-998703454ec6", "name": "Anionic Polymerization of Styrene with SecBuLi"}, {"node": ["Experiment"], "uid": "_:5f53560e-1eb2-494c-b67e-b1d271a78625", "uuid": "5f53560e-1eb2-494c-b67e-b1d271a78625", "name": "Anionic Polymerization of Styrene with SecBuLi", "process": [{"node": ["Process"], "uid": "_:4ef58d70-815a-4780-8751-6c6587ae32ff", "uuid": "4ef58d70-815a-4780-8751-6c6587ae32ff", "name": "Anionic of Synthesis Poly-Styrene", "type": "multistep", "ingredient": [{"node": ["Ingredient"], "uid": "_:ecad3b35-26d3-4118-b490-bca7a396d5a8", "uuid": "ecad3b35-26d3-4118-b490-bca7a396d5a8", "material": {"uuid": "e52d861c-ccc2-42c6-a9c4-054847769e05"}, "quantity": [{"node": ["Quantity"], "uid": "_:4ed7c6b4-11cc-4f50-9efa-c27c7ed0a7f3", "uuid": "4ed7c6b4-11cc-4f50-9efa-c27c7ed0a7f3", "key": "volume", "value": 1.7e-08, "unit": "m**3"}], "keyword": ["initiator"]}, {"node": ["Ingredient"], "uid": "_:3283e47c-72f2-428a-a3db-8477e7754198", "uuid": "3283e47c-72f2-428a-a3db-8477e7754198", "material": {"uuid": "9ac2bb9d-3b24-42e6-833b-16d05f235273"}, "quantity": [{"node": ["Quantity"], "uid": "_:23b1f6e8-e295-4932-94c6-45effb2d68e2", "uuid": "23b1f6e8-e295-4932-94c6-45effb2d68e2", "key": "volume", "value": 0.0001, "unit": "m**3"}], "keyword": ["solvent"]}, {"node": ["Ingredient"], "uid": "_:d70ac8bb-c61f-4f30-815e-2ede3df98881", "uuid": "d70ac8bb-c61f-4f30-815e-2ede3df98881", "material": {"uuid": "a58cec1f-94b6-45f9-aca0-79e5893ba12d"}, "quantity": [{"node": ["Quantity"], "uid": "_:4a1ce7ed-b532-444f-939f-7547ae67b99a", "uuid": "4a1ce7ed-b532-444f-939f-7547ae67b99a", "key": "mass", "value": 0.000455, "unit": "kg"}], "keyword": ["monomer"]}, {"node": ["Ingredient"], "uid": "_:c71bf34b-c49d-4532-8b68-8ff19058c7fe", "uuid": "c71bf34b-c49d-4532-8b68-8ff19058c7fe", "material": {"uuid": "4ec8e732-5dec-440b-a752-d5096e5224bb"}, "quantity": [{"node": ["Quantity"], "uid": "_:f6f8d8a6-b3f8-40ab-be81-e3563e1d6256", "uuid": "f6f8d8a6-b3f8-40ab-be81-e3563e1d6256", "key": "volume", "value": 0.005, "unit": "m**3"}], "keyword": ["quench"]}, {"node": ["Ingredient"], "uid": "_:bea6caa7-0a1b-4588-96ff-751852bdd09b", "uuid": "bea6caa7-0a1b-4588-96ff-751852bdd09b", "material": {"uuid": "56ab0d1a-fcb7-44a2-a61c-b52a341236c4"}, "quantity": [{"node": ["Quantity"], "uid": "_:08423765-085f-4fba-9b85-f05688a86502", "uuid": "08423765-085f-4fba-9b85-f05688a86502", "key": "volume", "value": 0.1, "unit": "m**3"}], "keyword": ["workup"]}], "description": "In an argon filled glove box, a round bottom flask was filled with 216 ml of dried toluene. The solution of secBuLi (3 ml, 3.9 mmol) was added next, followed by styrene (22.3 g, 176 mmol) to initiate the polymerization. The reaction mixture immediately turned orange. After 30 min, the reaction was quenched with the addition of 3 ml of methanol. The polymer was isolated by precipitation in methanol 3 times and dried under vacuum.", "condition": [{"node": ["Condition"], "uid": "_:5b5f69de-12eb-4fda-85aa-32216b690f6d", "uuid": "5b5f69de-12eb-4fda-85aa-32216b690f6d", "key": "temperature", "type": "value", "value": 25, "unit": "celsius"}, {"node": ["Condition"], "uid": "_:e446ae2a-3b51-42a6-9512-b0dec166d617", "uuid": "e446ae2a-3b51-42a6-9512-b0dec166d617", "key": "time_duration", "type": "value", "value": 60, "unit": "min"}], "property": [{"node": ["Property"], "uid": "_:778e5096-e98d-4bd5-b4cf-f55405378e63", "uuid": "778e5096-e98d-4bd5-b4cf-f55405378e63", "key": "yield_mass", "type": "number", "value": 0.00047, "unit": "kilogram", "method": "scale"}]}]}], "inventory": [{"node": ["Inventory"], "uid": "_:7e4c4ee3-4dfe-4a6a-ace2-028180b95f22", "uuid": "7e4c4ee3-4dfe-4a6a-ace2-028180b95f22", "name": "Common chemicals for poly-styrene synthesis", "material": [{"uuid": "e52d861c-ccc2-42c6-a9c4-054847769e05"}, {"uuid": "9ac2bb9d-3b24-42e6-833b-16d05f235273"}, {"uuid": "a58cec1f-94b6-45f9-aca0-79e5893ba12d"}, {"uuid": "4ec8e732-5dec-440b-a752-d5096e5224bb"}, {"uuid": "56ab0d1a-fcb7-44a2-a61c-b52a341236c4"}]}]}], "material": [{"node": ["Material"], "uid": "_:ac8f953c-6d85-4544-9a4e-d10f87a4f28d", "uuid": "ac8f953c-6d85-4544-9a4e-d10f87a4f28d", "name": "polystyrene", "property": [{"node": ["Property"], "uid": "_:838158e7-b66f-4672-aa59-fa67bbf6d82c", "uuid": "838158e7-b66f-4672-aa59-fa67bbf6d82c", "key": "phase", "type": "none", "value": "solid", "unit": null}, {"node": ["Property"], "uid": "_:f752eceb-d7fc-46db-8f75-b91692f215f9", "uuid": "f752eceb-d7fc-46db-8f75-b91692f215f9", "key": "color", "type": "none", "value": "white", "unit": null}], "names": ["poly(styrene)", "poly(vinylbenzene)"], "bigsmiles": "[H]{[>][<]C(C[>])c1ccccc1[<]}C(C)CC", "chem_repeat": ["C8H8"]}]}
(venv) PS C:\Users\berenger\sdktest>

I suggest to define a global a prefix (or suffix) by doing let's say:
api.set_global_(suffix|prefix)("mySuperTest - ")

...or to display the list of duplicates.

My bad, I added two identical Experiments, I figured it out when adding a prefix manually replacing name=" by "name="SDKTestBerenger -

FName are fixed, but I got now an error regarding MaterialPost additionalProperties:

Traceback (most recent call last):
  File "C:\Users\berenger\sdktest\synthesis.py", line 112, in <module>
    api.save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 619, in save
    self._internal_save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 684, in _internal_save
    returned_save_values = _fix_node_save(self, node, response, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\utils\save_helper.py", line 77, in _fix_node_save
    returned_save_values = api._internal_save(missing_node, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 645, in _internal_save
    node.validate()
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\nodes\core.py", line 157, in validate
    api._is_node_schema_valid(self.get_json(is_patch=is_patch).json, is_patch=is_patch)
  File "<@beartype(cript.api.api.API._is_node_schema_valid) at 0x25e3b1fb010>", line 50, in _is_node_schema_valid
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 591, in _is_node_schema_valid
    raise CRIPTNodeSchemaError(node_type=node_dict["node"], json_schema_validation_error=str(error)) from error
cript.nodes.exceptions.CRIPTNodeSchemaError: JSON database schema validation for node ['Material'] failed.Error: Additional properties are not allowed ('pubchem_id' was unexpected)

Failed validating 'additionalProperties' in schema:
    {'$id': 'MaterialPost',
     'additionalProperties': False,
     'properties': {'amino_acid': {'type': 'string'},
                    'bigsmiles': {'type': 'string'},
                    'chem_formula': {'type': 'string'},
                    'chem_repeat': {'items': {'type': 'string'},
                                    'type': 'array'},
                    'chemical_id': {'type': 'string'},
                    'component': {'items': {'anyOf': [{'$ref': 'EdgeUUID'},
                                                      {'$ref': 'Edge'}]},
                                  'type': 'array'},
                    'computational_forcefield': {'anyOf': [{'$ref': 'EdgeUUID'},
                                                           {'$ref': 'ComputationalForcefieldPost'},
                                                           {'$ref': 'Edge'}]},
                    'created_at': {'$ref': 'Timestamp'},
                    'created_by': {'$ref': 'Creator'},
                    'inchi': {'type': 'string'},
                    'inchi_key': {'type': 'string'},
                    'keyword': {'$ref': 'MaterialKeyword'},
                    'locked': {'default': False, 'type': 'boolean'},
                    'lot_number': {'type': 'string'},
                    'model_version': {'$ref': 'ModelVersion'},
                    'mol_form': {'type': 'string'},
                    'name': {'$ref': 'NameField'},
                    'names': {'items': {'type': 'string'}, 'type': 'array'},
                    'node': {'items': {'enum': ['Material'],
                                       'type': 'string'},
                             'type': 'array'},
                    'notes': {'$ref': 'NotesField'},
                    'parent_material': {'anyOf': [{'$ref': 'EdgeUUID'},
                                                  {'$ref': 'Edge'}]},
                    'process': {'anyOf': [{'$ref': 'EdgeUUID'},
                                          {'$ref': 'ProcessPost'},
                                          {'$ref': 'Edge'}]},
                    'property': {'items': {'anyOf': [{'$ref': 'EdgeUUID'},
                                                     {'$ref': 'PropertyPost'}]},
                                 'type': 'array'},
                    'pubchem_cid': {'type': 'integer'},
                    'public': {'default': False, 'type': 'boolean'},
                    'smiles': {'type': 'string'},
                    'uid': {'$ref': 'TempUID'},
                    'updated_at': {'$ref': 'Timestamp'},
                    'updated_by': {'$ref': 'Creator'},
                    'uuid': {'default': 'uuid()',
                             'readOnly': True,
                             'type': 'string'},
                    'vendor': {'type': 'string'}},
     'required': ['node', 'name'],
     'type': 'object'}

On instance:
    {'name': 'SDKTestBerenger - toluene',
     'node': ['Material'],
     'pubchem_id': 1140,
     'smiles': 'Cc1ccccc1',
     'uid': '_:f982cc4c-4070-4e67-9121-26b9dd56f83d',
     'uuid': 'f982cc4c-4070-4e67-9121-26b9dd56f83d'}

I assume there is a typo in the documentation, and pubchem_cid should have been defined instead of pubchem_id.

Retrying... I assumed well, no more issue with pubchem_id.

But, I got another issue:

INFO: Validating Project graph...
INFO: Validating Material graph...
INFO: Validating Material graph...
Traceback (most recent call last):
  File "C:\Users\berenger\sdktest\synthesis.py", line 112, in <module>
    api.save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 625, in save
    raise exc from exc
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 619, in save
    self._internal_save(project)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 684, in _internal_save
    returned_save_values = _fix_node_save(self, node, response, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\utils\save_helper.py", line 77, in _fix_node_save
    returned_save_values = api._internal_save(missing_node, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 684, in _internal_save
    returned_save_values = _fix_node_save(self, node, response, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\utils\save_helper.py", line 104, in _fix_node_save
    save_values += api._internal_save(duplicate_node, save_values)
  File "C:\Users\berenger\sdktest\venv\lib\site-packages\cript\api\api.py", line 706, in _internal_save
    raise CRIPTAPISaveError(api_host_domain=self._host, http_code=response["code"], api_response=response["error"], patch_request=patch_request, pre_saved_nodes=save_values.saved_uuid, json_data=json_data)  # type: ignore
cript.api.exceptions.CRIPTAPISaveError: API responded to POST with 'http:400 'name' is a required property at path: /' data: {"node": ["Material"], "uid": "_:061d7a40-1f1f-46c4-91f5-512a65a95895", "uuid": "061d7a40-1f1f-46c4-91f5-512a65a95895", "chemical_id": "598-30-1"}

Apparently the name is missing on the material.

After searching for cript.Material( I can confirm there is no unnammed material in the code. I am not sure what's the problem...

To be continued...

Copy link

@bearmit bearmit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why, but I couldn't finish the walkthrough: https://c-accel-cript.github.io/Python-SDK/examples/synthesis/

The last error I got was not related to my data I think. It's like a node with a uuid was trying to be posted without a name. See my comments above this.

@InnocentBug
Copy link
Collaborator

I am not sure why, but I couldn't finish the walkthrough: https://c-accel-cript.github.io/Python-SDK/examples/synthesis/

The last error I got was not related to my data I think. It's like a node with a uuid was trying to be posted without a name. See my comments above this.

Yes, this is a confusing data error.
It is a duplicated name for the material.
We are aware that this is not a good error message for that.

@nh916 nh916 merged commit ad7bcbf into main Aug 12, 2023
21 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants