diff --git a/.github/scripts/resolve_dockerfile.py b/.github/scripts/resolve_dockerfile.py new file mode 100644 index 0000000..4b06921 --- /dev/null +++ b/.github/scripts/resolve_dockerfile.py @@ -0,0 +1,49 @@ +import sys +import os +import requests + +from ersilia_pack.parsers import DockerfileInstallParser, YAMLInstallParser + +REPO_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..")) +PY_VERSION_MAP = { + '3.8': 'py38', + '3.9': 'py39', + '3.10': 'py310', + '3.11': 'py311', + '3.12': 'py312' +} +model_id = sys.argv[1] +def resolve_parser(): + if os.path.exists(os.path.abspath(os.path.join(REPO_PATH, "Dockerfile"))): + return DockerfileInstallParser(file_dir=REPO_PATH) + elif os.path.exists(os.path.join(REPO_PATH, "install.yml")): + return YAMLInstallParser(file_dir=REPO_PATH) + else: + raise ValueError("No install file found") + +def resolve_python_version(parser): + return parser._get_python_version() + +def read_dockerfile(parser): + commands = parser._get_commands() + has_conda = parser._has_conda(commands) + if has_conda: + file_url = "https://raw.githubusercontent.com/ersilia-os/ersilia/master/dockerfiles/dockerize-ersiliapack/model/Dockerfile.conda" + else: + file_url = "https://raw.githubusercontent.com/ersilia-os/ersilia/master/dockerfiles/dockerize-ersiliapack/model/Dockerfile.pip" + response = requests.get(file_url) + return response.text + +def write_version_and_model_id(file_content, python_version): + python_version = PY_VERSION_MAP[python_version] + file_content = file_content.replace("eos_identifier", model_id) + lines = file_content.split("\n") + lines[0] = lines[0].replace("VERSION", python_version) + with open(os.path.join(REPO_PATH, "../", "Dockerfile"), "w") as f: + f.write("\n".join(lines)) + +if __name__ == "__main__": + parser = resolve_parser() + python_version = resolve_python_version(parser) + dockerfile = read_dockerfile(parser) + write_version_and_model_id(dockerfile, python_version) \ No newline at end of file diff --git a/.github/scripts/verify_model_outcome.py b/.github/scripts/verify_model_outcome.py new file mode 100644 index 0000000..5021e81 --- /dev/null +++ b/.github/scripts/verify_model_outcome.py @@ -0,0 +1,27 @@ +import csv + +def check_non_null_outcomes_in_output_csv(csv_file_path): + with open(csv_file_path, 'r') as csv_file: + csv_reader = csv.reader(csv_file) + header = next(csv_reader) + row = next(csv_reader) + for val in row[2:]: # Skip the first two columns (Inchikey and input) + if val not in ['', None]: # Returns if even one outcome is not null + return False + return True + +if __name__ == '__main__': + # Read file path from command line + import sys + if len(sys.argv) < 2: + print('Usage: python verify_model_output.py ') + exit(1) + + output_csv_file = sys.argv[1] + + if check_non_null_outcomes_in_output_csv(output_csv_file): + # If there are null outcomes, exit with status code 1 + print('All outcomes are null') + else: + print('Some outcomes are not null') + diff --git a/.github/workflows/json-check.yml b/.github/workflows/json-check.yml new file mode 100644 index 0000000..22cd701 --- /dev/null +++ b/.github/workflows/json-check.yml @@ -0,0 +1,18 @@ +name: json syntax check + +on: + push: + paths: + - "**.json" + pull_request: + +jobs: + json-test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # pin@v3.5.2 + + - name: json syntax check + id: json-yaml-validate + uses: GrantBirki/json-yaml-validate@87b2d309a02f4942c5e602183eeea11008a640f9 # pin@v1.4.0 diff --git a/.github/workflows/post-model-upload.yml b/.github/workflows/post-model-upload.yml new file mode 100644 index 0000000..d33c69f --- /dev/null +++ b/.github/workflows/post-model-upload.yml @@ -0,0 +1,194 @@ +name: Post Model Upload actions + +on: + workflow_run: + workflows: ["Upload model to DockerHub"] + types: + - completed + +jobs: + post-model-upload: + if: ${{ github.repository != 'ersilia-os/eos-template' }} + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download arch.txt + uses: actions/download-artifact@v4 + with: + name: arch + path: . + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Check metadata file + id: checkMetadata + continue-on-error: true + run: | + if [[ ! -f metadata.yml ]]; then + echo "metadata.yml file not found" + exit 1 + fi + + - name: Update Metadata YAML file with DockerHub info + id: updateMetadataYAML + if: steps.checkMetadata.outcome == 'success' + run: | + python3 -c " + import yaml + with open('metadata.yml', 'r') as f: + data = yaml.safe_load(f) + print(data) + with open('arch.txt', 'r') as f: + arch = f.read().rstrip() + arch = arch.split(',') + data['DockerHub'] = 'https://hub.docker.com/r/ersiliaos/{0}'.format(data['Identifier']) + data['Docker Architecture'] = arch + with open('metadata.yml', 'w') as f: + yaml.dump(data, f, default_flow_style=False, sort_keys=False) + " + rm arch.txt + + - name: Update Metadata JSON file with DockerHub info + id: updateMetadataJSON + if: steps.checkMetadata.outcome == 'failure' + run: | + python3 -c " + import json + with open('metadata.json', 'r') as f: + data = json.load(f) + print(data) + with open('arch.txt', 'r') as f: + arch = f.read().rstrip() + arch = arch.split(',') + data['DockerHub'] = 'https://hub.docker.com/r/ersiliaos/{0}'.format(data['Identifier']) + data['Docker Architecture'] = arch + with open('metadata.json', 'w') as f: + json.dump(data, f, indent=4) + " + rm arch.txt + + + - name: Commit and push changes done to the Metadata file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "updating metadata [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true + + # Setup conda + - name: Setup conda + id: setupConda + uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + python-version: "3.10.10" + + # Install ersilia + - name: Install dependencies in Conda environment + id: installDependenciesInConda + run: | + conda install gh -c conda-forge + python -m pip install git+https://github.com/ersilia-os/ersilia.git + + - name: Update metadata to AirTable + id: update-metadata-to-airtable + env: + USER_NAME: ${{ github.repository_owner }} + BRANCH: "main" + REPO_NAME: ${{ github.event.repository.name }} + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + run: | + source activate + pip install requests pyairtable + echo "Updating metadata to AirTable looking at owner: $USER_NAME" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py airtable-update --user $USER_NAME --repo $REPO_NAME --branch $BRANCH --api-key $AIRTABLE_API_KEY + rm airtableops.py + + - name: sync metadata to S3 JSON + id: sync-metadata-to-s3 + env: + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + source activate + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/convert_airtable_to_json.py + pip install boto3 requests pyairtable + python convert_airtable_to_json.py $AIRTABLE_API_KEY $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY + rm convert_airtable_to_json.py + + - name: Update README file + id: update-readme-file + env: + MODEL_ID: ${{ github.event.repository.name }} + run: | + echo "Updating README file with AirTable metadata for model: $MODEL_ID" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py readme-update --repo $MODEL_ID --path . + rm airtableops.py + less README.md + + - name: Commit and push changes done to the README file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "updating readme [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true + + - name: Docker Hub Description + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: ersiliaos/${{ github.event.repository.name }} + short-description: "Ersilia Model Hub Identifier: ${{ github.event.repository.name }}" + + # Create an issue within the repository to track that this model is ready for testing + + - name: Shuffle assignees + id: shuffle + run: | + export assignees=$(echo "${{ vars.assignees }}" | awk 'BEGIN {FS=","}; {srand();split($0,a,FS); print a[int(rand()*NF+1)]}') + echo "$assignees" >> $GITHUB_STEP_SUMMARY + echo "shuffled_assignee=$assignees" >> $GITHUB_OUTPUT + echo "shuffled_assignee=$assignees" >> $GITHUB_ENV + + - name: Check for existing issue + id: check_existing_test_issue + run: | + gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }} + issue_number=$(gh issue list --limit 100 --search "${{ vars.test_issue_title }}" --json number --jq '.[0].number') + echo "::set-output name=issue_number::$issue_number" + + - name: Create a Test issue + uses: actions-ecosystem/action-create-issue@b63bc2bbacb6a838dfe4a9f70da6665ae0962a49 + id: create_test_issue + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + title: ${{ vars.TEST_ISSUE_TITLE }} + assignees: | + ${{ steps.shuffle.outputs.shuffled_assignee }} + body: | + This model is a new incorporation to the Ersilia Model Hub or it has been modified. If you are assigned to this issue, please try it out and ensure everything works! + To test a model, first clone it in your local system (ideally, from dockerhub) using the CLI commands: + ``` + ersilia -v fetch eosxxxx --from_dockerhub + ersilia serve eosxxxx + ersilia test + ``` + The test command will automatically check that the model can handle null outputs and whether it produces consistent results. Please copy here the result of the test command. If it passes, simply close the issue as completed. If it fails, please detail at which step and whether you have taken any steps to solve it. Please tag the original model contributor and one of Ersilia's maintainers for support. + labels: | + test + if: steps.check_existing_test_issue.outputs.issue_number == '' diff --git a/.github/workflows/post2slack.yml b/.github/workflows/post2slack.yml new file mode 100644 index 0000000..9a77592 --- /dev/null +++ b/.github/workflows/post2slack.yml @@ -0,0 +1,17 @@ +name: Send Slack message +on: + issues: + types: [opened] + +jobs: + slack: + runs-on: ubuntu-latest + steps: + - name: post slack + uses: slackapi/slack-github-action@v1.23.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }} + with: + slack-message: | + "new issue: https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }} created." + channel-id: ${{ secrets.SLACK_CHANNEL_TESTER }} diff --git a/.github/workflows/test-model-pr.yml b/.github/workflows/test-model-pr.yml new file mode 100644 index 0000000..a76fb5c --- /dev/null +++ b/.github/workflows/test-model-pr.yml @@ -0,0 +1,79 @@ +name: Model Test on PR + +on: + pull_request: + +jobs: + test: + if: github.repository != 'ersilia-os/eos-template' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # pin@v3.5.2 + with: + lfs: true + +# This might stop working in the future, so we need to keep an eye on it + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: true + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + swap-storage: true + + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + + - name: Source conda + run: source $CONDA/etc/profile.d/conda.sh + + - name: Set Python to 3.10.10 + run: + conda install -y python=3.10.10 + + - name: Install dependencies + run: | + source activate + conda init + conda install git-lfs -c conda-forge + git-lfs install + conda install gh -c conda-forge + + - name: Install ersilia + run: | + source activate + python --version + echo "After conda init" + conda init + python -m pip install git+https://github.com/ersilia-os/ersilia.git + + - name: Predict output + env: + MODEL_ID: ${{ github.event.repository.name }} + uses: nick-fields/retry@v3 + with: + timeout_minutes: 10 + max_attempts: 3 + command: | + source activate + echo "Sample model id selected: $MODEL_ID" + ersilia -v fetch $MODEL_ID --from_dir . + ersilia -v serve $MODEL_ID + ersilia example -n 5 -f input.csv --predefined + ersilia -v api -i input.csv + ersilia close + + - name: Upload log output + if: always() + uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb #pin v3.1.1 + with: + name: debug-logs + retention-days: 14 + path: /home/runner/eos/*.log diff --git a/.github/workflows/test-model.yml b/.github/workflows/test-model.yml new file mode 100644 index 0000000..db5ce34 --- /dev/null +++ b/.github/workflows/test-model.yml @@ -0,0 +1,155 @@ +name: Model test on push + +on: + push: + branches: ['main'] + workflow_dispatch: + +jobs: + test: + if: github.repository != 'ersilia-os/eos-template' + runs-on: ubuntu-latest + steps: + - name: Checkout persist credentials + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # pin@v3.5.2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + lfs: 'true' + +# This might stop working in the future, so we need to keep an eye on it + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: true + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + swap-storage: true + + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + + - name: Source conda + run: source $CONDA/etc/profile.d/conda.sh + + - name: Set Python to 3.10.10 + run: + conda install -y python=3.10.10 + + - name: Install dependencies + run: | + source activate + conda init + conda install git-lfs -c conda-forge + git-lfs install + conda install gh -c conda-forge + + - name: Install ersilia + run: | + source activate + python --version + echo "After conda init" + conda init + python -m pip install git+https://github.com/ersilia-os/ersilia.git + + - name: Update metadata to AirTable + id: update-metadata-to-airtable + env: + USER_NAME: ${{ github.repository_owner }} + BRANCH: "main" + REPO_NAME: ${{ github.event.repository.name }} + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + uses: nick-fields/retry@v3 + with: + timeout_minutes: 10 + max_attempts: 3 + command: | + source activate + pip install requests pyairtable + echo "Updating metadata to AirTable looking at owner: $USER_NAME" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py airtable-update --user $USER_NAME --repo $REPO_NAME --branch $BRANCH --api-key $AIRTABLE_API_KEY + rm airtableops.py + + - name: sync metadata to S3 JSON + id: sync-metadata-to-s3 + env: + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + source activate + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/convert_airtable_to_json.py + pip install boto3 requests pyairtable + python convert_airtable_to_json.py $AIRTABLE_API_KEY $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY + rm convert_airtable_to_json.py + + - name: Update README file + id: update-readme-file + env: + MODEL_ID: ${{ github.event.repository.name }} + run: | + source activate + echo "Updating README file with AirTable metadata for model: $MODEL_ID" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py readme-update --repo $MODEL_ID --path . + rm airtableops.py + less README.md + + - name: Commit and push changes done to the README file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "updating readme [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true + + - name: Fetch model + env: + MODEL_ID: ${{ github.event.repository.name }} + run: | + source activate + ersilia -v fetch $MODEL_ID --from_dir . + FOLDER="$HOME/eos/repository/$MODEL_ID" + if [ ! -d "$FOLDER" ]; then + echo "Error: Folder '$FOLDER' does not exist." >&2 + exit 1 + fi + + - name: Generate input and run model + env: + MODEL_ID: ${{ github.event.repository.name }} + run: | + source activate + ersilia -v serve $MODEL_ID + ersilia example -n 5 -f input.csv --predefined + ersilia -v run -i "input.csv" -o "output.csv" + ersilia close + cat output.csv + + - name: Test output + run: | + output=$(python .github/scripts/verify_model_outcome.py output.csv) + if echo "$output" | grep -q "All outcomes are null"; then + echo "Error in model outcome, aborting test" + exit 1 + fi + rm output.csv + + - name: Upload log output + if: always() + uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb #pin v3.1.1 + with: + name: debug-logs + retention-days: 14 + path: /home/runner/eos/*.log diff --git a/.github/workflows/upload-bentoml.yml b/.github/workflows/upload-bentoml.yml new file mode 100644 index 0000000..456876a --- /dev/null +++ b/.github/workflows/upload-bentoml.yml @@ -0,0 +1,142 @@ +name: Upload BentoML Dockerized Model with or without Multi-stage Conda Pack + +on: + workflow_call: + inputs: + version: + required: true + type: string + +jobs: + build-bentoml-image: + if: ${{ github.repository != 'ersilia-os/eos-template' }} + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check if we can use this workflow + run: | + if [[ -f install.yml ]]; then + echo "This workflow is not supported for this repository" + exit 1 + fi + + # https://github.com/docker/setup-qemu-action + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + # log in to dockerhub + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + # This might stop working in the future, so we need to keep an eye on it + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: true + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + swap-storage: true + + - name: Setup conda + id: setupConda + uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + python-version: "3.10.10" + + - name: Install dependencies in Conda environment + id: installDependenciesInConda + run: | + conda install git-lfs -c conda-forge + git-lfs install + conda install gh -c conda-forge + python -m pip install git+https://github.com/ersilia-os/ersilia.git + + - name: Generate the Dockerfile + id: generateDockerfile + env: + REPO_NAME: ${{ github.event.repository.name }} + VERSION: ${{ inputs.version}} + run: | + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/place_a_dockerfile_in_current_eos_repo.py + python -m pip install requests + python place_a_dockerfile_in_current_eos_repo.py $REPO_NAME $VERSION + rm place_a_dockerfile_in_current_eos_repo.py + + # We cannot tag it as anything other than latest because + # ersilia cli only looks for the 'latest' tag + - name: Build only AMD64 Image for Testing + id: buildForTest + uses: docker/build-push-action@v5 + with: + context: . + load: true + tags: ersiliaos/${{ github.event.repository.name }}:latest + + # TODO This is very hacky, maybe we want to use the ersilia test command in the future for this + - name: Test built image + id: testBuiltImage + env: + PULL_IMAGE: n + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + run: | + ersilia -v fetch ${{ github.event.repository.name }} --from_dockerhub + ersilia -v serve ${{ github.event.repository.name }} --track #Added --track here + ersilia example -n 1 -f input.csv --predefined + ersilia -v run -i "input.csv" -o "output.csv" + ersilia close + output=$(python .github/scripts/verify_model_outcome.py output.csv) + if echo "$output" | grep -q "All outcomes are null"; then + echo "Error in model outcome, aborting build" + exit 1 + fi + rm output.csv + + - name: Build and push + id: buildMultiple + continue-on-error: true + uses: docker/build-push-action@v6.7.0 + timeout-minutes: 45 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ersiliaos/${{ github.event.repository.name }}:latest + + - name: Set build failure output + id: buildCheck + run: | + if [[ "${{ steps.buildMultiple.outcome }}" == "failure" ]]; then + echo "::set-output name=failed::true" + echo "AMD64" > arch.txt + else + echo "::set-output name=failed::false" + echo "AMD64,ARM64" > arch.txt + fi + + - name: Upload arch.txt + uses: actions/upload-artifact@v4 + with: + name: arch + path: arch.txt diff --git a/.github/workflows/upload-ersilia-pack.yml b/.github/workflows/upload-ersilia-pack.yml new file mode 100644 index 0000000..fe4bd5c --- /dev/null +++ b/.github/workflows/upload-ersilia-pack.yml @@ -0,0 +1,122 @@ +name: Upload Ersilia Pack Dockerized Model + +on: + workflow_call: + +jobs: + build-ersilia-pack-image: + if: ${{ github.repository != 'ersilia-os/eos-template' }} + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + with: + lfs: true + + - run: git lfs pull + # https://github.com/docker/setup-qemu-action + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + # log in to dockerhub + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + # This might stop working in the future, so we need to keep an eye on it + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: true + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + swap-storage: true + + # Install ersilia-pack, requests, and ersilia to test the built image with ersilia CLI + - name: Setup Python for Ersilia Pack + id: setupPythonForErsiliaPack + uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 + with: + python-version: '3.10' + + - name: Install ersilia-pack and generate the right Dockerfile + env: + REPO_NAME: ${{ github.event.repository.name }} + run: | + python -m pip install git+https://github.com/ersilia-os/ersilia-pack.git + python -m pip install requests + python -m pip install git+https://github.com/ersilia-os/ersilia.git + python .github/scripts/resolve_dockerfile.py $REPO_NAME + + - name: Build only AMD64 Image for Testing + id: buildForTestErsiliaPack + uses: docker/build-push-action@v6.7.0 + with: + context: ../ # We need to go back to the root directory to find the Dockerfile and copy the model repository + load: true + tags: ersiliaos/${{ github.event.repository.name }}:latest + + - name: Test built image + id: testBuiltImageErsiliaPack + env: + PULL_IMAGE: n + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 + if: steps.buildForTestErsiliaPack.outcome == 'success' + run: | + ersilia -v fetch ${{ github.event.repository.name }} --from_dockerhub + ersilia -v serve ${{ github.event.repository.name }} --track #Added --track here + ersilia example -n 1 -f input.csv --predefined + ersilia -v run -i "input.csv" -o "output.csv" + ersilia close + output=$(python .github/scripts/verify_model_outcome.py output.csv) + if echo "$output" | grep -q "All outcomes are null"; then + echo "Error in model outcome, aborting build" + exit 1 + fi + rm output.csv + + - name: Build and push + id: buildMultiple + continue-on-error: true + uses: docker/build-push-action@v6.7.0 + timeout-minutes: 45 + with: + context: ../ + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ersiliaos/${{ github.event.repository.name }}:latest + + - name: Set build failure output + id: buildCheck + run: | + if [[ "${{ steps.buildMultiple.outcome }}" == "failure" ]]; then + echo "::set-output name=failed::true" + echo "AMD64" > arch.txt + else + echo "::set-output name=failed::false" + echo "AMD64,ARM64" > arch.txt + fi + + - name: Upload arch.txt + uses: actions/upload-artifact@v4 + with: + name: arch + path: arch.txt diff --git a/.github/workflows/upload-model-to-dockerhub.yml b/.github/workflows/upload-model-to-dockerhub.yml new file mode 100644 index 0000000..e272e93 --- /dev/null +++ b/.github/workflows/upload-model-to-dockerhub.yml @@ -0,0 +1,29 @@ +name: Upload model to DockerHub +on: + workflow_dispatch: + + workflow_run: + workflows: ["Upload model to S3"] + types: + - completed + +jobs: + upload-ersilia-pack: + uses: ./.github/workflows/upload-ersilia-pack.yml + secrets: inherit + + upload-multi-stage-condapack: + needs: [upload-ersilia-pack] + if: ${{ failure() }} + uses: ./.github/workflows/upload-bentoml.yml + secrets: inherit + with: + version: multistage-condapack + + upload-legacy-bentoml: + needs: [upload-multi-stage-condapack] + if: ${{ failure() }} + uses: ./.github/workflows/upload-bentoml.yml + secrets: inherit + with: + version: legacy-bentoml diff --git a/.github/workflows/upload-model-to-s3.yml b/.github/workflows/upload-model-to-s3.yml new file mode 100644 index 0000000..f3a48d5 --- /dev/null +++ b/.github/workflows/upload-model-to-s3.yml @@ -0,0 +1,156 @@ +name: Upload model to S3 +on: + workflow_dispatch: + + workflow_run: + workflows: ["Model test on push"] + types: + - completed + +jobs: + upload_model_to_s3: + if: ${{ github.repository != 'ersilia-os/eos-template' && github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + steps: + - name: Checkout persist credentials + uses: actions/checkout@master + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + lfs: 'true' + + - name: Add conda to system path + run: echo $CONDA/bin >> $GITHUB_PATH + + - name: Source conda + run: source $CONDA/etc/profile.d/conda.sh + + - name: Set Python to 3.10.10 + run: + conda install -y python=3.10.10 + + - name: Install dependencies + run: | + source activate + conda init + conda install git-lfs -c conda-forge + git-lfs install + conda install gh -c conda-forge + + - name: Install ersilia + run: | + source activate + python --version + echo "After conda init" + conda init + python -m pip install git+https://github.com/ersilia-os/ersilia.git + + - name: Check metadata file + id: checkMetadata + continue-on-error: true + run: | + if [[ ! -f metadata.yml ]]; then + echo "metadata.yml file not found" + exit 1 + fi + + - name: Update Metadata JSON file with DockerHub info + if: steps.checkMetadata.outcome == 'failure' + id: UpdateMetadataJSON + run: | + python3 -c " + import json + with open('metadata.json', 'r') as f: + data = json.load(f) + data['S3'] = 'https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/{0}.zip'.format(data['Identifier']) + with open('metadata.json', 'w') as f: + json.dump(data, f, indent=4) + " + + - name: Update Metadata YAML file with DockerHub info + if: steps.checkMetadata.outcome == 'success' + id: UpdateMetadataYAML + run: | + python3 -c " + import yaml + with open('metadata.yml', 'r') as f: + data = yaml.safe_load(f) + data['S3'] = 'https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/{0}.zip'.format(data['Identifier']) + with open('metadata.yml', 'w') as f: + yaml.dump(data, f, default_flow_style=False, sort_keys=False) + " + + - name: Commit and push changes done to the Metadata JSON file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "updating metadata [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true + + - name: Update metadata to AirTable + id: update-metadata-to-airtable + env: + USER_NAME: ${{ github.repository_owner }} + BRANCH: "main" + REPO_NAME: ${{ github.event.repository.name }} + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + run: | + source activate + pip install requests pyairtable + echo "Updating metadata to AirTable looking at owner: $USER_NAME" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py airtable-update --user $USER_NAME --repo $REPO_NAME --branch $BRANCH --api-key $AIRTABLE_API_KEY + rm airtableops.py + + - name: sync metadata to S3 JSON + id: sync-metadata-to-s3 + env: + AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + source activate + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/convert_airtable_to_json.py + pip install boto3 requests pyairtable + python convert_airtable_to_json.py $AIRTABLE_API_KEY $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY + rm convert_airtable_to_json.py + + - name: Update README file + id: update-readme-file + env: + MODEL_ID: ${{ github.event.repository.name }} + run: | + source activate + echo "Updating README file with AirTable metadata for model: $MODEL_ID" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/airtableops.py + python3 airtableops.py readme-update --repo $MODEL_ID --path . + rm airtableops.py + less README.md + + - name: Commit and push changes done to the README file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "updating readme [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true + + - name: Upload model to S3 + id: upload-model-to-s3 + env: + REPO_NAME: ${{ github.event.repository.name }} + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + source activate + echo "Uploading model to S3 bucket" + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/upload_model_to_s3.py + python3 upload_model_to_s3.py $REPO_NAME $AWS_ACCESS_KEY $AWS_SECRET_ACCESS_KEY . + rm upload_model_to_s3.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..809fa6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,130 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ +/data.h5 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6aeb811 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM bentoml/model-server:0.11.0-py310 + +RUN pip install numpy==1.26.4 +RUN pip install rdkit==2022.9.5 + +WORKDIR /repo +COPY . /repo diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b6785a --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Morgan counts fingerprints + +The Morgan Fingerprints, or extended connectivity fingerprints (ECFP4) are one of the most widely used molecular representations. They are circular representations (from an atom, search the atoms around with a radius n) and can have thousands of features. This implementation uses the RDKit package and is done with radius 3 and 2048 dimensions. + +## Identifiers + +* EOS model ID: `eos5axz` +* Slug: `morgan-counts` + +## Characteristics + +* Input: `Compound` +* Input Shape: `Single` +* Task: `Representation` +* Output: `Descriptor` +* Output Type: `Integer` +* Output Shape: `List` +* Interpretation: Vector representation of a molecule + +## References + +* [Publication](https://www.rdkit.org/docs/RDKit_Book.html) +* [Source Code](https://github.com/rdkit/rdkit) +* Ersilia contributor: [miquelduranfrigola](https://github.com/miquelduranfrigola) + +## Ersilia model URLs +* [GitHub](https://github.com/ersilia-os/eos5axz) +* [AWS S3](https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/eos5axz.zip) +* [DockerHub](https://hub.docker.com/r/ersiliaos/eos5axz) (AMD64, ARM64) + +## Citation + +If you use this model, please cite the [original authors](https://www.rdkit.org/docs/RDKit_Book.html) of the model and the [Ersilia Model Hub](https://github.com/ersilia-os/ersilia/blob/master/CITATION.cff). + +## License + +This package is licensed under a GPL-3.0 license. The model contained within this package is licensed under a BSD-3.0 license. + +Notice: Ersilia grants access to these models 'as is' provided by the original authors, please refer to the original code repository and/or publication if you use the model in your research. + +## About Us + +The [Ersilia Open Source Initiative](https://ersilia.io) is a Non Profit Organization ([1192266](https://register-of-charities.charitycommission.gov.uk/charity-search/-/charity-details/5170657/full-print)) with the mission is to equip labs, universities and clinics in LMIC with AI/ML tools for infectious disease research. + +[Help us](https://www.ersilia.io/donate) achieve our mission! \ No newline at end of file diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..303d278 --- /dev/null +++ b/metadata.json @@ -0,0 +1,37 @@ +{ + "Identifier": "eos5axz", + "Slug": "morgan-counts", + "Status": "Ready", + "Title": "Morgan counts fingerprints", + "Description": "The Morgan Fingerprints, or extended connectivity fingerprints (ECFP4) are one of the most widely used molecular representations. They are circular representations (from an atom, search the atoms around with a radius n) and can have thousands of features. This implementation uses the RDKit package and is done with radius 3 and 2048 dimensions.\n", + "Mode": "Pretrained", + "Input": [ + "Compound" + ], + "Input Shape": "Single", + "Task": [ + "Representation" + ], + "Output": [ + "Descriptor" + ], + "Output Type": [ + "Integer" + ], + "Output Shape": "List", + "Interpretation": "Vector representation of a molecule", + "Tag": [ + "Fingerprint", + "Descriptor" + ], + "Publication": "https://www.rdkit.org/docs/RDKit_Book.html", + "Source Code": "https://github.com/rdkit/rdkit", + "License": "BSD-3.0", + "Contributor": "miquelduranfrigola", + "S3": "https://ersilia-models-zipped.s3.eu-central-1.amazonaws.com/eos5axz.zip", + "DockerHub": "https://hub.docker.com/r/ersiliaos/eos5axz", + "Docker Architecture": [ + "AMD64", + "ARM64" + ] +} \ No newline at end of file diff --git a/model/checkpoints/README.md b/model/checkpoints/README.md new file mode 100644 index 0000000..926034c --- /dev/null +++ b/model/checkpoints/README.md @@ -0,0 +1 @@ +# Model Pretrained Parameters diff --git a/model/framework/code/main.py b/model/framework/code/main.py new file mode 100644 index 0000000..1f9eb5e --- /dev/null +++ b/model/framework/code/main.py @@ -0,0 +1,55 @@ +# imports +import os +import csv +import sys + +from rdkit import Chem +from rdkit.Chem import rdMolDescriptors as rd +import numpy as np + +# parse arguments +input_file = sys.argv[1] +output_file = sys.argv[2] + +# current file directory +root = os.path.dirname(os.path.abspath(__file__)) + +RADIUS = 3 +NBITS = 2048 + + +def clip_sparse(vect, nbits): + l = [0] * nbits + for i, v in vect.GetNonzeroElements().items(): + l[i] = v if v < 255 else 255 + return + +def morganfp(mol): + v = rd.GetHashedMorganFingerprint(mol, radius=RADIUS, nBits=NBITS) + return clip_sparse(v, NBITS) + +# read SMILES from .csv file, assuming one column with header +with open(input_file, "r") as f: + reader = csv.reader(f) + next(reader) # skip header + smiles_list = [r[0] for r in reader] + +# run model + +outputs = list( + map( + lambda x: np.array(morganfp(Chem.MolFromSmiles(x)), dtype=np.uint8), smiles_list + ) +) + +# check input and output have the same length +input_len = len(smiles_list) +output_len = len(outputs) +assert input_len == output_len + +# write output in a .csv file +with open(output_file, "w") as f: + writer = csv.writer(f) + writer.writerow(["value"]) # header + for o in outputs: + writer.writerow(o) diff --git a/model/framework/examples/input.csv b/model/framework/examples/input.csv new file mode 100644 index 0000000..291598b --- /dev/null +++ b/model/framework/examples/input.csv @@ -0,0 +1,2 @@ +smiles +CCCC \ No newline at end of file diff --git a/model/framework/examples/output.csv b/model/framework/examples/output.csv new file mode 100644 index 0000000..9fb7d08 --- /dev/null +++ b/model/framework/examples/output.csv @@ -0,0 +1,2 @@ +f0000,f0001,f0002,f0003,f0004,f0005,f0006,f0007,f0008,f0009,f0010,f0011,f0012,f0013,f0014,f0015,f0016,f0017,f0018,f0019,f0020,f0021,f0022,f0023,f0024,f0025,f0026,f0027,f0028,f0029,f0030,f0031,f0032,f0033,f0034,f0035,f0036,f0037,f0038,f0039,f0040,f0041,f0042,f0043,f0044,f0045,f0046,f0047,f0048,f0049,f0050,f0051,f0052,f0053,f0054,f0055,f0056,f0057,f0058,f0059,f0060,f0061,f0062,f0063,f0064,f0065,f0066,f0067,f0068,f0069,f0070,f0071,f0072,f0073,f0074,f0075,f0076,f0077,f0078,f0079,f0080,f0081,f0082,f0083,f0084,f0085,f0086,f0087,f0088,f0089,f0090,f0091,f0092,f0093,f0094,f0095,f0096,f0097,f0098,f0099,f0100,f0101,f0102,f0103,f0104,f0105,f0106,f0107,f0108,f0109,f0110,f0111,f0112,f0113,f0114,f0115,f0116,f0117,f0118,f0119,f0120,f0121,f0122,f0123,f0124,f0125,f0126,f0127,f0128,f0129,f0130,f0131,f0132,f0133,f0134,f0135,f0136,f0137,f0138,f0139,f0140,f0141,f0142,f0143,f0144,f0145,f0146,f0147,f0148,f0149,f0150,f0151,f0152,f0153,f0154,f0155,f0156,f0157,f0158,f0159,f0160,f0161,f0162,f0163,f0164,f0165,f0166,f0167,f0168,f0169,f0170,f0171,f0172,f0173,f0174,f0175,f0176,f0177,f0178,f0179,f0180,f0181,f0182,f0183,f0184,f0185,f0186,f0187,f0188,f0189,f0190,f0191,f0192,f0193,f0194,f0195,f0196,f0197,f0198,f0199,f0200,f0201,f0202,f0203,f0204,f0205,f0206,f0207,f0208,f0209,f0210,f0211,f0212,f0213,f0214,f0215,f0216,f0217,f0218,f0219,f0220,f0221,f0222,f0223,f0224,f0225,f0226,f0227,f0228,f0229,f0230,f0231,f0232,f0233,f0234,f0235,f0236,f0237,f0238,f0239,f0240,f0241,f0242,f0243,f0244,f0245,f0246,f0247,f0248,f0249,f0250,f0251,f0252,f0253,f0254,f0255,f0256,f0257,f0258,f0259,f0260,f0261,f0262,f0263,f0264,f0265,f0266,f0267,f0268,f0269,f0270,f0271,f0272,f0273,f0274,f0275,f0276,f0277,f0278,f0279,f0280,f0281,f0282,f0283,f0284,f0285,f0286,f0287,f0288,f0289,f0290,f0291,f0292,f0293,f0294,f0295,f0296,f0297,f0298,f0299,f0300,f0301,f0302,f0303,f0304,f0305,f0306,f0307,f0308,f0309,f0310,f0311,f0312,f0313,f0314,f0315,f0316,f0317,f0318,f0319,f0320,f0321,f0322,f0323,f0324,f0325,f0326,f0327,f0328,f0329,f0330,f0331,f0332,f0333,f0334,f0335,f0336,f0337,f0338,f0339,f0340,f0341,f0342,f0343,f0344,f0345,f0346,f0347,f0348,f0349,f0350,f0351,f0352,f0353,f0354,f0355,f0356,f0357,f0358,f0359,f0360,f0361,f0362,f0363,f0364,f0365,f0366,f0367,f0368,f0369,f0370,f0371,f0372,f0373,f0374,f0375,f0376,f0377,f0378,f0379,f0380,f0381,f0382,f0383,f0384,f0385,f0386,f0387,f0388,f0389,f0390,f0391,f0392,f0393,f0394,f0395,f0396,f0397,f0398,f0399,f0400,f0401,f0402,f0403,f0404,f0405,f0406,f0407,f0408,f0409,f0410,f0411,f0412,f0413,f0414,f0415,f0416,f0417,f0418,f0419,f0420,f0421,f0422,f0423,f0424,f0425,f0426,f0427,f0428,f0429,f0430,f0431,f0432,f0433,f0434,f0435,f0436,f0437,f0438,f0439,f0440,f0441,f0442,f0443,f0444,f0445,f0446,f0447,f0448,f0449,f0450,f0451,f0452,f0453,f0454,f0455,f0456,f0457,f0458,f0459,f0460,f0461,f0462,f0463,f0464,f0465,f0466,f0467,f0468,f0469,f0470,f0471,f0472,f0473,f0474,f0475,f0476,f0477,f0478,f0479,f0480,f0481,f0482,f0483,f0484,f0485,f0486,f0487,f0488,f0489,f0490,f0491,f0492,f0493,f0494,f0495,f0496,f0497,f0498,f0499,f0500,f0501,f0502,f0503,f0504,f0505,f0506,f0507,f0508,f0509,f0510,f0511,f0512,f0513,f0514,f0515,f0516,f0517,f0518,f0519,f0520,f0521,f0522,f0523,f0524,f0525,f0526,f0527,f0528,f0529,f0530,f0531,f0532,f0533,f0534,f0535,f0536,f0537,f0538,f0539,f0540,f0541,f0542,f0543,f0544,f0545,f0546,f0547,f0548,f0549,f0550,f0551,f0552,f0553,f0554,f0555,f0556,f0557,f0558,f0559,f0560,f0561,f0562,f0563,f0564,f0565,f0566,f0567,f0568,f0569,f0570,f0571,f0572,f0573,f0574,f0575,f0576,f0577,f0578,f0579,f0580,f0581,f0582,f0583,f0584,f0585,f0586,f0587,f0588,f0589,f0590,f0591,f0592,f0593,f0594,f0595,f0596,f0597,f0598,f0599,f0600,f0601,f0602,f0603,f0604,f0605,f0606,f0607,f0608,f0609,f0610,f0611,f0612,f0613,f0614,f0615,f0616,f0617,f0618,f0619,f0620,f0621,f0622,f0623,f0624,f0625,f0626,f0627,f0628,f0629,f0630,f0631,f0632,f0633,f0634,f0635,f0636,f0637,f0638,f0639,f0640,f0641,f0642,f0643,f0644,f0645,f0646,f0647,f0648,f0649,f0650,f0651,f0652,f0653,f0654,f0655,f0656,f0657,f0658,f0659,f0660,f0661,f0662,f0663,f0664,f0665,f0666,f0667,f0668,f0669,f0670,f0671,f0672,f0673,f0674,f0675,f0676,f0677,f0678,f0679,f0680,f0681,f0682,f0683,f0684,f0685,f0686,f0687,f0688,f0689,f0690,f0691,f0692,f0693,f0694,f0695,f0696,f0697,f0698,f0699,f0700,f0701,f0702,f0703,f0704,f0705,f0706,f0707,f0708,f0709,f0710,f0711,f0712,f0713,f0714,f0715,f0716,f0717,f0718,f0719,f0720,f0721,f0722,f0723,f0724,f0725,f0726,f0727,f0728,f0729,f0730,f0731,f0732,f0733,f0734,f0735,f0736,f0737,f0738,f0739,f0740,f0741,f0742,f0743,f0744,f0745,f0746,f0747,f0748,f0749,f0750,f0751,f0752,f0753,f0754,f0755,f0756,f0757,f0758,f0759,f0760,f0761,f0762,f0763,f0764,f0765,f0766,f0767,f0768,f0769,f0770,f0771,f0772,f0773,f0774,f0775,f0776,f0777,f0778,f0779,f0780,f0781,f0782,f0783,f0784,f0785,f0786,f0787,f0788,f0789,f0790,f0791,f0792,f0793,f0794,f0795,f0796,f0797,f0798,f0799,f0800,f0801,f0802,f0803,f0804,f0805,f0806,f0807,f0808,f0809,f0810,f0811,f0812,f0813,f0814,f0815,f0816,f0817,f0818,f0819,f0820,f0821,f0822,f0823,f0824,f0825,f0826,f0827,f0828,f0829,f0830,f0831,f0832,f0833,f0834,f0835,f0836,f0837,f0838,f0839,f0840,f0841,f0842,f0843,f0844,f0845,f0846,f0847,f0848,f0849,f0850,f0851,f0852,f0853,f0854,f0855,f0856,f0857,f0858,f0859,f0860,f0861,f0862,f0863,f0864,f0865,f0866,f0867,f0868,f0869,f0870,f0871,f0872,f0873,f0874,f0875,f0876,f0877,f0878,f0879,f0880,f0881,f0882,f0883,f0884,f0885,f0886,f0887,f0888,f0889,f0890,f0891,f0892,f0893,f0894,f0895,f0896,f0897,f0898,f0899,f0900,f0901,f0902,f0903,f0904,f0905,f0906,f0907,f0908,f0909,f0910,f0911,f0912,f0913,f0914,f0915,f0916,f0917,f0918,f0919,f0920,f0921,f0922,f0923,f0924,f0925,f0926,f0927,f0928,f0929,f0930,f0931,f0932,f0933,f0934,f0935,f0936,f0937,f0938,f0939,f0940,f0941,f0942,f0943,f0944,f0945,f0946,f0947,f0948,f0949,f0950,f0951,f0952,f0953,f0954,f0955,f0956,f0957,f0958,f0959,f0960,f0961,f0962,f0963,f0964,f0965,f0966,f0967,f0968,f0969,f0970,f0971,f0972,f0973,f0974,f0975,f0976,f0977,f0978,f0979,f0980,f0981,f0982,f0983,f0984,f0985,f0986,f0987,f0988,f0989,f0990,f0991,f0992,f0993,f0994,f0995,f0996,f0997,f0998,f0999,f1000,f1001,f1002,f1003,f1004,f1005,f1006,f1007,f1008,f1009,f1010,f1011,f1012,f1013,f1014,f1015,f1016,f1017,f1018,f1019,f1020,f1021,f1022,f1023,f1024,f1025,f1026,f1027,f1028,f1029,f1030,f1031,f1032,f1033,f1034,f1035,f1036,f1037,f1038,f1039,f1040,f1041,f1042,f1043,f1044,f1045,f1046,f1047,f1048,f1049,f1050,f1051,f1052,f1053,f1054,f1055,f1056,f1057,f1058,f1059,f1060,f1061,f1062,f1063,f1064,f1065,f1066,f1067,f1068,f1069,f1070,f1071,f1072,f1073,f1074,f1075,f1076,f1077,f1078,f1079,f1080,f1081,f1082,f1083,f1084,f1085,f1086,f1087,f1088,f1089,f1090,f1091,f1092,f1093,f1094,f1095,f1096,f1097,f1098,f1099,f1100,f1101,f1102,f1103,f1104,f1105,f1106,f1107,f1108,f1109,f1110,f1111,f1112,f1113,f1114,f1115,f1116,f1117,f1118,f1119,f1120,f1121,f1122,f1123,f1124,f1125,f1126,f1127,f1128,f1129,f1130,f1131,f1132,f1133,f1134,f1135,f1136,f1137,f1138,f1139,f1140,f1141,f1142,f1143,f1144,f1145,f1146,f1147,f1148,f1149,f1150,f1151,f1152,f1153,f1154,f1155,f1156,f1157,f1158,f1159,f1160,f1161,f1162,f1163,f1164,f1165,f1166,f1167,f1168,f1169,f1170,f1171,f1172,f1173,f1174,f1175,f1176,f1177,f1178,f1179,f1180,f1181,f1182,f1183,f1184,f1185,f1186,f1187,f1188,f1189,f1190,f1191,f1192,f1193,f1194,f1195,f1196,f1197,f1198,f1199,f1200,f1201,f1202,f1203,f1204,f1205,f1206,f1207,f1208,f1209,f1210,f1211,f1212,f1213,f1214,f1215,f1216,f1217,f1218,f1219,f1220,f1221,f1222,f1223,f1224,f1225,f1226,f1227,f1228,f1229,f1230,f1231,f1232,f1233,f1234,f1235,f1236,f1237,f1238,f1239,f1240,f1241,f1242,f1243,f1244,f1245,f1246,f1247,f1248,f1249,f1250,f1251,f1252,f1253,f1254,f1255,f1256,f1257,f1258,f1259,f1260,f1261,f1262,f1263,f1264,f1265,f1266,f1267,f1268,f1269,f1270,f1271,f1272,f1273,f1274,f1275,f1276,f1277,f1278,f1279,f1280,f1281,f1282,f1283,f1284,f1285,f1286,f1287,f1288,f1289,f1290,f1291,f1292,f1293,f1294,f1295,f1296,f1297,f1298,f1299,f1300,f1301,f1302,f1303,f1304,f1305,f1306,f1307,f1308,f1309,f1310,f1311,f1312,f1313,f1314,f1315,f1316,f1317,f1318,f1319,f1320,f1321,f1322,f1323,f1324,f1325,f1326,f1327,f1328,f1329,f1330,f1331,f1332,f1333,f1334,f1335,f1336,f1337,f1338,f1339,f1340,f1341,f1342,f1343,f1344,f1345,f1346,f1347,f1348,f1349,f1350,f1351,f1352,f1353,f1354,f1355,f1356,f1357,f1358,f1359,f1360,f1361,f1362,f1363,f1364,f1365,f1366,f1367,f1368,f1369,f1370,f1371,f1372,f1373,f1374,f1375,f1376,f1377,f1378,f1379,f1380,f1381,f1382,f1383,f1384,f1385,f1386,f1387,f1388,f1389,f1390,f1391,f1392,f1393,f1394,f1395,f1396,f1397,f1398,f1399,f1400,f1401,f1402,f1403,f1404,f1405,f1406,f1407,f1408,f1409,f1410,f1411,f1412,f1413,f1414,f1415,f1416,f1417,f1418,f1419,f1420,f1421,f1422,f1423,f1424,f1425,f1426,f1427,f1428,f1429,f1430,f1431,f1432,f1433,f1434,f1435,f1436,f1437,f1438,f1439,f1440,f1441,f1442,f1443,f1444,f1445,f1446,f1447,f1448,f1449,f1450,f1451,f1452,f1453,f1454,f1455,f1456,f1457,f1458,f1459,f1460,f1461,f1462,f1463,f1464,f1465,f1466,f1467,f1468,f1469,f1470,f1471,f1472,f1473,f1474,f1475,f1476,f1477,f1478,f1479,f1480,f1481,f1482,f1483,f1484,f1485,f1486,f1487,f1488,f1489,f1490,f1491,f1492,f1493,f1494,f1495,f1496,f1497,f1498,f1499,f1500,f1501,f1502,f1503,f1504,f1505,f1506,f1507,f1508,f1509,f1510,f1511,f1512,f1513,f1514,f1515,f1516,f1517,f1518,f1519,f1520,f1521,f1522,f1523,f1524,f1525,f1526,f1527,f1528,f1529,f1530,f1531,f1532,f1533,f1534,f1535,f1536,f1537,f1538,f1539,f1540,f1541,f1542,f1543,f1544,f1545,f1546,f1547,f1548,f1549,f1550,f1551,f1552,f1553,f1554,f1555,f1556,f1557,f1558,f1559,f1560,f1561,f1562,f1563,f1564,f1565,f1566,f1567,f1568,f1569,f1570,f1571,f1572,f1573,f1574,f1575,f1576,f1577,f1578,f1579,f1580,f1581,f1582,f1583,f1584,f1585,f1586,f1587,f1588,f1589,f1590,f1591,f1592,f1593,f1594,f1595,f1596,f1597,f1598,f1599,f1600,f1601,f1602,f1603,f1604,f1605,f1606,f1607,f1608,f1609,f1610,f1611,f1612,f1613,f1614,f1615,f1616,f1617,f1618,f1619,f1620,f1621,f1622,f1623,f1624,f1625,f1626,f1627,f1628,f1629,f1630,f1631,f1632,f1633,f1634,f1635,f1636,f1637,f1638,f1639,f1640,f1641,f1642,f1643,f1644,f1645,f1646,f1647,f1648,f1649,f1650,f1651,f1652,f1653,f1654,f1655,f1656,f1657,f1658,f1659,f1660,f1661,f1662,f1663,f1664,f1665,f1666,f1667,f1668,f1669,f1670,f1671,f1672,f1673,f1674,f1675,f1676,f1677,f1678,f1679,f1680,f1681,f1682,f1683,f1684,f1685,f1686,f1687,f1688,f1689,f1690,f1691,f1692,f1693,f1694,f1695,f1696,f1697,f1698,f1699,f1700,f1701,f1702,f1703,f1704,f1705,f1706,f1707,f1708,f1709,f1710,f1711,f1712,f1713,f1714,f1715,f1716,f1717,f1718,f1719,f1720,f1721,f1722,f1723,f1724,f1725,f1726,f1727,f1728,f1729,f1730,f1731,f1732,f1733,f1734,f1735,f1736,f1737,f1738,f1739,f1740,f1741,f1742,f1743,f1744,f1745,f1746,f1747,f1748,f1749,f1750,f1751,f1752,f1753,f1754,f1755,f1756,f1757,f1758,f1759,f1760,f1761,f1762,f1763,f1764,f1765,f1766,f1767,f1768,f1769,f1770,f1771,f1772,f1773,f1774,f1775,f1776,f1777,f1778,f1779,f1780,f1781,f1782,f1783,f1784,f1785,f1786,f1787,f1788,f1789,f1790,f1791,f1792,f1793,f1794,f1795,f1796,f1797,f1798,f1799,f1800,f1801,f1802,f1803,f1804,f1805,f1806,f1807,f1808,f1809,f1810,f1811,f1812,f1813,f1814,f1815,f1816,f1817,f1818,f1819,f1820,f1821,f1822,f1823,f1824,f1825,f1826,f1827,f1828,f1829,f1830,f1831,f1832,f1833,f1834,f1835,f1836,f1837,f1838,f1839,f1840,f1841,f1842,f1843,f1844,f1845,f1846,f1847,f1848,f1849,f1850,f1851,f1852,f1853,f1854,f1855,f1856,f1857,f1858,f1859,f1860,f1861,f1862,f1863,f1864,f1865,f1866,f1867,f1868,f1869,f1870,f1871,f1872,f1873,f1874,f1875,f1876,f1877,f1878,f1879,f1880,f1881,f1882,f1883,f1884,f1885,f1886,f1887,f1888,f1889,f1890,f1891,f1892,f1893,f1894,f1895,f1896,f1897,f1898,f1899,f1900,f1901,f1902,f1903,f1904,f1905,f1906,f1907,f1908,f1909,f1910,f1911,f1912,f1913,f1914,f1915,f1916,f1917,f1918,f1919,f1920,f1921,f1922,f1923,f1924,f1925,f1926,f1927,f1928,f1929,f1930,f1931,f1932,f1933,f1934,f1935,f1936,f1937,f1938,f1939,f1940,f1941,f1942,f1943,f1944,f1945,f1946,f1947,f1948,f1949,f1950,f1951,f1952,f1953,f1954,f1955,f1956,f1957,f1958,f1959,f1960,f1961,f1962,f1963,f1964,f1965,f1966,f1967,f1968,f1969,f1970,f1971,f1972,f1973,f1974,f1975,f1976,f1977,f1978,f1979,f1980,f1981,f1982,f1983,f1984,f1985,f1986,f1987,f1988,f1989,f1990,f1991,f1992,f1993,f1994,f1995,f1996,f1997,f1998,f1999,f2000,f2001,f2002,f2003,f2004,f2005,f2006,f2007,f2008,f2009,f2010,f2011,f2012,f2013,f2014,f2015,f2016,f2017,f2018,f2019,f2020,f2021,f2022,f2023,f2024,f2025,f2026,f2027,f2028,f2029,f2030,f2031,f2032,f2033,f2034,f2035,f2036,f2037,f2038,f2039,f2040,f2041,f2042,f2043,f2044,f2045,f2046,f2047 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/model/framework/run.sh b/model/framework/run.sh new file mode 100644 index 0000000..3f33f76 --- /dev/null +++ b/model/framework/run.sh @@ -0,0 +1 @@ +python $1/code/main.py $2 $3 diff --git a/pack.py b/pack.py new file mode 100644 index 0000000..172416e --- /dev/null +++ b/pack.py @@ -0,0 +1,6 @@ +from src.service import Service + + +service = Service() +service.pack("model", None) +service.save() diff --git a/src/LICENSE b/src/LICENSE new file mode 100644 index 0000000..a44b4f5 --- /dev/null +++ b/src/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2006-2015, Rational Discovery LLC, Greg Landrum, and Julie Penzotti and others +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/service.py b/src/service.py new file mode 100644 index 0000000..96a7481 --- /dev/null +++ b/src/service.py @@ -0,0 +1,139 @@ +from typing import List + +from bentoml import BentoService, api, artifacts +from bentoml.adapters import JsonInput +from bentoml.types import JsonSerializable +from bentoml.service import BentoServiceArtifact + +import pickle +import os +import shutil +import tempfile +import subprocess +import csv + +CHECKPOINTS_BASEDIR = "checkpoints" +FRAMEWORK_BASEDIR = "framework" + + +def load_model(framework_dir, checkpoints_dir): + mdl = Model() + mdl.load(framework_dir, checkpoints_dir) + return mdl + + +def Float(x): + try: + return float(x) + except: + return None + + +class Model(object): + def __init__(self): + self.DATA_FILE = "_data.csv" + self.OUTPUT_FILE = "_output.csv" + self.RUN_FILE = "_run.sh" + self.LOG_FILE = "run.log" + + def load(self, framework_dir, checkpoints_dir): + self.framework_dir = framework_dir + self.checkpoints_dir = checkpoints_dir + + def set_checkpoints_dir(self, dest): + self.checkpoints_dir = os.path.abspath(dest) + + def set_framework_dir(self, dest): + self.framework_dir = os.path.abspath(dest) + + def run(self, input_list): + tmp_folder = tempfile.mkdtemp(prefix="eos-") + data_file = os.path.join(tmp_folder, self.DATA_FILE) + output_file = os.path.join(tmp_folder, self.OUTPUT_FILE) + log_file = os.path.join(tmp_folder, self.LOG_FILE) + with open(data_file, "w") as f: + f.write("input" + os.linesep) + for inp in input_list: + f.write(inp + os.linesep) + run_file = os.path.join(tmp_folder, self.RUN_FILE) + with open(run_file, "w") as f: + lines = [ + "bash {0}/run.sh {0} {1} {2}".format( + self.framework_dir, data_file, output_file + ) + ] + f.write(os.linesep.join(lines)) + cmd = "bash {0}".format(run_file) + with open(log_file, "w") as fp: + subprocess.Popen( + cmd, stdout=fp, stderr=fp, shell=True, env=os.environ + ).wait() + with open(output_file, "r") as f: + reader = csv.reader(f) + h = next(reader) + R = [] + for r in reader: + R += [ + {"outcome": [Float(x) for x in r]} + ] # <-- EDIT: Modify according to type of output (Float, String...) + meta = {"outcome": h} + result = {"result": R, "meta": meta} + shutil.rmtree(tmp_folder) + return result + + +class Artifact(BentoServiceArtifact): + def __init__(self, name): + super(Artifact, self).__init__(name) + self._model = None + self._extension = ".pkl" + + def _copy_checkpoints(self, base_path): + src_folder = self._model.checkpoints_dir + dst_folder = os.path.join(base_path, "checkpoints") + if os.path.exists(dst_folder): + os.rmdir(dst_folder) + shutil.copytree(src_folder, dst_folder) + + def _copy_framework(self, base_path): + src_folder = self._model.framework_dir + dst_folder = os.path.join(base_path, "framework") + if os.path.exists(dst_folder): + os.rmdir(dst_folder) + shutil.copytree(src_folder, dst_folder) + + def _model_file_path(self, base_path): + return os.path.join(base_path, self.name + self._extension) + + def pack(self, model): + self._model = model + return self + + def load(self, path): + model_file_path = self._model_file_path(path) + model = pickle.load(open(model_file_path, "rb")) + model.set_checkpoints_dir( + os.path.join(os.path.dirname(model_file_path), "checkpoints") + ) + model.set_framework_dir( + os.path.join(os.path.dirname(model_file_path), "framework") + ) + return self.pack(model) + + def get(self): + return self._model + + def save(self, dst): + self._copy_checkpoints(dst) + self._copy_framework(dst) + pickle.dump(self._model, open(self._model_file_path(dst), "wb")) + + +@artifacts([Artifact("model")]) +class Service(BentoService): + @api(input=JsonInput(), batch=True) + def run(self, input: List[JsonSerializable]): + input = input[0] + input_list = [inp["input"] for inp in input] + output = self.artifacts.model.run(input_list) + return [output]