Skip to content

Develop #438

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/docs_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ on:
- main
- develop
- "*"
concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
build:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/doctest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ on:
- main
- develop

concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
doctest:
strategy:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ on:
- main
- develop

concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
mypy-test:
strategy:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test_coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ on:
- main
- develop

concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
test-coverage:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ on:
- main
- develop

concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
test-examples:
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ on:
- develop
- "*"

concurrency:
# github.workflow: name of the workflow
# github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

# Cancel in-progress runs when a new workflow with the same group name is triggered
cancel-in-progress: true

jobs:
install:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 3 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

The fixtures are all functional fixtures that stay consistent between all tests.
"""
import logging
import os

import pytest
Expand Down Expand Up @@ -49,14 +50,15 @@ def cript_api():
"""
storage_token = os.getenv("CRIPT_STORAGE_TOKEN")

with cript.API(host=None, api_token=None, storage_token=storage_token) as api:
with cript.API(host=None, api_token=None, storage_token=storage_token, default_log_level=logging.DEBUG) as api:
# overriding AWS S3 cognito variables to be sure we do not upload test data to production storage
# staging AWS S3 cognito storage variables
api._IDENTITY_POOL_ID = "us-east-1:25043452-a922-43af-b8a6-7e938a9e55c1"
api._COGNITO_LOGIN_PROVIDER = "cognito-idp.us-east-1.amazonaws.com/us-east-1_vyK1N9p22"
api._BUCKET_NAME = "cript-stage-user-data"
# using the tests folder name within our cloud storage
api._BUCKET_DIRECTORY_NAME = "tests"
api.extra_api_log_debug_info = True

yield api

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/synthesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ These materials are simple, notice how we use the SMILES notation here as an ide
Similarly, we can create more initial materials.

```python
toluene = cript.Material(name="toluene", identifier=[{"smiles": "Cc1ccccc1"}, {"pubchem_id": 1140}])
toluene = cript.Material(name="toluene", identifier=[{"smiles": "Cc1ccccc1"}, {"pubchem_cid": 1140}])
styrene = cript.Material(name="styrene", identifier=[{"smiles": "c1ccccc1C=C"}, {"inchi": "InChI=1S/C8H8/c1-2-8-6-4-3-5-7-8/h2-7H,1H2"}])
butanol = cript.Material(name="1-butanol", identifier=[{"smiles": "OCCCC"}, {"inchi_key": "InChIKey=LRHPLDYGYMQRHN-UHFFFAOYSA-N"}])
methanol = cript.Material(name="methanol", identifier=[{"smiles": "CO"}, {"names": ["Butan-1-ol", "Butyric alcohol", "Methylolpropane", "n-Butan-1-ol", "methanol"]}])
Expand Down
53 changes: 51 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ tab for developer documentation._

**Q:** Is there documentation detailing the internal workings of the code?

**A:** _Absolutely! For an in-depth look at the CRIPT Python SDK code,
**A:** _Absolutely! For an in-depth look at the CRIPT Python SDK code,
consult the [GitHub repository wiki internal documentation](https://github.com/C-Accel-CRIPT/Python-SDK/wiki)._

---
Expand Down Expand Up @@ -84,7 +84,7 @@ A GitHub account is required._

**Q:** Where can I find the release notes for each SDK version?

**A:** _The release notes can be found on our
**A:** _The release notes can be found on our
[CRIPT Python SDK repository releases section](https://github.com/C-Accel-CRIPT/Python-SDK/releases)_

---
Expand All @@ -97,6 +97,55 @@ the code is written to get a better grasp of it?
There you will find documentation on everything from how our code is structure,
how we aim to write our documentation, CI/CD, and more._

---

**Q:** What can I do, when my `api.search(...)` fails with a `cript.nodes.exception.CRIPTJsonDeserializationError` or similar?

**A:** _There is a solution for you. Sometimes CRIPT can contain nodes formatted in a way that the Python SDK does not understand. We can disable the automatic conversion from the API response into SDK nodes. Here is an example of how to achieve this:
```python
# Create API object in with statement, here it assumes host, token, and storage token are in your environment variables
with cript.API() as api:
# Find the paginator object, which is a python iterator over the search results.
materials_paginator = cript_api.search(node_type=cript.Material, search_mode=cript.SearchModes.NODE_TYPE)
# Usually you would do
# `materials_list = list(materials_paginator)`
# or
# for node in materials_paginator:
# #do node stuff
# But now we want more control over the iteration to ignore failing node decoding.
# And store the result in a list of valid nodes
materials_list = []
# We use a while True loop to iterate over the results
while True:
# This first try catches, when we reach the end of the search results.
# The `next()` function raises a StopIteration exception in that case
try:
# First we try to convert the current response into a node directly
try:
material_node = next(materials_paginator)
# But if that fails, we catch the exception from CRIPT
except cript.CRIPTException as exc:
# In case of failure, we disable the auto_load_function temporarily
materials_paginator.auto_load_nodes = False
# And only obtain the unloaded node JSON instead
material_json = next(materials_paginator)
# Here you can inspect and manually handle the problem.
# In the example, we just print it and ignore it otherwise
print(exc, material_json)
else:
# After a valid node is loaded (try block didn't fail)
# we store the valid node in the list
materials_list += [material_node]
finally:
# No matter what happened, for the next iteration we want to try to obtain
# an auto loaded node again, so we reset the paginator state.
materials_paginator.auto_load_nodes = True
except StopIteration:
# If next() of the paginator indicates an end of the search results, break the loop
break
```


_We try to also have type hinting, comments, and docstrings for all the code that we work on so it is clear and easy for anyone reading it to easily understand._

_if all else fails, contact us on our [GitHub Repository](https://github.com/C-Accel-CRIPT/Python-SDK)._
1 change: 1 addition & 0 deletions src/cript/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# trunk-ignore-all(ruff/F401)

from cript.api.api import API
from cript.api.data_schema import DataSchema
from cript.api.valid_search_modes import SearchModes
from cript.api.vocabulary_categories import VocabCategories
Loading