# SChem
https://pypi.org/project/schem/. Install with `pip install schem`
Clean Room implementation of the backend of SpaceChem (https://www.zachtronics.com/spacechem).
## Usage (CLI)
```
python -m schem [-h] [--version] [-l LEVEL_FILE] [--max-cycles MAX_CYCLES]
[--check-precog] [--max-precog-check-cycles MAX_PRECOG_CHECK_CYCLES]
[--seed SEED] [--hash-states HASH_STATES]
[--export] [--no-run] [--strict]
[--json | --verbose] [--debug [DEBUG]]
[solution_files ...]
```
E.g. `python -m schem` will validate the cycles-reactors-symbols score of any solution export(s) in the user's clipboard. See `python -m schem --help` for details.
## Usage (python)
Supposing `level_export`, `solution_export` are strings as exported by SpaceChem CE:
```python
from schem import Level, Solution
# Load a solution
solution = Solution(solution_export) # Auto-use appropriate official level
solution = Solution(solution_export, level=level_export) # Custom level
solution = Solution(solution_export, level=Level(level_export)) # Alternative
# Run a solution
solution.run()
# => Score(cycles=45, reactors=1, symbols=14)
# Check the expected score that was in the export's metadata
solution.expected_score
# => Score(cycles=44, reactors=1, symbols=14)
# Reset the run state of a solution
solution.reset()
# Validate that a solution matched its expected score
solution.validate()
# =/> ScoreError("[Of Pancakes and Spaceships] 44-1-14 "Cycles" by Zig: Expected 44 cycles but got 45.")
# Check if a solution uses precognition
solution.is_precognitive() # slow
# => False
# Bundle method for calling validate() if expected score is present, else run(), optionally checking precog,
# and returning a dict of all this info and any error
solution.evaluate()
# => {"level_name": "Tunnels III",
# "resnet_id": (1, 1, 3), # Volume, Issue, Puzzle
# "author": "Zig",
# "cycles": 244,
# "reactors": 1,
# "symbols": 14,
# "solution_name": "symbols",
# "error": ScoreError("[Tunnels III] 243-1-14 \"symbols\" by Zig: Expected 243 cycles but got 244.")
#}
solution.evaluate(check_precog=True)
# => {"level_name": "Challenge: Going Green",
# "author": "Zig",
# "cycles: 3578,
# "reactors": 1,
# "symbols": 103,
# "solution_name": "assumes 2nd input",
# "precog": true,
# "precog_explanation": "Solution is precognitive; failed whenever molecule 2 was Hydrogen Sulfide, for 9 such
# appearances (whereas solution success rate was otherwise 100%)."
#}
# Re-export the solution. Sorts export lines to ensure uniqueness
solution.export_str()
# => "SOLUTION:..."
```
Raw data
{
"_id": null,
"home_page": "https://github.com/spacechem-community-developers/SChem",
"name": "schem",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Zig",
"author_email": "junknenopok@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/06/f5/52a8a0da810704e3d478dd31bf1b63f21fd346206b14903d1e2044505f15/schem-0.34.1.tar.gz",
"platform": null,
"description": "# SChem\r\n\r\nhttps://pypi.org/project/schem/. Install with `pip install schem`\r\n\r\nClean Room implementation of the backend of SpaceChem (https://www.zachtronics.com/spacechem).\r\n\r\n## Usage (CLI)\r\n\r\n```\r\npython -m schem [-h] [--version] [-l LEVEL_FILE] [--max-cycles MAX_CYCLES]\r\n [--check-precog] [--max-precog-check-cycles MAX_PRECOG_CHECK_CYCLES]\r\n [--seed SEED] [--hash-states HASH_STATES]\r\n [--export] [--no-run] [--strict]\r\n [--json | --verbose] [--debug [DEBUG]]\r\n [solution_files ...]\r\n```\r\n\r\nE.g. `python -m schem` will validate the cycles-reactors-symbols score of any solution export(s) in the user's clipboard. See `python -m schem --help` for details.\r\n\r\n## Usage (python)\r\n\r\nSupposing `level_export`, `solution_export` are strings as exported by SpaceChem CE:\r\n```python\r\nfrom schem import Level, Solution\r\n\r\n# Load a solution\r\nsolution = Solution(solution_export) # Auto-use appropriate official level\r\nsolution = Solution(solution_export, level=level_export) # Custom level\r\nsolution = Solution(solution_export, level=Level(level_export)) # Alternative\r\n\r\n# Run a solution\r\nsolution.run()\r\n# => Score(cycles=45, reactors=1, symbols=14)\r\n\r\n# Check the expected score that was in the export's metadata\r\nsolution.expected_score\r\n# => Score(cycles=44, reactors=1, symbols=14)\r\n\r\n# Reset the run state of a solution\r\nsolution.reset()\r\n\r\n# Validate that a solution matched its expected score\r\nsolution.validate()\r\n# =/> ScoreError(\"[Of Pancakes and Spaceships] 44-1-14 \"Cycles\" by Zig: Expected 44 cycles but got 45.\")\r\n\r\n# Check if a solution uses precognition\r\nsolution.is_precognitive() # slow\r\n# => False\r\n\r\n# Bundle method for calling validate() if expected score is present, else run(), optionally checking precog,\r\n# and returning a dict of all this info and any error\r\nsolution.evaluate()\r\n# => {\"level_name\": \"Tunnels III\",\r\n# \"resnet_id\": (1, 1, 3), # Volume, Issue, Puzzle\r\n# \"author\": \"Zig\",\r\n# \"cycles\": 244,\r\n# \"reactors\": 1,\r\n# \"symbols\": 14,\r\n# \"solution_name\": \"symbols\",\r\n# \"error\": ScoreError(\"[Tunnels III] 243-1-14 \\\"symbols\\\" by Zig: Expected 243 cycles but got 244.\")\r\n#}\r\n\r\nsolution.evaluate(check_precog=True)\r\n# => {\"level_name\": \"Challenge: Going Green\",\r\n# \"author\": \"Zig\",\r\n# \"cycles: 3578,\r\n# \"reactors\": 1,\r\n# \"symbols\": 103,\r\n# \"solution_name\": \"assumes 2nd input\",\r\n# \"precog\": true,\r\n# \"precog_explanation\": \"Solution is precognitive; failed whenever molecule 2 was Hydrogen Sulfide, for 9 such\r\n# appearances (whereas solution success rate was otherwise 100%).\"\r\n#}\r\n\r\n# Re-export the solution. Sorts export lines to ensure uniqueness\r\nsolution.export_str()\r\n# => \"SOLUTION:...\"\r\n```\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Clean Room implementation of the backend of SpaceChem (https://www.zachtronics.com/spacechem).",
"version": "0.34.1",
"project_urls": {
"Homepage": "https://github.com/spacechem-community-developers/SChem"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a8ceea3c2083efd0849b02ab7e9e46149872d887edf1b4099e90dae7d03866ef",
"md5": "13bfe35d3bdaee683c4a6fa87c1515e1",
"sha256": "9993cf2069feb6d67c9694af022f0e19e316bcd3a3d369f9a6d4790575c4098b"
},
"downloads": -1,
"filename": "schem-0.34.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13bfe35d3bdaee683c4a6fa87c1515e1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 207959,
"upload_time": "2024-08-18T21:49:59",
"upload_time_iso_8601": "2024-08-18T21:49:59.469038Z",
"url": "https://files.pythonhosted.org/packages/a8/ce/ea3c2083efd0849b02ab7e9e46149872d887edf1b4099e90dae7d03866ef/schem-0.34.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "06f552a8a0da810704e3d478dd31bf1b63f21fd346206b14903d1e2044505f15",
"md5": "5320557597f5895b99c8198ffe38c09a",
"sha256": "90b4dfe375f7b66d1f0db5bf4007337819a78cf07ef1a4a8db59a96de3bc04e5"
},
"downloads": -1,
"filename": "schem-0.34.1.tar.gz",
"has_sig": false,
"md5_digest": "5320557597f5895b99c8198ffe38c09a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 250884,
"upload_time": "2024-08-18T21:50:01",
"upload_time_iso_8601": "2024-08-18T21:50:01.549993Z",
"url": "https://files.pythonhosted.org/packages/06/f5/52a8a0da810704e3d478dd31bf1b63f21fd346206b14903d1e2044505f15/schem-0.34.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-18 21:50:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "spacechem-community-developers",
"github_project": "SChem",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "schem"
}