├── NOTICE ├── doc ├── requirements.txt ├── Makefile ├── index.rst └── conf.py ├── src └── braket │ ├── ir │ ├── blackbird │ │ ├── __init__.py │ │ └── program_v1.py │ ├── openqasm │ │ ├── __init__.py │ │ ├── modifiers.py │ │ └── program_v1.py │ ├── gate_model_shared │ │ └── __init__.py │ ├── annealing │ │ ├── __init__.py │ │ └── problem_v1.py │ ├── jaqcd │ │ ├── results.py │ │ ├── shared_models.py │ │ └── __init__.py │ └── ahs │ │ ├── shifting_field.py │ │ ├── time_series.py │ │ ├── __init__.py │ │ ├── physical_field.py │ │ ├── local_detuning.py │ │ ├── atom_arrangement.py │ │ ├── driving_field.py │ │ ├── hamiltonian.py │ │ └── program_v1.py │ ├── _schemas │ ├── __init__.py │ └── _version.py │ ├── jobs_data │ ├── __init__.py │ └── persisted_job_data_v1.py │ ├── schema_common │ ├── __init__.py │ └── schema_header.py │ ├── device_schema │ ├── error_mitigation │ │ ├── error_mitigation_scheme.py │ │ ├── __init__.py │ │ ├── error_mitigation_properties.py │ │ └── debias.py │ ├── aqt │ │ └── __init__.py │ ├── quera │ │ └── __init__.py │ ├── iqm │ │ ├── __init__.py │ │ ├── iqm_device_parameters_v1.py │ │ └── iqm_provider_properties_v1.py │ ├── oqc │ │ ├── __init__.py │ │ └── oqc_device_parameters_v1.py │ ├── ionq │ │ └── __init__.py │ ├── xanadu │ │ ├── __init__.py │ │ └── xanadu_device_parameters_v1.py │ ├── simulators │ │ ├── __init__.py │ │ ├── gate_model_simulator_paradigm_properties_v1.py │ │ └── gate_model_simulator_device_parameters_v1.py │ ├── pulse │ │ ├── __init__.py │ │ ├── pulse_function_v1.py │ │ ├── frame_v1.py │ │ └── port_v1.py │ ├── openqasm_program_set_device_action_properties.py │ ├── rigetti │ │ ├── __init__.py │ │ └── rigetti_device_parameters_v1.py │ ├── dwave │ │ ├── dwave_2000Q_device_parameters_v1.py │ │ ├── dwave_advantage_device_parameters_v1.py │ │ └── __init__.py │ ├── result_type.py │ ├── common │ │ └── gate_model_device_parameters_v1.py │ ├── device_connectivity.py │ ├── blackbird_device_action_properties.py │ ├── device_action_properties.py │ ├── gate_model_parameters_v1.py │ ├── gate_model_qpu_paradigm_properties_v1.py │ └── jaqcd_device_action_properties.py │ └── task_result │ ├── program_set_executable_cancellation_v1.py │ ├── aqt_metadata_v1.py │ ├── iqm_metadata_v1.py │ ├── oqc_metadata_v1.py │ ├── quera_metadata_v1.py │ ├── xanadu_metadata_v1.py │ ├── simulator_metadata_v1.py │ ├── ionq_metadata_v1.py │ ├── photonic_model_task_result_v1.py │ ├── program_set_task_result_v1.py │ ├── program_set_executable_failure_v1.py │ ├── annealing_task_result_v1.py │ └── program_result_v1.py ├── setup.cfg ├── .pre-commit-config.yaml ├── pyproject.toml ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── documentation_request.md │ ├── feature_request.md │ └── bug_report.md ├── dependabot.yml ├── workflows │ ├── check-format.yml │ ├── twine-check.yml │ ├── publish-to-pypi.yml │ ├── python-package.yml │ ├── dependent-tests.yml │ └── code-freeze.yml ├── pull_request_template.md └── scripts │ └── update_dependency.py ├── CODE_OF_CONDUCT.md ├── .coveragerc ├── CODEOWNERS ├── .gitignore ├── .readthedocs.yml ├── test └── unit_tests │ └── braket │ ├── schema_common │ ├── conftest.py │ └── test_schema_header.py │ ├── ir │ ├── ahs │ │ ├── test_shifting_field.py │ │ ├── test_time_series.py │ │ ├── test_driving_field.py │ │ ├── test_atom_arrangement.py │ │ └── test_physical_field.py │ ├── jaqcd │ │ ├── test_optional_multi_parameter.py │ │ ├── test_single_target.py │ │ ├── test_single_control.py │ │ ├── test_multi_state.py │ │ ├── test_angle.py │ │ ├── test_multi_target.py │ │ ├── test_multi_control.py │ │ ├── test_optional_multi_target.py │ │ ├── test_two_dimensional_matrix.py │ │ ├── test_double_target.py │ │ ├── test_double_control.py │ │ ├── test_damping_probability.py │ │ ├── test_probability.py │ │ ├── test_two_dimensional_matrix_list.py │ │ ├── test_optional_nested_multi_target.py │ │ └── test_triple_probability.py │ ├── blackbird │ │ └── test_blackbird_program_v1.py │ ├── openqasm │ │ └── test_openqasm_program_v1.py │ └── annealing │ │ └── test_problem_v1.py │ ├── device_schema │ ├── common │ │ └── test_gate_model_device_parameters_v1.py │ ├── test_result_type.py │ ├── test_device_execution_window.py │ ├── test_device_connectivity.py │ ├── test_device_action_properties.py │ ├── simulator │ │ ├── test_gate_model_simulator_paradigm_properties_v1.py │ │ └── test_gate_model_simulator_device_parameters_v1.py │ ├── iqm │ │ ├── test_iqm_device_parameters_v1.py │ │ └── test_iqm_provider_properties_v1.py │ ├── oqc │ │ └── test_oqc_device_parameters_v1.py │ ├── test_blackbird_device_action_properties.py │ ├── xanadu │ │ └── test_xanadu_device_parameters_v1.py │ ├── rigetti │ │ ├── test_rigetti_device_parameters_v1.py │ │ └── test_rigetti_provider_properties_v2.py │ ├── test_gate_model_qpu_paradigm_properties_v1.py │ ├── dwave │ │ └── test_dwave_device_parameters_v1.py │ ├── test_gate_model_parameters_v1.py │ └── test_openqasm_program_set_device_action_properties.py │ ├── task_result │ ├── test_ionq_metadata_v1.py │ └── test_simulator_metadata_v1.py │ └── jobs_data │ └── test_persisted_job_data_v1.py ├── tox.ini └── bin └── apply-header.py /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx>7 2 | sphinx-rtd-theme>=1.3.0 3 | sphinxcontrib-apidoc 4 | -------------------------------------------------------------------------------- /src/braket/ir/blackbird/__init__.py: -------------------------------------------------------------------------------- 1 | from braket.ir.blackbird.program_v1 import Program # noqa: F401 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [aliases] 2 | test=pytest 3 | 4 | [tool:pytest] 5 | xfail_strict = true 6 | addopts = 7 | --verbose -n auto 8 | testpaths = test/unit_tests 9 | 10 | -------------------------------------------------------------------------------- /src/braket/ir/openqasm/__init__.py: -------------------------------------------------------------------------------- 1 | from braket.ir.openqasm.program_set_v1 import ProgramSet # noqa: F401 2 | from braket.ir.openqasm.program_v1 import Program # noqa: F401 3 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: local 3 | hooks: 4 | - id: tox 5 | name: tox 6 | stages: [push] 7 | language: system 8 | entry: tox 9 | types: [python] 10 | pass_filenames: false 11 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.ruff] 2 | target-version = "py39" 3 | line-length = 100 4 | lint.isort = { known-first-party = [ 5 | "braket", 6 | ] } 7 | lint.extend-select = ["I", "UP", "PERF"] 8 | lint.preview = true 9 | 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://forums.aws.amazon.com/tags/braket 5 | about: Use AWS Developer Forums to ask and answer questions 6 | -------------------------------------------------------------------------------- /src/braket/ir/gate_model_shared/__init__.py: -------------------------------------------------------------------------------- 1 | from braket.ir.gate_model_shared.results import ( # noqa: F401 2 | AdjointGradient, 3 | Amplitude, 4 | DensityMatrix, 5 | Expectation, 6 | Probability, 7 | Sample, 8 | StateVector, 9 | Variance, 10 | ) 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Set update schedule for GitHub Actions 2 | 3 | version: 2 4 | updates: 5 | 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | # Check for updates to GitHub Actions every month 10 | interval: "monthly" 11 | commit-message: 12 | prefix: infra 13 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | parallel = True 3 | branch = True 4 | source = 5 | braket 6 | 7 | [paths] 8 | source = 9 | src/braket 10 | .tox/*/lib/python*/site-packages/braket 11 | 12 | [report] 13 | show_missing = True 14 | 15 | [html] 16 | directory = build/coverage 17 | 18 | [xml] 19 | output = build/coverage/coverage.xml 20 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 2 | 3 | # These owners will be the default owners for everything in 4 | # the repo. Unless a later match takes precedence, these accounts 5 | # will be requested for review when someone opens a pull request. 6 | * @amazon-braket/braket-maintainers 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *# 3 | *.swp 4 | *.idea 5 | *.iml 6 | .vscode/* 7 | 8 | .ycm_extra_conf.py 9 | .tox 10 | .python-version 11 | 12 | __pycache__/ 13 | *.py[cod] 14 | *$py.class 15 | *.egg-info/ 16 | *.ipynb_checkpoints/ 17 | pip-wheel-metadata/ 18 | 19 | /.coverage 20 | /.coverage.* 21 | /.cache 22 | /.pytest_cache 23 | /.mypy_cache 24 | 25 | /doc/_apidoc/ 26 | /build 27 | /venv 28 | /build_files.tar.gz 29 | /dist 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation request 3 | about: Request improved documentation 4 | title: '' 5 | labels: 'documentation' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What did you find confusing? Please describe.** 11 | A clear and concise description of what you found confusing. Ex. I tried to [...] but I didn't understand how to [...] 12 | 13 | **Describe how documentation can be improved** 14 | A clear and concise description of where documentation was lacking and how it can be improved. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the documentation request here. 18 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | configuration: doc/conf.py 11 | 12 | # Optionally build your docs in additional formats such as PDF 13 | formats: 14 | - pdf 15 | 16 | build: 17 | os: ubuntu-lts-latest 18 | tools: 19 | python: latest 20 | 21 | # Optionally set the version of Python and requirements required to build your docs 22 | python: 23 | install: 24 | - method: pip 25 | path: . 26 | - requirements: doc/requirements.txt 27 | -------------------------------------------------------------------------------- /src/braket/_schemas/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from ._version import __version__ # noqa: F401 15 | -------------------------------------------------------------------------------- /src/braket/ir/annealing/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.annealing.problem_v1 import Problem, ProblemType # noqa: F401 15 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = amazon-braket-schemas 8 | SOURCEDIR = . 9 | BUILDDIR = ../build/documentation 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest new functionality for this library 4 | title: '' 5 | labels: 'feature' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the feature you'd like** 11 | A clear and concise description of the functionality you want. 12 | 13 | **How would this feature be used? Please describe.** 14 | A clear and concise description of the use case for this feature. Please provide an example, if possible. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/braket/_schemas/_version.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | """Version information. 15 | Version number (major.minor.patch[-label]) 16 | """ 17 | 18 | __version__ = "1.27.1.dev0" 19 | -------------------------------------------------------------------------------- /src/braket/jobs_data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.jobs_data.persisted_job_data_v1 import ( # noqa: F401 15 | PersistedJobData, 16 | PersistedJobDataFormat, 17 | ) 18 | -------------------------------------------------------------------------------- /src/braket/schema_common/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.schema_common.schema_base import BraketSchemaBase # noqa: F401 15 | from braket.schema_common.schema_header import BraketSchemaHeader # noqa: F401 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: File a report to help us reproduce and fix the problem 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To reproduce** 14 | A clear, step-by-step set of instructions to reproduce the bug. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots or logs** 20 | If applicable, add screenshots or logs to help explain your problem. 21 | 22 | **System information** 23 | A description of your system. Please provide: 24 | - **Amazon Braket Python Schemas version**: 25 | - **Python version**: 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /src/braket/device_schema/error_mitigation/error_mitigation_scheme.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel 15 | 16 | 17 | class ErrorMitigationScheme(BaseModel): 18 | """ 19 | Base class for an error mitigation scheme. 20 | """ 21 | -------------------------------------------------------------------------------- /src/braket/device_schema/aqt/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.aqt.aqt_device_capabilities_v1 import AqtDeviceCapabilities # noqa: F401 15 | from braket.device_schema.aqt.aqt_provider_properties_v1 import AqtProviderProperties # noqa: F401 16 | -------------------------------------------------------------------------------- /.github/workflows/check-format.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Check code format 5 | 6 | on: 7 | pull_request: 8 | branches: 9 | - main 10 | - feature/** 11 | 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | check-code-format: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v6 21 | - name: Set up Python 22 | uses: actions/setup-python@v6 23 | with: 24 | python-version: '3.x' 25 | - name: Install dependencies 26 | run: | 27 | pip install tox 28 | - name: Run code format checks 29 | run: | 30 | tox -e linters_check 31 | -------------------------------------------------------------------------------- /src/braket/ir/jaqcd/results.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.gate_model_shared.results import ( # noqa: F401 15 | AdjointGradient, 16 | Amplitude, 17 | DensityMatrix, 18 | Expectation, 19 | Probability, 20 | Sample, 21 | StateVector, 22 | Variance, 23 | ) 24 | -------------------------------------------------------------------------------- /src/braket/device_schema/quera/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.quera.quera_ahs_paradigm_properties_v1 import ( # noqa: F401, E501 15 | QueraAhsParadigmProperties, 16 | ) 17 | from braket.device_schema.quera.quera_device_capabilities_v1 import ( # noqa: F401 18 | QueraDeviceCapabilities, 19 | ) 20 | -------------------------------------------------------------------------------- /src/braket/task_result/program_set_executable_cancellation_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | from pydantic.v1 import BaseModel 14 | 15 | 16 | class ProgramSetExecutableCancellationMetadata(BaseModel): 17 | """ 18 | Attributes: 19 | status (str): Status of the task; this should always be CANCELLED. 20 | """ 21 | 22 | status: str 23 | -------------------------------------------------------------------------------- /src/braket/device_schema/iqm/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.iqm.iqm_device_capabilities_v1 import IqmDeviceCapabilities # noqa: F401 15 | from braket.device_schema.iqm.iqm_device_parameters_v1 import IqmDeviceParameters # noqa: F401 16 | from braket.device_schema.iqm.iqm_provider_properties_v1 import IqmProviderProperties # noqa: F401 17 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | Amazon Braket Python Schemas 2 | ==================== 3 | 4 | Amazon Braket Python Schemas is an open source library that contains the schemas for Braket, including: 5 | 6 | * intermediate representations (IR) for Amazon Braket quantum tasks and offers serialization and deserialization of those IR payloads. Think of the IR as the contract between the Amazon Braket SDK and Amazon Braket API for quantum programs. 7 | * schemas for the S3 results of each quantum task 8 | * schemas for the device capabilities of each device 9 | 10 | Here you'll find an overview and API documentation for Amazon Braket Python Schemas. The project homepage is in GitHub, https://github.com/amazon-braket/amazon-braket-schemas-python, where you can find the source and installation instructions for the library. 11 | 12 | Indices and tables 13 | __________________ 14 | 15 | * :doc:`_apidoc/modules` 16 | * :ref:`genindex` 17 | * :ref:`modindex` 18 | * :ref:`search` 19 | -------------------------------------------------------------------------------- /src/braket/device_schema/oqc/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.oqc.oqc_device_capabilities_v1 import OqcDeviceCapabilities # noqa: F401 15 | from braket.device_schema.oqc.oqc_device_parameters_v1 import OqcDeviceParameters # noqa: F401 16 | from braket.device_schema.oqc.oqc_provider_properties_v1 import ( # noqa: F401, E501 17 | OqcProviderProperties, 18 | ) 19 | -------------------------------------------------------------------------------- /src/braket/device_schema/ionq/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.ionq.ionq_device_capabilities_v1 import ( # noqa: F401 15 | IonqDeviceCapabilities, 16 | ) 17 | from braket.device_schema.ionq.ionq_device_parameters_v1 import IonqDeviceParameters # noqa: F401 18 | from braket.device_schema.ionq.ionq_provider_properties_v1 import ( # noqa: F401, E501 19 | IonqProviderProperties, 20 | ) 21 | -------------------------------------------------------------------------------- /src/braket/device_schema/error_mitigation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.device_schema.error_mitigation.debias import Debias # noqa: F401 15 | from braket.device_schema.error_mitigation.error_mitigation_properties import ( # noqa: F401 16 | ErrorMitigationProperties, 17 | ) 18 | from braket.device_schema.error_mitigation.error_mitigation_scheme import ( # noqa: F401 19 | ErrorMitigationScheme, 20 | ) 21 | -------------------------------------------------------------------------------- /.github/workflows/twine-check.yml: -------------------------------------------------------------------------------- 1 | name: Check long description for PyPI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | - feature/** 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | twine-check: 14 | name: Check long description 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v6 18 | - name: Set up Python 19 | uses: actions/setup-python@v6 20 | with: 21 | python-version: '3.x' 22 | - name: Install wheel 23 | run: python -m pip install --user --upgrade wheel 24 | - name: Install twine 25 | run: python -m pip install --user --upgrade twine 26 | - name: Install setuptools 27 | run: python -m pip install --user --upgrade setuptools 28 | - name: Build a binary wheel and a source tarball 29 | run: python setup.py sdist bdist_wheel 30 | - name: Check that long description will render correctly on PyPI. 31 | run: twine check dist/* 32 | -------------------------------------------------------------------------------- /src/braket/device_schema/error_mitigation/error_mitigation_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel 15 | 16 | 17 | class ErrorMitigationProperties(BaseModel): 18 | """ 19 | Properties of an error mitigation scheme. 20 | 21 | Attributes: 22 | minimumShots (int): The minimum number of shots needed to use the error mitigation scheme. 23 | """ 24 | 25 | minimumShots: int 26 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/shifting_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.ahs.local_detuning import LocalDetuning 15 | 16 | # The class `ShiftingField` is deprecated. Please use `LocalDetuning` instead. 17 | # This file and class will be removed in a future version. 18 | # We are retaining this now to avoid breaking backwards compatibility for users already 19 | # utilizing this nomenclature. 20 | ShiftingField = LocalDetuning 21 | -------------------------------------------------------------------------------- /src/braket/device_schema/xanadu/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.xanadu.xanadu_device_capabilities_v1 import ( # noqa: F401 15 | XanaduDeviceCapabilities, 16 | ) 17 | from braket.device_schema.xanadu.xanadu_device_parameters_v1 import ( # noqa: F401 18 | XanaduDeviceParameters, 19 | ) 20 | from braket.device_schema.xanadu.xanadu_provider_properties_v1 import ( # noqa: F401 21 | XanaduProviderProperties, 22 | ) 23 | -------------------------------------------------------------------------------- /test/unit_tests/braket/schema_common/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | 16 | from braket.schema_common.schema_header import BraketSchemaHeader 17 | 18 | 19 | @pytest.fixture 20 | def name(): 21 | return "braket.test.schema" 22 | 23 | 24 | @pytest.fixture 25 | def version(): 26 | return "1.0" 27 | 28 | 29 | @pytest.fixture 30 | def braket_schema_header(name, version): 31 | return BraketSchemaHeader(name=name, version=version) 32 | -------------------------------------------------------------------------------- /src/braket/device_schema/error_mitigation/debias.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from enum import Enum 15 | 16 | from braket.device_schema.error_mitigation.error_mitigation_scheme import ErrorMitigationScheme 17 | 18 | 19 | class Debias(ErrorMitigationScheme): 20 | """ 21 | The debias error mitigation scheme. This scheme takes no parameters. 22 | """ 23 | 24 | class Type(str, Enum): 25 | debias = "braket.device_schema.error_mitigation.debias.Debias" 26 | 27 | type = Type.debias 28 | -------------------------------------------------------------------------------- /.github/workflows/publish-to-pypi.yml: -------------------------------------------------------------------------------- 1 | name: Publish distribution to PyPI 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | build-and-publish: 9 | name: Build and publish distribution to PyPI 10 | runs-on: ubuntu-latest 11 | environment: 12 | name: pypi 13 | url: https://pypi.org/p/amazon-braket-schemas 14 | permissions: 15 | id-token: write 16 | steps: 17 | - uses: actions/checkout@v6 18 | - name: Set up Python 19 | uses: actions/setup-python@v6 20 | with: 21 | python-version: '3.x' 22 | - name: Install wheel 23 | run: python -m pip install --user --upgrade wheel 24 | - name: Install twine 25 | run: python -m pip install --user --upgrade twine 26 | - name: Install setuptools 27 | run: python -m pip install --user --upgrade setuptools 28 | - name: Build a binary wheel and a source tarball 29 | run: python setup.py sdist bdist_wheel 30 | - name: Publish distribution to PyPI 31 | uses: pypa/gh-action-pypi-publish@release/v1 32 | -------------------------------------------------------------------------------- /doc/conf.py: -------------------------------------------------------------------------------- 1 | """Sphinx configuration.""" 2 | 3 | import datetime 4 | 5 | import pkg_resources 6 | 7 | # Sphinx configuration below. 8 | project = "amazon-braket-schemas" 9 | version = pkg_resources.require(project)[0].version 10 | release = version 11 | copyright = "{}, Amazon.com".format(datetime.datetime.now().year) 12 | 13 | extensions = [ 14 | "sphinxcontrib.apidoc", 15 | "sphinx.ext.autodoc", 16 | "sphinx.ext.viewcode", 17 | "sphinx.ext.napoleon", 18 | "sphinx.ext.todo", 19 | "sphinx.ext.coverage", 20 | ] 21 | 22 | source_suffix = ".rst" 23 | master_doc = "index" 24 | 25 | autoclass_content = "both" 26 | autodoc_member_order = "bysource" 27 | default_role = "py:obj" 28 | 29 | html_theme = "sphinx_rtd_theme" 30 | htmlhelp_basename = "{}doc".format(project) 31 | 32 | napoleon_use_rtype = False 33 | 34 | apidoc_module_dir = "../src/braket" 35 | apidoc_output_dir = "_apidoc" 36 | apidoc_excluded_paths = ["../test"] 37 | apidoc_separate_modules = True 38 | apidoc_module_first = True 39 | apidoc_extra_args = ["-f", "--implicit-namespaces", "-H", "API Reference"] 40 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/time_series.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | 16 | from pydantic.v1 import BaseModel 17 | 18 | 19 | class TimeSeries(BaseModel): 20 | """ 21 | Specifies the TimeSeries, real-valued time series 22 | 23 | Attributes: 24 | values: list[float] 25 | times: list[float], ascending 26 | 27 | Examples: 28 | >>> TimeSeries(values=[-1.25664e8,1.25664e8],times=[0.0,3.0e-6]) 29 | """ 30 | 31 | values: list[Decimal] 32 | times: list[Decimal] 33 | -------------------------------------------------------------------------------- /src/braket/device_schema/simulators/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | 15 | from braket.device_schema.simulators.gate_model_simulator_device_capabilities_v1 import ( # noqa: F401, E501 16 | GateModelSimulatorDeviceCapabilities, 17 | ) 18 | from braket.device_schema.simulators.gate_model_simulator_device_parameters_v1 import ( # noqa: F401, E501 19 | GateModelSimulatorDeviceParameters, 20 | ) 21 | from braket.device_schema.simulators.gate_model_simulator_paradigm_properties_v1 import ( # noqa: F401, E501 22 | GateModelSimulatorParadigmProperties, 23 | ) 24 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/ahs/test_shifting_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.ahs.shifting_field import ShiftingField 18 | 19 | valid_atom_field = {"time_series": {"values": [], "times": []}, "pattern": ""} 20 | 21 | 22 | def test_valid(): 23 | shifting_field = ShiftingField(magnitude=valid_atom_field) 24 | assert shifting_field.magnitude == valid_atom_field 25 | 26 | 27 | @pytest.mark.xfail(raises=ValidationError) 28 | def test__missing_magnitude(): 29 | ShiftingField() 30 | -------------------------------------------------------------------------------- /src/braket/device_schema/pulse/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.pulse.frame_v1 import Frame # noqa: F401 15 | from braket.device_schema.pulse.native_gate_calibrations_v1 import ( # noqa: F401 16 | NativeGateCalibrations, 17 | ) 18 | from braket.device_schema.pulse.port_v1 import Direction, Port # noqa: F401 19 | from braket.device_schema.pulse.pulse_device_action_properties_v1 import ( # noqa: F401 20 | PulseDeviceActionProperties, 21 | ) 22 | from braket.device_schema.pulse.pulse_function_v1 import ( # noqa: F401 23 | PulseFunction, 24 | PulseFunctionArgument, 25 | ) 26 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.ahs.atom_arrangement import AtomArrangement # noqa: F401 15 | from braket.ir.ahs.driving_field import DrivingField # noqa: F401 16 | from braket.ir.ahs.hamiltonian import Hamiltonian # noqa: F401 17 | from braket.ir.ahs.local_detuning import LocalDetuning # noqa: F401 18 | from braket.ir.ahs.physical_field import PhysicalField # noqa: F401 19 | from braket.ir.ahs.program_v1 import Program, Setup # noqa: F401 20 | from braket.ir.ahs.shifting_field import ShiftingField # noqa: F401 21 | from braket.ir.ahs.time_series import TimeSeries # noqa: F401 22 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_optional_multi_parameter.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import OptionalMultiParameter 18 | 19 | 20 | def test_missing_targets(): 21 | OptionalMultiParameter() 22 | 23 | 24 | @pytest.mark.xfail(raises=ValidationError) 25 | def test_list_empty_str(): 26 | OptionalMultiParameter(parameters=[""]) 27 | 28 | 29 | def test_different_str_formats(): 30 | OptionalMultiParameter(parameters=["theta_0", "beta", "gamma1", "0"]) 31 | 32 | 33 | def test_empty_list(): 34 | OptionalMultiParameter(parameters=[]) 35 | -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Python package 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main, feature/** ] 11 | 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | build: 18 | runs-on: ${{ matrix.os }} 19 | strategy: 20 | matrix: 21 | os: [ubuntu-latest, macos-latest, windows-latest] 22 | python-version: ["3.10", "3.11", "3.12", "3.13"] 23 | 24 | steps: 25 | - uses: actions/checkout@v6 26 | - name: Set up Python ${{ matrix.python-version }} 27 | uses: actions/setup-python@v6 28 | with: 29 | python-version: ${{ matrix.python-version }} 30 | - name: Install dependencies 31 | run: | 32 | pip install tox 33 | - name: Run unit tests 34 | run: | 35 | tox -e unit-tests 36 | - name: Upload coverage report to Codecov 37 | uses: codecov/codecov-action@v5 38 | with: 39 | token: ${{ secrets.CODECOV_TOKEN }} 40 | if: ${{ strategy.job-index }} == 0 41 | -------------------------------------------------------------------------------- /.github/workflows/dependent-tests.yml: -------------------------------------------------------------------------------- 1 | name: Dependent tests 2 | 3 | on: 4 | pull_request: 5 | branches: [ main, feature/** ] 6 | 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | python-version: ["3.13"] 18 | dependent: 19 | - amazon-braket-default-simulator-python 20 | - amazon-braket-sdk-python 21 | - amazon-braket-pennylane-plugin-python 22 | 23 | steps: 24 | - uses: actions/checkout@v6 25 | - name: Set up Python ${{ matrix.python-version }} 26 | uses: actions/setup-python@v6 27 | with: 28 | python-version: ${{ matrix.python-version }} 29 | - name: Install dependencies 30 | run: | 31 | pip install --upgrade pip 32 | pip install -e . 33 | cd .. 34 | git clone https://github.com/aws/${{ matrix.dependent }}.git 35 | cd ${{ matrix.dependent }} 36 | # Update the amazon-braket-schemas dependency to reference the current commit 37 | python ${GITHUB_WORKSPACE}/.github/scripts/update_dependency.py 38 | pip install -e .[test] 39 | - name: Run unit tests 40 | run: | 41 | cd ../${{ matrix.dependent }} 42 | pytest 43 | -------------------------------------------------------------------------------- /src/braket/device_schema/openqasm_program_set_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import conint, constr 15 | 16 | from braket.device_schema.device_action_properties import DeviceActionProperties 17 | 18 | 19 | class OpenQASMProgramSetDeviceActionProperties(DeviceActionProperties): 20 | """ 21 | Defines the properties for the Braket OpenQASM program set action. 22 | 23 | Attributes: 24 | maximumExecutables(int): The maximum number of executables 25 | that can be in a single program set. 26 | """ 27 | 28 | actionType: constr(regex=r"^braket\.ir\.openqasm\.program_set$") 29 | maximumExecutables: conint(ge=0) 30 | maximumTotalShots: conint(ge=0) 31 | -------------------------------------------------------------------------------- /src/braket/ir/jaqcd/shared_models.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.gate_model_shared.shared_models import ( # noqa: F401 15 | Angle, 16 | CompilerDirective, 17 | DampingProbability, 18 | DampingSingleProbability, 19 | DoubleControl, 20 | DoubleTarget, 21 | MultiControl, 22 | MultiProbability, 23 | MultiState, 24 | MultiTarget, 25 | Observable, 26 | OptionalMultiParameter, 27 | OptionalMultiTarget, 28 | OptionalNestedMultiTarget, 29 | SingleControl, 30 | SingleProbability, 31 | SingleProbability_34, 32 | SingleProbability_1516, 33 | SingleTarget, 34 | TripleProbability, 35 | TwoDimensionalMatrix, 36 | TwoDimensionalMatrixList, 37 | ) 38 | -------------------------------------------------------------------------------- /.github/workflows/code-freeze.yml: -------------------------------------------------------------------------------- 1 | name: Code Freeze 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | workflow_dispatch: 8 | 9 | permissions: 10 | contents: read 11 | 12 | env: 13 | FROZEN: ${{ vars.FROZEN }} 14 | UNFROZEN_PREFIX: ${{ vars.UNFROZEN_PREFIX }} 15 | 16 | jobs: 17 | check-pr-frozen-status: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Fetch PR data and check if merge allowed 21 | if: env.FROZEN == 'true' 22 | env: 23 | PR_TITLE: ${{ github.event.pull_request.title }} 24 | BRANCH_NAME: ${{ github.event.pull_request.head.ref }} 25 | run: | 26 | # if it's not a critical fix 27 | if ! [[ "$PR_TITLE" == fix(critical):* ]]; then 28 | # and there's an unfrozen prefix 29 | if [[ -n "${UNFROZEN_PREFIX:-}" ]]; then 30 | # check if the branch matches unfrozen prefix 31 | if [[ "$BRANCH_NAME" != $UNFROZEN_PREFIX* ]]; then 32 | echo "Error: You can only merge from branches that start with '$UNFROZEN_PREFIX', or PRs titled with prefix 'fix(critical): '." 33 | exit 1 34 | fi 35 | # repo is fully frozen 36 | else 37 | echo "Error: You can only merge PRs titled with prefix 'fix(critical): '." 38 | exit 1 39 | fi 40 | fi -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_single_target.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import SingleTarget 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_target(): 22 | SingleTarget() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_int(): 27 | SingleTarget(target="foo") 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_lt_zero(): 32 | SingleTarget(target=-1) 33 | 34 | 35 | def test_gte_zero(): 36 | for target in [0, 1]: 37 | obj = SingleTarget(target=target) 38 | assert obj.target == target 39 | 40 | 41 | def test_extra_params(): 42 | SingleTarget(target=0, foo="bar") 43 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/physical_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | from typing import Union 16 | 17 | from pydantic.v1 import BaseModel 18 | 19 | from braket.ir.ahs.time_series import TimeSeries 20 | 21 | 22 | class PhysicalField(BaseModel): 23 | """ 24 | Represents the temporal and spatial dependence of a control parameter affecting the atoms 25 | 26 | Attributes: 27 | time_series: TimeSeries 28 | pattern: Values refer to the pattern at the positions setup.atom_array.sites 29 | 30 | Examples: 31 | >>> PhysicalField(time_series=TimeSeries,pattern='uniform') 32 | >>> PhysicalField(time_series=TimeSeries,pattern=[0.5, 1.0, 0.5, 0.5, 0.5, 0.5]) 33 | """ 34 | 35 | time_series: TimeSeries 36 | pattern: Union[str, list[Decimal]] 37 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/common/test_gate_model_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | from braket.device_schema.common.gate_model_device_parameters_v1 import GateModelDeviceParameters 17 | 18 | 19 | def test_common_gate_model_device_parameters(): 20 | input_json = { 21 | "braketSchemaHeader": { 22 | "name": "braket.device_schema.common.gate_model_device_parameters", 23 | "version": "1", 24 | }, 25 | "paradigmParameters": { 26 | "braketSchemaHeader": { 27 | "name": "braket.device_schema.gate_model_parameters", 28 | "version": "1", 29 | }, 30 | "qubitCount": 10, 31 | }, 32 | } 33 | GateModelDeviceParameters.parse_raw_schema(json.dumps(input_json)) 34 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | *Testing done:* 6 | 7 | ## Merge Checklist 8 | 9 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request._ 10 | 11 | #### General 12 | 13 | - [ ] I have read the [CONTRIBUTING](https://github.com/amazon-braket/amazon-braket-schemas-python/blob/main/CONTRIBUTING.md) doc 14 | - [ ] I used the commit message format described in [CONTRIBUTING](https://github.com/amazon-braket/amazon-braket-schemas-python/blob/main/CONTRIBUTING.md#commit-your-change) 15 | - [ ] I have updated any necessary documentation, including [READMEs](https://github.com/amazon-braket/amazon-braket-schemas-python/blob/main/README.md) and [API docs](https://github.com/amazon-braket/amazon-braket-schemas-python/blob/main/CONTRIBUTING.md#documentation-guidelines) (if appropriate) 16 | 17 | #### Tests 18 | 19 | - [ ] I have added tests that prove my fix is effective or that my feature works (if appropriate) 20 | - [ ] I have checked that my tests are not configured for a specific region or account (if appropriate) 21 | 22 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 23 | -------------------------------------------------------------------------------- /src/braket/device_schema/rigetti/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.rigetti.rigetti_device_capabilities_v1 import ( 15 | RigettiDeviceCapabilities as RigettiDeviceCapabilities, 16 | ) 17 | from braket.device_schema.rigetti.rigetti_device_capabilities_v2 import ( # noqa: F401 18 | RigettiDeviceCapabilities as RigettiDeviceCapabilitiesV2, 19 | ) 20 | from braket.device_schema.rigetti.rigetti_device_parameters_v1 import ( 21 | RigettiDeviceParameters as RigettiDeviceParameters, 22 | ) 23 | from braket.device_schema.rigetti.rigetti_provider_properties_v1 import ( 24 | RigettiProviderProperties as RigettiProviderProperties, 25 | ) 26 | from braket.device_schema.rigetti.rigetti_provider_properties_v2 import ( # noqa: F401 27 | RigettiProviderProperties as RigettiProviderPropertiesV2, 28 | ) 29 | -------------------------------------------------------------------------------- /src/braket/ir/openqasm/modifiers.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from enum import Enum 15 | from typing import Optional, Union 16 | 17 | from pydantic.v1 import BaseModel, constr 18 | 19 | 20 | class Control(BaseModel): 21 | name: constr(regex=r"^ctrl$") 22 | max_qubits: Optional[int] = None # None indicates no limit 23 | 24 | 25 | class NegControl(BaseModel): 26 | name: constr(regex=r"^negctrl$") 27 | max_qubits: Optional[int] = None # None indicates no limit 28 | 29 | 30 | class ExponentType(str, Enum): 31 | INT = "int" 32 | FLOAT = "float" 33 | 34 | 35 | class Power(BaseModel): 36 | name: constr(regex=r"^pow$") 37 | exponent_types: list[ExponentType] 38 | 39 | 40 | class Inverse(BaseModel): 41 | name: constr(regex=r"^inv$") 42 | 43 | 44 | Modifier = Union[Control, NegControl, Power, Inverse] 45 | -------------------------------------------------------------------------------- /src/braket/task_result/aqt_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, constr 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class AqtMetadata(BraketSchemaBase): 20 | """ 21 | The AQT metadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | compiledProgram (str): The program executed on the QPU. 27 | """ 28 | 29 | _AQT_METADATA_HEADER = BraketSchemaHeader(name="braket.task_result.aqt_metadata", version="1") 30 | braketSchemaHeader: BraketSchemaHeader = Field( 31 | default=_AQT_METADATA_HEADER, const=_AQT_METADATA_HEADER 32 | ) 33 | 34 | compiledProgram: constr(min_length=2) 35 | -------------------------------------------------------------------------------- /src/braket/task_result/iqm_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, constr 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class IqmMetadata(BraketSchemaBase): 20 | """ 21 | The IQM metadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | compiledProgram (str): The program executed on the QPU. 27 | """ 28 | 29 | _IQM_METADATA_HEADER = BraketSchemaHeader(name="braket.task_result.iqm_metadata", version="1") 30 | braketSchemaHeader: BraketSchemaHeader = Field( 31 | default=_IQM_METADATA_HEADER, const=_IQM_METADATA_HEADER 32 | ) 33 | 34 | compiledProgram: constr(min_length=2) 35 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/ahs/test_time_series.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.ir.ahs.time_series import TimeSeries 20 | 21 | valid_values = [Decimal(-1.25664e8), Decimal(1.25664e8)] 22 | valid_times = [Decimal(0.0), Decimal(3.0e-6)] 23 | 24 | 25 | def test_valid(): 26 | time_series = TimeSeries(values=valid_values, times=valid_times) 27 | assert time_series.values == valid_values 28 | assert time_series.times == valid_times 29 | 30 | 31 | @pytest.mark.xfail(raises=ValidationError) 32 | def test__missing_values(): 33 | TimeSeries( 34 | times=valid_times, 35 | ) 36 | 37 | 38 | @pytest.mark.xfail(raises=ValidationError) 39 | def test__missing_times(): 40 | TimeSeries( 41 | values=valid_values, 42 | ) 43 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/local_detuning.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel 15 | 16 | from braket.ir.ahs.physical_field import PhysicalField 17 | 18 | 19 | class LocalDetuning(BaseModel): 20 | r"""Specifies the local detuning, defined by the formula 21 | 22 | .. math:: 23 | H_{shift} (t) := -\Delta(t) \sum_k h_k | r_k \rangle \langle r_k | 24 | 25 | where 26 | 27 | :math:`\Delta(t)` is the magnitude of the frequency shift in rad/s, 28 | 29 | :math:`h_k` is the site coefficient, 30 | 31 | :math:`|r_k \rangle` is the Rydberg state of atom k. 32 | 33 | with the sum :math:`\sum_k` taken over all target atoms. 34 | 35 | Attributes: 36 | magnitude: PhysicalField 37 | 38 | Examples: 39 | >>> LocalDetuning(magnitude=PhysicalField) 40 | """ 41 | 42 | magnitude: PhysicalField 43 | -------------------------------------------------------------------------------- /src/braket/device_schema/iqm/iqm_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 17 | from braket.schema_common.schema_base import BraketSchemaBase 18 | from braket.schema_common.schema_header import BraketSchemaHeader 19 | 20 | 21 | class IqmDeviceParameters(BraketSchemaBase): 22 | """ 23 | This defines the parameters common to all the IQM devices. 24 | 25 | Attributes: 26 | paradigmParameters: Parameters that are common to gatemodel paradigm 27 | """ 28 | 29 | _PROGRAM_HEADER = BraketSchemaHeader( 30 | name="braket.device_schema.iqm.iqm_device_parameters", version="1" 31 | ) 32 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 33 | paradigmParameters: GateModelParameters 34 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_result_type.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.result_type import ResultType 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = {"name": "resultType1", "observables": ["observable1"], "minShots": 2, "maxShots": 4} 25 | return input 26 | 27 | 28 | def test_valid(valid_input): 29 | result = ResultType.parse_raw(json.dumps(valid_input)) 30 | assert result.name == "resultType1" 31 | assert result.observables == ["observable1"] 32 | assert result.minShots == 2 33 | assert result.maxShots == 4 34 | 35 | 36 | @pytest.mark.xfail(raises=ValidationError) 37 | def test_missing_name(valid_input): 38 | valid_input.pop("name") 39 | ResultType.parse_raw(json.dumps(valid_input)) 40 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/atom_arrangement.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | 16 | from pydantic.v1 import BaseModel 17 | 18 | 19 | class AtomArrangement(BaseModel): 20 | """ 21 | Specifies the atom array 22 | 23 | Attributes: 24 | sites: List of 2-d coordinates where the tweezers trap atoms 25 | filling: Marks atoms that occupy the trap sites with 1, and empty sites with 0 26 | 27 | 28 | Examples: 29 | >>> AtomArrangement(sites=[ 30 | ... [0.0, 0.0], 31 | ... [0.0, 3.0e-6], 32 | ... [0.0, 6.0e-6], 33 | ... [3.0e-6, 0.0], 34 | ... [3.0e-6, 3.0e-6], 35 | ... [3.0e-6, 6.0e-6] 36 | ... ], 37 | ... filling=[1,1,1,1,0,0]) 38 | """ 39 | 40 | sites: list[list[Decimal]] 41 | filling: list[int] 42 | -------------------------------------------------------------------------------- /src/braket/device_schema/dwave/dwave_2000Q_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.dwave.dwave_2000Q_device_level_parameters_v1 import ( 17 | Dwave2000QDeviceLevelParameters, 18 | ) 19 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 20 | 21 | 22 | class Dwave2000QDeviceParameters(BraketSchemaBase): 23 | """ 24 | This is the description of the D-Wave parameters 25 | 26 | Attributes: 27 | deviceLevelParameters: Parameters that are specific to this D-Wave device. 28 | """ 29 | 30 | _PROGRAM_HEADER = BraketSchemaHeader( 31 | name="braket.device_schema.dwave.dwave_2000Q_device_parameters", version="1" 32 | ) 33 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 34 | deviceLevelParameters: Dwave2000QDeviceLevelParameters 35 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_device_execution_window.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.device_execution_window import DeviceExecutionWindow, ExecutionDay 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "executionDay": "Everyday", 26 | "windowStartHour": "11:00", 27 | "windowEndHour": "12:00", 28 | } 29 | return input 30 | 31 | 32 | def test_valid(valid_input): 33 | result = DeviceExecutionWindow.parse_raw(json.dumps(valid_input)) 34 | assert result.executionDay == ExecutionDay("Everyday") 35 | 36 | 37 | @pytest.mark.xfail(raises=ValidationError) 38 | def test__missing_executionDay(valid_input): 39 | valid_input.pop("executionDay") 40 | assert DeviceExecutionWindow.parse_raw(json.dumps(valid_input)) 41 | -------------------------------------------------------------------------------- /src/braket/task_result/oqc_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, constr 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class OqcMetadata(BraketSchemaBase): 20 | """ 21 | The Oqc metadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | executedProgram (str): The program executed on the QPU. 27 | 28 | Examples: 29 | >>> OqcMetadata(executedProgram="DECLARE ro BIT[2];") 30 | """ 31 | 32 | _OQC_METADATA_HEADER = BraketSchemaHeader(name="braket.task_result.oqc_metadata", version="1") 33 | braketSchemaHeader: BraketSchemaHeader = Field( 34 | default=_OQC_METADATA_HEADER, const=_OQC_METADATA_HEADER 35 | ) 36 | 37 | compiledProgram: constr(min_length=2) 38 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_single_control.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import SingleControl 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_control(): 22 | SingleControl() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_int(): 27 | SingleControl(control="foo") 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_int_lt_zero(): 32 | SingleControl(control=-1) 33 | 34 | 35 | def test_int_gte_zero(): 36 | for control in (0, 1): 37 | obj = SingleControl(control=control) 38 | assert obj.control == control 39 | 40 | 41 | def test_int_extra_params(): 42 | SingleControl(control=0, foo="bar") 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_list(): 47 | SingleControl(control=[0]) 48 | -------------------------------------------------------------------------------- /src/braket/device_schema/dwave/dwave_advantage_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.dwave.dwave_advantage_device_level_parameters_v1 import ( 17 | DwaveAdvantageDeviceLevelParameters, 18 | ) 19 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 20 | 21 | 22 | class DwaveAdvantageDeviceParameters(BraketSchemaBase): 23 | """ 24 | This is the description of the D-Wave parameters 25 | 26 | Attributes: 27 | deviceLevelParameters: Parameters that are specific to this D-Wave device. 28 | """ 29 | 30 | _PROGRAM_HEADER = BraketSchemaHeader( 31 | name="braket.device_schema.dwave.dwave_advantage_device_parameters", version="1" 32 | ) 33 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 34 | deviceLevelParameters: DwaveAdvantageDeviceLevelParameters 35 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/blackbird/test_blackbird_program_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # # or in the "license" file accompanying this file. This file is 9 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 10 | # ANY KIND, either express or implied. See the License for the specific 11 | # language governing permissions and limitations under the License. 12 | 13 | import pytest 14 | from pydantic.v1 import ValidationError 15 | 16 | from braket.ir.blackbird import Program as BlackbirdProgram 17 | 18 | 19 | @pytest.mark.xfail(raises=ValidationError) 20 | def test_missing_source_property(): 21 | BlackbirdProgram() 22 | 23 | 24 | def test_blackbird_program(): 25 | source = "testsource" 26 | program = BlackbirdProgram(source=source) 27 | assert "braket.ir.blackbird.program" == program.braketSchemaHeader.name 28 | assert source == program.source 29 | 30 | 31 | def test_parse_obj(): 32 | source = "testsource" 33 | program = BlackbirdProgram(source=source) 34 | assert program == BlackbirdProgram.parse_obj(program.dict()) 35 | 36 | 37 | def test_parse_raw(): 38 | source = "testsource" 39 | program = BlackbirdProgram(source=source) 40 | assert program == BlackbirdProgram.parse_raw(program.json()) 41 | -------------------------------------------------------------------------------- /src/braket/task_result/quera_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, conint 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class QueraMetadata(BraketSchemaBase): 20 | """ 21 | The Querametadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | numSuccessfulShots (int): Number of successful shots in result. 27 | 28 | Examples: 29 | >>> QueraMetadata(numSuccessfulShots=100) 30 | """ 31 | 32 | _QUERA_METADATA_HEADER = BraketSchemaHeader( 33 | name="braket.task_result.quera_metadata", version="1" 34 | ) 35 | braketSchemaHeader: BraketSchemaHeader = Field( 36 | default=_QUERA_METADATA_HEADER, const=_QUERA_METADATA_HEADER 37 | ) 38 | 39 | numSuccessfulShots: conint(ge=0, le=1000) 40 | -------------------------------------------------------------------------------- /src/braket/ir/blackbird/program_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class Program(BraketSchemaBase): 20 | """ 21 | Root object of the Blackbird IR. 22 | 23 | More about Blackbird: 24 | https://quantum-blackbird.readthedocs.io/en/latest/ 25 | 26 | Attributes: 27 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 28 | to set this value. Only default is allowed. 29 | source (str): Blackbird program. 30 | 31 | Examples: 32 | >>> from braket.ir.blackbird import Program as BlackbirdProgram 33 | >>> BlackbirdProgram(source='') 34 | """ 35 | 36 | _PROGRAM_HEADER = BraketSchemaHeader(name="braket.ir.blackbird.program", version="1") 37 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 38 | source: str 39 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_multi_state.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import MultiState 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_states(): 22 | MultiState() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_str(): 27 | MultiState(states=[20, "101"]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_list_partial_non_matching_regex(): 32 | MultiState(states=["10202", "01"]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_empty_list(): 37 | MultiState(states=[]) 38 | 39 | 40 | def test_list_matching_regex(): 41 | states = ["1", "10101"] 42 | obj = MultiState(states=states) 43 | assert obj.states == states 44 | 45 | 46 | def test_list_extra_params(): 47 | MultiState(states=["01", "01101"], foo="bar") 48 | -------------------------------------------------------------------------------- /src/braket/task_result/xanadu_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, constr 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class XanaduMetadata(BraketSchemaBase): 20 | """ 21 | The Xanadumetadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | executedProgram (str): The program executed on the QPU. 27 | 28 | Examples: 29 | >>> XanaduMetadata(executedProgram="DECLARE ro BIT[2];") 30 | """ 31 | 32 | _XANADU_METADATA_HEADER = BraketSchemaHeader( 33 | name="braket.task_result.xanadu_metadata", version="1" 34 | ) 35 | braketSchemaHeader: BraketSchemaHeader = Field( 36 | default=_XANADU_METADATA_HEADER, const=_XANADU_METADATA_HEADER 37 | ) 38 | 39 | compiledProgram: constr(min_length=2) 40 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_angle.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import Angle 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_angle(): 22 | Angle() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_float(): 27 | Angle(angle="foo") 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_nan_float(): 32 | Angle(angle=float("nan")) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_inf_float(): 37 | Angle(angle=float("inf")) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_negative_inf_float(): 42 | Angle(angle=float("-inf")) 43 | 44 | 45 | def test_float(): 46 | angle = 0.15 47 | obj = Angle(angle=angle) 48 | assert obj.angle == angle 49 | 50 | 51 | def test_extra_params(): 52 | Angle(angle=0, foo="bar") 53 | -------------------------------------------------------------------------------- /test/unit_tests/braket/task_result/test_ionq_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.task_result import IonQMetadata 18 | 19 | 20 | def test_no_sharpening(): 21 | metadata = IonQMetadata() 22 | assert metadata.sharpenedProbabilities is None 23 | 24 | 25 | def test_sharpening_populated(): 26 | histogram = {"00": 0.5, "11": 0.5} 27 | metadata = IonQMetadata(sharpenedProbabilities=histogram) 28 | assert metadata.sharpenedProbabilities == histogram 29 | 30 | 31 | @pytest.mark.parametrize("histogram", [{"a": 0.5}, {"": 0.5}, {"0000": -0.3}, {"11": 1.4}]) 32 | @pytest.mark.xfail(raises=ValidationError) 33 | def test_invalid_sharpened_probabilities_vote(histogram): 34 | IonQMetadata(sharpenedProbabilities=histogram) 35 | 36 | 37 | @pytest.mark.xfail(raises=ValidationError) 38 | def test_header_incorrect(braket_schema_header): 39 | IonQMetadata(braketSchemaHeader=braket_schema_header) 40 | -------------------------------------------------------------------------------- /src/braket/device_schema/result_type.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import BaseModel 17 | 18 | 19 | class ResultType(BaseModel): 20 | """ 21 | Provides the result type for a quantum task to return. 22 | 23 | Attributes: 24 | 25 | name: Name of the result type. 26 | observables: Supported result types for this result type. 27 | minShots: Minimum number of shots for the results. 28 | maxShots: Maximum number of shots for the results. 29 | 30 | Examples: 31 | >>> import json 32 | >>> input_json = { 33 | ... "name": "resultType1", 34 | ... "observables": ["observable1"], 35 | ... "minShots": 0, 36 | ... "maxShots": 4, 37 | ... } 38 | >>> ResultType.parse_raw(json.dumps(input_json)) 39 | """ 40 | 41 | name: str 42 | observables: Optional[list[str]] 43 | minShots: Optional[int] 44 | maxShots: Optional[int] 45 | -------------------------------------------------------------------------------- /src/braket/device_schema/common/gate_model_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 17 | from braket.schema_common.schema_base import BraketSchemaBase 18 | from braket.schema_common.schema_header import BraketSchemaHeader 19 | 20 | 21 | class GateModelDeviceParameters(BraketSchemaBase): 22 | """Schema for parameters shared across all gate model devices. 23 | 24 | Args: 25 | braketSchemaHeader (BraketSchemaHeader): Schema header containing name and version. 26 | paradigmParameters (GateModelParameters): Parameters specific to gate model devices. 27 | """ 28 | 29 | _PROGRAM_HEADER = BraketSchemaHeader( 30 | name="braket.device_schema.common.gate_model_device_parameters", version="1" 31 | ) 32 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 33 | paradigmParameters: GateModelParameters 34 | -------------------------------------------------------------------------------- /src/braket/device_schema/pulse/pulse_function_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import BaseModel 17 | 18 | 19 | class PulseFunctionArgument(BaseModel): 20 | """ 21 | Defines a pulse function argument 22 | 23 | Attributes: 24 | name: The argument name 25 | type: The string name of the argument type 26 | description: Optional description for the argument 27 | 28 | """ 29 | 30 | name: str 31 | type: str 32 | optional: bool = False 33 | description: Optional[str] 34 | 35 | 36 | class PulseFunction(BaseModel): 37 | """ 38 | Describes a pulse function 39 | 40 | Attributes: 41 | functionName: The name of the function 42 | arguments: List of function arguments 43 | returnType: Return type of the function. If null function has no return value. 44 | 45 | """ 46 | 47 | functionName: str 48 | arguments: list[PulseFunctionArgument] 49 | returnType: Optional[str] 50 | -------------------------------------------------------------------------------- /src/braket/task_result/simulator_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from pydantic.v1 import Field, conint 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class SimulatorMetadata(BraketSchemaBase): 20 | """ 21 | The simulator metadata result schema. 22 | 23 | Attributes: 24 | braketSchemaHeader (BraketSchemaHeader): Schema header. 25 | Users do not need to set this value. Only default is allowed. 26 | executionDuration (int): The number of milliseconds it took to execute 27 | the circuit on the simulator. 28 | 29 | Examples: 30 | >>> SimulatorMetadata(executionDuration=100) 31 | 32 | """ 33 | 34 | _SIMULATOR_METADATA_HEADER = BraketSchemaHeader( 35 | name="braket.task_result.simulator_metadata", version="1" 36 | ) 37 | braketSchemaHeader: BraketSchemaHeader = Field( 38 | default=_SIMULATOR_METADATA_HEADER, const=_SIMULATOR_METADATA_HEADER 39 | ) 40 | executionDuration: conint(ge=0) 41 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = linters,docs,unit-tests 3 | 4 | [testenv:unit-tests] 5 | basepython = python3 6 | # {posargs} contains additional arguments specified when invoking tox. e.g. tox -- -s -k test_foo.py 7 | commands = 8 | pytest {posargs} --cov-report term-missing --cov-report html --cov-report xml --cov=braket 9 | extras = test 10 | 11 | [testenv:linters] 12 | basepython = python3 13 | # Remove this to check what versions are installed for the env. This stops running pip freeze. 14 | list_dependencies_command = echo 15 | deps = 16 | {[testenv:ruff-format]deps} 17 | {[testenv:ruff-check]deps} 18 | commands = 19 | {[testenv:ruff-format]commands} 20 | {[testenv:ruff-check]commands} 21 | 22 | # Read only linter env 23 | [testenv:linters_check] 24 | basepython = python3 25 | extras = linters 26 | commands = 27 | {[testenv:ruff-check]commands} 28 | 29 | [testenv:ruff-check] 30 | basepython = python3 31 | extras = linters 32 | deps = ruff 33 | commands = 34 | ruff check src {posargs} 35 | 36 | [testenv:ruff-format] 37 | basepython = python3 38 | extras = linters 39 | deps = ruff 40 | commands = 41 | ruff format . {posargs} 42 | 43 | [testenv:docs] 44 | basepython = python3 45 | commands = 46 | sphinx-build -E -T -b html doc build/documentation/html 47 | extras = docs 48 | 49 | [testenv:serve-docs] 50 | basepython = python3 51 | skip_install = true 52 | changedir = build/documentation/html 53 | commands = 54 | python -m http.server {posargs} 55 | 56 | [testenv:zip-build] 57 | basepython = python3 58 | skip_install = true 59 | commands = 60 | /bin/sh -c 'tar -czvf build_files.tar.gz build/' 61 | -------------------------------------------------------------------------------- /src/braket/device_schema/device_connectivity.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel 15 | 16 | 17 | class DeviceConnectivity(BaseModel): 18 | """ 19 | This schema defines the common properties that need to be existent if a connection is defined. 20 | 21 | Attributes: 22 | 23 | fullyConnected: If each qubit is connected to all other qubits then 24 | it called fully connected. true if fully connected else it will be false. 25 | 26 | connectivityGraph: It defines for each qubit what are the connected qubits. 27 | For a fullyConnected graph it will be empty since all the qubits are 28 | connected to each other 29 | 30 | 31 | Examples: 32 | >>> import json 33 | >>> input_json = { 34 | ... "fullyConnected": False, 35 | ... "connectivityGraph": {"1": ["2", "3"]}, 36 | ... } 37 | >>> DeviceConnectivity.parse_raw(json.dumps(input_json)) 38 | """ 39 | 40 | fullyConnected: bool 41 | connectivityGraph: dict[str, list[str]] 42 | -------------------------------------------------------------------------------- /src/braket/task_result/ionq_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import Field, confloat, constr 17 | 18 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 19 | 20 | 21 | class IonQMetadata(BraketSchemaBase): 22 | """ 23 | Metadata for results of IonQ tasks. 24 | 25 | Attributes: 26 | braketSchemaHeader (BraketSchemaHeader): Schema header. 27 | Users do not need to set this value. Only default is allowed. 28 | sharpenedProbabilities (Optional[dict[str, float]]): The histogram of results after 29 | postprocessing with sharpening. Default: None. 30 | """ 31 | 32 | _IONQ_METADATA_HEADER = BraketSchemaHeader(name="braket.task_result.ionq_metadata", version="1") 33 | braketSchemaHeader: BraketSchemaHeader = Field( 34 | default=_IONQ_METADATA_HEADER, const=_IONQ_METADATA_HEADER 35 | ) 36 | sharpenedProbabilities: Optional[ 37 | dict[constr(regex="^[01]+$", min_length=1), confloat(ge=0, le=1)] 38 | ] = None 39 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_multi_target.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import MultiTarget 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_targets(): 22 | MultiTarget() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | MultiTarget(targets=[0, "foo"]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_list_lt_zero(): 32 | MultiTarget(targets=[-1, -2]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_list_partial_lt_zero(): 37 | MultiTarget(targets=[0, -1]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | MultiTarget(targets=[]) 43 | 44 | 45 | def test_list_gte_zero(): 46 | targets = [0, 1] 47 | obj = MultiTarget(targets=targets) 48 | assert obj.targets == targets 49 | 50 | 51 | def test_list_extra_params(): 52 | MultiTarget(targets=[0, 1], foo="bar") 53 | -------------------------------------------------------------------------------- /src/braket/device_schema/pulse/frame_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Any, Optional 15 | 16 | from pydantic.v1 import BaseModel 17 | 18 | 19 | class Frame(BaseModel): 20 | """ 21 | Defines the pre-built frames for the given hardware. For more details on frames 22 | refer to the OpenQasm/OpenPulse documentation 23 | 24 | Attributes: 25 | frameId: The id name of the frame that may be loaded in OpenQasm 26 | portId: The id of the associated hardware port the frame uses 27 | frequency: The initial frequency of the frame 28 | phase: The initial phase of the frame 29 | associatedGate: Optional detail if the frame is associated with a gate 30 | qubitMappings: Optional list of associated qubits for the frame 31 | 32 | """ 33 | 34 | frameId: str 35 | portId: str 36 | frequency: float 37 | centerFrequency: Optional[float] 38 | phase: float 39 | associatedGate: Optional[str] 40 | qubitMappings: Optional[list[int]] 41 | qhpSpecificProperties: Optional[dict[str, Any]] 42 | -------------------------------------------------------------------------------- /src/braket/device_schema/pulse/port_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from enum import Enum 15 | from typing import Any, Optional 16 | 17 | from pydantic.v1 import BaseModel 18 | 19 | 20 | class Direction(Enum): 21 | """ 22 | Specifies the direction of port. 23 | """ 24 | 25 | tx = "tx" 26 | rx = "rx" 27 | 28 | 29 | class Port(BaseModel): 30 | """ 31 | Represents a hardware port that may be used for pulse control. For more details on ports 32 | refer to the OpenQasm/OpenPulse documentation 33 | 34 | Attributes: 35 | portId: The id of the associated hardware port the frame uses 36 | direction: The directionality of the port 37 | portType: The port type of the control hardware 38 | dt: The smallest time step that may be used on the control hardware 39 | 40 | """ 41 | 42 | portId: str 43 | direction: Direction 44 | portType: str 45 | dt: float 46 | qubitMappings: Optional[list[int]] 47 | centerFrequencies: Optional[set[float]] 48 | qhpSpecificProperties: Optional[dict[str, Any]] 49 | -------------------------------------------------------------------------------- /test/unit_tests/braket/schema_common/test_schema_header.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.schema_common.schema_header import BraketSchemaHeader 18 | 19 | 20 | @pytest.fixture 21 | def name(): 22 | return "braket.test.schema" 23 | 24 | 25 | @pytest.fixture 26 | def version(): 27 | return "1.0" 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_missing_properties(): 32 | BraketSchemaHeader() 33 | 34 | 35 | def test_schema_header_correct(name, version): 36 | header = BraketSchemaHeader(name=name, version=version) 37 | assert header.name == name 38 | assert header.version == version 39 | assert BraketSchemaHeader.parse_raw(header.json()) == header 40 | 41 | 42 | @pytest.mark.xfail(raises=ValidationError) 43 | def test_header_name_incorrect(version): 44 | BraketSchemaHeader(name="", version=version) 45 | 46 | 47 | @pytest.mark.xfail(raises=ValidationError) 48 | def test_header_version_incorrect(name): 49 | BraketSchemaHeader(name=name, version="") 50 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_multi_control.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import MultiControl 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_controls(): 22 | MultiControl() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | MultiControl(controls=[0, "foo"]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_list_lt_zero(): 32 | MultiControl(controls=[-1, -2]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_list_partial_lt_zero(): 37 | MultiControl(controls=[0, -1]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | MultiControl(controls=[]) 43 | 44 | 45 | def test_list_gte_zero(): 46 | controls = [0, 1] 47 | obj = MultiControl(controls=controls) 48 | assert obj.controls == controls 49 | 50 | 51 | def test_list_extra_params(): 52 | MultiControl(controls=[0, 1], foo="bar") 53 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_optional_multi_target.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import OptionalMultiTarget 18 | 19 | 20 | def test_missing_targets(): 21 | OptionalMultiTarget() 22 | 23 | 24 | @pytest.mark.xfail(raises=ValidationError) 25 | def test_list_partial_non_int(): 26 | OptionalMultiTarget(targets=[0, "foo"]) 27 | 28 | 29 | @pytest.mark.xfail(raises=ValidationError) 30 | def test_list_lt_zero(): 31 | OptionalMultiTarget(targets=[-1, -2]) 32 | 33 | 34 | @pytest.mark.xfail(raises=ValidationError) 35 | def test_list_partial_lt_zero(): 36 | OptionalMultiTarget(targets=[0, -1]) 37 | 38 | 39 | @pytest.mark.xfail(raises=ValidationError) 40 | def test_empty_list(): 41 | OptionalMultiTarget(targets=[]) 42 | 43 | 44 | def test_list_gte_zero(): 45 | targets = [0, 1] 46 | obj = OptionalMultiTarget(targets=targets) 47 | assert obj.targets == targets 48 | 49 | 50 | def test_list_extra_params(): 51 | OptionalMultiTarget(targets=[0, 1], foo="bar") 52 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/ahs/test_driving_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.ahs.driving_field import DrivingField 18 | 19 | valid_atom_field = {"time_series": {"values": [], "times": []}, "pattern": ""} 20 | 21 | 22 | def test_valid(): 23 | driving_field = DrivingField( 24 | amplitude=valid_atom_field, phase=valid_atom_field, detuning=valid_atom_field 25 | ) 26 | assert driving_field.amplitude == valid_atom_field 27 | assert driving_field.phase == valid_atom_field 28 | assert driving_field.detuning == valid_atom_field 29 | 30 | 31 | @pytest.mark.xfail(raises=ValidationError) 32 | def test__missing_amplitude(): 33 | DrivingField(phase=valid_atom_field, detuning=valid_atom_field) 34 | 35 | 36 | @pytest.mark.xfail(raises=ValidationError) 37 | def test__missing_phase(): 38 | DrivingField(amplitude=valid_atom_field, detuning=valid_atom_field) 39 | 40 | 41 | @pytest.mark.xfail(raises=ValidationError) 42 | def test__missing_detuning(): 43 | DrivingField(amplitude=valid_atom_field, phase=valid_atom_field) 44 | -------------------------------------------------------------------------------- /test/unit_tests/braket/task_result/test_simulator_metadata_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.task_result.simulator_metadata_v1 import SimulatorMetadata 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_properties(): 22 | SimulatorMetadata() 23 | 24 | 25 | def test_simulator_metadata_correct(execution_duration): 26 | metadata = SimulatorMetadata(executionDuration=execution_duration) 27 | assert metadata.executionDuration == execution_duration 28 | assert SimulatorMetadata.parse_raw(metadata.json()) == metadata 29 | assert metadata == SimulatorMetadata.parse_raw_schema(metadata.json()) 30 | 31 | 32 | @pytest.mark.xfail(raises=ValidationError) 33 | def test_execution_duration_incorrect(): 34 | execution_duration = -1 35 | SimulatorMetadata(executionDuration=execution_duration) 36 | 37 | 38 | @pytest.mark.xfail(raises=ValidationError) 39 | def test_simulator_header_incorrect(braket_schema_header, execution_duration): 40 | SimulatorMetadata(braketSchemaHeader=braket_schema_header, executionDuration=execution_duration) 41 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_device_connectivity.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.device_connectivity import DeviceConnectivity 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": {"name": "braket.device_schema.device_connectivity", "version": "1"}, 26 | "fullyConnected": False, 27 | "connectivityGraph": {"1": ["2", "3"]}, 28 | } 29 | return input 30 | 31 | 32 | def test_valid(valid_input): 33 | result = DeviceConnectivity.parse_raw(json.dumps(valid_input)) 34 | assert result.connectivityGraph == {"1": ["2", "3"]} 35 | 36 | 37 | @pytest.mark.xfail(raises=ValidationError) 38 | def test_missing_fully_connected(valid_input): 39 | valid_input.pop("fullyConnected") 40 | assert DeviceConnectivity.parse_raw(json.dumps(valid_input)) 41 | 42 | 43 | @pytest.mark.xfail(raises=ValidationError) 44 | def test_missing_graphy(valid_input): 45 | valid_input.pop("connectivityGraph") 46 | DeviceConnectivity.parse_raw(json.dumps(valid_input)) 47 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/ahs/test_atom_arrangement.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.ir.ahs.atom_arrangement import AtomArrangement 20 | 21 | valid_site_input = [ 22 | [Decimal(0.0), Decimal(0.0)], 23 | [Decimal(0.0), Decimal(3.0e-6)], 24 | [Decimal(0.0), Decimal(6.0e-6)], 25 | [Decimal(3.0e-6), Decimal(0.0)], 26 | [Decimal(3.0e-6), Decimal(3.0e-6)], 27 | [Decimal(3.0e-6), Decimal(6.0e-6)], 28 | ] 29 | valid_filling = [Decimal(1), Decimal(1), Decimal(1), Decimal(1), Decimal(0), Decimal(0)] 30 | 31 | 32 | def test_valid(): 33 | atom_array = AtomArrangement(sites=valid_site_input, filling=valid_filling) 34 | assert atom_array.sites == valid_site_input 35 | assert atom_array.filling == valid_filling 36 | 37 | 38 | @pytest.mark.xfail(raises=ValidationError) 39 | def test__missing_sites(): 40 | AtomArrangement( 41 | filling=valid_filling, 42 | ) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test__missing_filling(): 47 | AtomArrangement( 48 | sites=valid_site_input, 49 | ) 50 | -------------------------------------------------------------------------------- /src/braket/device_schema/dwave/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from braket.device_schema.dwave.dwave_2000Q_device_level_parameters_v1 import ( # noqa: F401 15 | Dwave2000QDeviceLevelParameters, 16 | ) 17 | from braket.device_schema.dwave.dwave_2000Q_device_parameters_v1 import ( # noqa: F401 18 | Dwave2000QDeviceParameters, 19 | ) 20 | from braket.device_schema.dwave.dwave_advantage_device_level_parameters_v1 import ( # noqa: F401 21 | DwaveAdvantageDeviceLevelParameters, 22 | ) 23 | from braket.device_schema.dwave.dwave_advantage_device_parameters_v1 import ( # noqa: F401 24 | DwaveAdvantageDeviceParameters, 25 | ) 26 | from braket.device_schema.dwave.dwave_device_capabilities_v1 import ( # noqa: F401 27 | DwaveDeviceCapabilities, 28 | ) 29 | from braket.device_schema.dwave.dwave_device_parameters_v1 import ( # noqa: F401 30 | DwaveDeviceParameters, 31 | ) 32 | from braket.device_schema.dwave.dwave_provider_level_parameters_v1 import ( # noqa: F401 33 | DwaveProviderLevelParameters, 34 | PostProcessingType, 35 | ResultFormat, 36 | ) 37 | from braket.device_schema.dwave.dwave_provider_properties_v1 import ( # noqa: F401 38 | DwaveProviderProperties, 39 | ) 40 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_two_dimensional_matrix.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import TwoDimensionalMatrix 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_targets(): 22 | TwoDimensionalMatrix() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | TwoDimensionalMatrix(matrix=[[0, "foo"]]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_empty_nested_list(): 32 | TwoDimensionalMatrix(matrix=[[]]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_element_list_size_gt_two(): 37 | TwoDimensionalMatrix(matrix=[[[0, 1, 2]]]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | TwoDimensionalMatrix(matrix=[]) 43 | 44 | 45 | def test_list_gte_zero(): 46 | matrix = [[[1.0, 0], [0, 1]], [[0.0, 1], [1, 0]]] 47 | obj = TwoDimensionalMatrix(matrix=matrix) 48 | assert obj.matrix == matrix 49 | 50 | 51 | def test_list_extra_params(): 52 | TwoDimensionalMatrix(matrix=[[[1.0, 0], [0, 1]], [[0.0, 1], [1, 0]]], foo="bar") 53 | -------------------------------------------------------------------------------- /.github/scripts/update_dependency.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import fileinput 15 | from pathlib import Path 16 | 17 | # Here we replace the `amazon-braket-schemas` dependency to point to the file 18 | # system; otherwise pip will install them separately, allowing it to override the version of 19 | # any mutual dependencies with the schemas. By pointing to the file system, pip will be 20 | # forced to reconcile the dependencies in setup.py with the dependencies of the schemas, 21 | # and raise an error if there are conflicts. While we can't do this for every upstream 22 | # dependency, we can do this for the ones we own to make sure that when the schema updates 23 | # its dependencies, these upstream github repos will not be impacted. 24 | 25 | package = "amazon-braket-schemas" 26 | path = Path.cwd().parent.resolve() 27 | 28 | for line in fileinput.input("setup.py", inplace=True): 29 | # Update the amazon-braket-default-simulator dependency in setup.py to use the local path. This 30 | # would help catch conflicts during the installation process. 31 | replaced_line = ( 32 | line if package not in line else f'"{package} @ file://{path}/{package}-python",\n' 33 | ) 34 | print(replaced_line, end="") 35 | -------------------------------------------------------------------------------- /src/braket/ir/jaqcd/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from braket.ir.jaqcd.instructions import ( # noqa: F401 15 | CV, 16 | CY, 17 | CZ, 18 | ECR, 19 | XX, 20 | XY, 21 | YY, 22 | ZZ, 23 | AmplitudeDamping, 24 | BitFlip, 25 | CCNot, 26 | CNot, 27 | CPhaseShift, 28 | CPhaseShift00, 29 | CPhaseShift01, 30 | CPhaseShift10, 31 | CSwap, 32 | Depolarizing, 33 | EndVerbatimBox, 34 | GeneralizedAmplitudeDamping, 35 | H, 36 | I, 37 | ISwap, 38 | Kraus, 39 | MultiQubitPauliChannel, 40 | PauliChannel, 41 | PhaseDamping, 42 | PhaseFlip, 43 | PhaseShift, 44 | PSwap, 45 | Rx, 46 | Ry, 47 | Rz, 48 | S, 49 | Si, 50 | StartVerbatimBox, 51 | Swap, 52 | T, 53 | Ti, 54 | TwoQubitDephasing, 55 | TwoQubitDepolarizing, 56 | Unitary, 57 | V, 58 | Vi, 59 | X, 60 | Y, 61 | Z, 62 | ) 63 | from braket.ir.jaqcd.program_v1 import Program # noqa: F401 64 | from braket.ir.jaqcd.results import ( # noqa: F401 65 | AdjointGradient, 66 | Amplitude, 67 | DensityMatrix, 68 | Expectation, 69 | Probability, 70 | Sample, 71 | StateVector, 72 | Variance, 73 | ) 74 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/driving_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel 15 | 16 | from braket.ir.ahs.physical_field import PhysicalField 17 | 18 | 19 | class DrivingField(BaseModel): 20 | r"""Specifies the driving field, defined by the formula 21 | 22 | .. math:: 23 | H_{drive} (t) := \frac{\Omega(t)}{2} e^{i \phi(t)} \left( 24 | \sum_k |g_k \rangle \langle r_k| + |r_k \rangle \langle g_k| 25 | \right) - \Delta(t) \sum_k{| r_k \rangle \langle r_k |} 26 | 27 | where 28 | 29 | :math:`\Omega(t)` is the global Rabi frequency in rad/s, 30 | 31 | :math:`\phi(t)` is the global phase in rad/s, 32 | 33 | :math:`\Delta(t)` is the global detuning in rad/s, 34 | 35 | :math:`|g_k \rangle` is the ground state of atom k, 36 | 37 | :math:`|r_k \rangle` is the Rydberg state of atom k. 38 | 39 | with the sum :math:`\sum_k` taken over all target atoms. 40 | 41 | Attributes: 42 | amplitude: PhysicalField(pattern=“uniform”) 43 | phase: PhysicalField(pattern=“uniform”) 44 | detuning: PhysicalField(pattern=“uniform”) 45 | """ 46 | 47 | amplitude: PhysicalField 48 | phase: PhysicalField 49 | detuning: PhysicalField 50 | -------------------------------------------------------------------------------- /src/braket/device_schema/xanadu/xanadu_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | 15 | from pydantic.v1 import Field 16 | 17 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 18 | 19 | 20 | class XanaduDeviceParameters(BraketSchemaBase): 21 | """ 22 | This defines the parameters common to all the Xanadu devices. 23 | 24 | Attributes: 25 | paradigmParameters: Parameters that are common to photonic devices 26 | gateParameters: A dictionary of gate parameters to two numbers representing 27 | the lower and upper bound for each parameter. 28 | target: Device name 29 | Examples: 30 | >>> import json 31 | >>> input_json = { 32 | ... "braketSchemaHeader": { 33 | ... "name": "braket.device_schema.xanadu.xanadu_device_parameters", 34 | ... "version": "1", 35 | ... }, 36 | ... } 37 | >>> XanaduDeviceParameters.parse_raw_schema(json.dumps(input_json)) 38 | """ 39 | 40 | _PROGRAM_HEADER = BraketSchemaHeader( 41 | name="braket.device_schema.xanadu.xanadu_device_parameters", version="1" 42 | ) 43 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 44 | -------------------------------------------------------------------------------- /src/braket/device_schema/simulators/gate_model_simulator_paradigm_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field, conint 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class GateModelSimulatorParadigmProperties(BraketSchemaBase): 20 | """ 21 | This class defines the properties that are specific to simulator device 22 | 23 | Attributes: 24 | qubitCount: number of qubits simulator device contains 25 | 26 | Examples: 27 | >>> import json 28 | >>> input_json = { 29 | ... "braketSchemaHeader": { 30 | ... "name": 31 | ... "braket.device_schema.simulators.gate_model_simulator_paradigm_properties", 32 | ... "version": "1", 33 | ... }, 34 | ... "qubitCount": 32 35 | ... } 36 | >>> GateModelSimulatorParadigmProperties.parse_raw_schema(json.dumps(input_json)) 37 | 38 | """ 39 | 40 | _PROGRAM_HEADER = BraketSchemaHeader( 41 | name="braket.device_schema.simulators.gate_model_simulator_paradigm_properties", version="1" 42 | ) 43 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 44 | qubitCount: conint(ge=0) 45 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.device_action_properties import DeviceActionProperties 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "actionType": "braket.ir.jaqcd.program", 26 | "version": ["1"], 27 | } 28 | return input 29 | 30 | 31 | def test_valid(valid_input): 32 | result = DeviceActionProperties.parse_raw(json.dumps(valid_input)) 33 | assert result.actionType == "braket.ir.jaqcd.program" 34 | 35 | 36 | def test_valid_str_invalid_enum(valid_input): 37 | valid_input["actionType"] = "blah" 38 | result = DeviceActionProperties.parse_raw(json.dumps(valid_input)) 39 | assert result.actionType == "blah" 40 | 41 | 42 | @pytest.mark.xfail(raises=ValidationError) 43 | def test__missing_actionType(valid_input): 44 | valid_input.pop("actionType") 45 | DeviceActionProperties.parse_raw(json.dumps(valid_input)) 46 | 47 | 48 | @pytest.mark.xfail(raises=ValidationError) 49 | def test__missing_version(valid_input): 50 | valid_input.pop("version") 51 | DeviceActionProperties.parse_raw(json.dumps(valid_input)) 52 | -------------------------------------------------------------------------------- /src/braket/device_schema/iqm/iqm_provider_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import TypeVar, Union 15 | 16 | from pydantic.v1 import Field 17 | 18 | from braket.schema_common.schema_base import BraketSchemaBase 19 | from braket.schema_common.schema_header import BraketSchemaHeader 20 | 21 | GateFidelityType = TypeVar("GateFidelityType", bound=dict[str, Union[str, float]]) 22 | OneQubitType = TypeVar("OneQubitType", bound=Union[float, list[GateFidelityType]]) 23 | TwoQubitType = TypeVar("TwoQubitType", bound=dict[str, Union[float, dict[str, int]]]) 24 | 25 | QubitType = TypeVar("QubitType", bound=dict[str, Union[OneQubitType, TwoQubitType]]) 26 | 27 | 28 | class IqmProviderProperties(BraketSchemaBase): 29 | """ 30 | This defines the properties common to all the IQM devices. 31 | 32 | Attributes: 33 | properties (dict[str, dict[str, QubitType]]): Basic specifications for 34 | the device, such as gate fidelities and coherence times. 35 | """ 36 | 37 | _PROGRAM_HEADER = BraketSchemaHeader( 38 | name="braket.device_schema.iqm.iqm_provider_properties", version="1" 39 | ) 40 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 41 | properties: dict[str, dict[str, QubitType]] 42 | -------------------------------------------------------------------------------- /src/braket/device_schema/blackbird_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | 15 | from pydantic.v1 import conlist, constr 16 | 17 | from braket.device_schema.device_action_properties import DeviceActionProperties 18 | from braket.device_schema.result_type import ResultType 19 | 20 | 21 | class BlackbirdDeviceActionProperties(DeviceActionProperties): 22 | """ 23 | Defines the schema for properties for the actions that can be 24 | supported by devices that accept Blackbird IR. 25 | 26 | Attributes: 27 | supportedOperations: Operations supported by the Blackbird action. 28 | supportedResultTypes: Result types that are supported by the Blackbird action. 29 | 30 | 31 | Examples: 32 | >>> import json 33 | >>> input_json = { 34 | ... "actionType": "braket.ir.blackbird.program", 35 | ... "version": ["1"], 36 | ... "supportedOperations": [ BSGate, XGate, ZGate], 37 | ... "supportedResultTypes": [], 38 | ... } 39 | >>> BlackbirdDeviceActionProperties.parse_raw(json.dumps(input_json)) 40 | 41 | """ 42 | 43 | actionType: constr(regex=r"^braket\.ir\.blackbird\.program$") 44 | supportedOperations: list[str] 45 | supportedResultTypes: conlist(ResultType, max_items=0) 46 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/openqasm/test_openqasm_program_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # # or in the "license" file accompanying this file. This file is 9 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 10 | # ANY KIND, either express or implied. See the License for the specific 11 | # language governing permissions and limitations under the License. 12 | 13 | import pytest 14 | from pydantic.v1 import ValidationError 15 | 16 | from braket.ir.openqasm.program_v1 import Program as OpenQASMProgram 17 | 18 | 19 | @pytest.mark.xfail(raises=ValidationError) 20 | def test_missing_source_property(): 21 | OpenQASMProgram() 22 | 23 | 24 | def test_arbitrary_openqasm_program(): 25 | obj = OpenQASMProgram(source="this is a string.") 26 | assert obj.braketSchemaHeader.name == "braket.ir.openqasm.program" 27 | assert obj.source == "this is a string." 28 | 29 | 30 | def test_parse_obj(): 31 | obj = OpenQASMProgram(source="this is a string.") 32 | assert obj == OpenQASMProgram.parse_obj(obj.dict()) 33 | 34 | 35 | def test_parse_raw(): 36 | obj = OpenQASMProgram(source="this is a string.") 37 | assert obj == OpenQASMProgram.parse_raw(obj.json()) 38 | 39 | 40 | @pytest.mark.parametrize( 41 | "inputs", 42 | [ 43 | { 44 | "input_1": "abc", 45 | }, 46 | { 47 | "input_1": float("nan"), 48 | }, 49 | ], 50 | ) 51 | @pytest.mark.xfail(raises=ValidationError) 52 | def test_openqasm_program_with_invalid_input_value_should_raise_validation_error(inputs): 53 | OpenQASMProgram(inputs=inputs) 54 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/simulator/test_gate_model_simulator_paradigm_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.simulators.gate_model_simulator_paradigm_properties_v1 import ( 20 | GateModelSimulatorParadigmProperties, 21 | ) 22 | 23 | 24 | @pytest.fixture(scope="module") 25 | def valid_input(): 26 | input = { 27 | "braketSchemaHeader": { 28 | "name": "braket.device_schema.simulators.gate_model_simulator_paradigm_properties", 29 | "version": "1", 30 | }, 31 | "qubitCount": 32, 32 | } 33 | return input 34 | 35 | 36 | def test_valid(valid_input): 37 | assert GateModelSimulatorParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test__missing_schemaHeader(valid_input): 42 | valid_input.pop("braketSchemaHeader") 43 | GateModelSimulatorParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 44 | 45 | 46 | @pytest.mark.xfail(raises=ValidationError) 47 | def test__missing_qubitCount(valid_input): 48 | valid_input.pop("qubitCount") 49 | GateModelSimulatorParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 50 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_double_target.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import DoubleTarget 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_targets(): 22 | DoubleTarget() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | DoubleTarget(targets=[0, "foo"]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_list_lt_zero(): 32 | DoubleTarget(targets=[-1, -2]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_list_partial_lt_zero(): 37 | DoubleTarget(targets=[0, -1]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | DoubleTarget(targets=[]) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_list_of_1(): 47 | DoubleTarget(targets=[1]) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_list_of_3(): 52 | DoubleTarget(targets=[1, 2, 3]) 53 | 54 | 55 | def test_list_gte_zero(): 56 | targets = [0, 1] 57 | obj = DoubleTarget(targets=targets) 58 | assert obj.targets == targets 59 | 60 | 61 | def test_list_extra_params(): 62 | DoubleTarget(targets=[0, 1], foo="bar") 63 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_double_control.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import DoubleControl 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_controls(): 22 | DoubleControl() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | DoubleControl(controls=[0, "foo"]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_list_lt_zero(): 32 | DoubleControl(controls=[-1, -2]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_list_partial_lt_zero(): 37 | DoubleControl(controls=[0, -1]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | DoubleControl(controls=[]) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_list_of_1(): 47 | DoubleControl(controls=[1]) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_list_of_3(): 52 | DoubleControl(controls=[1, 2, 3]) 53 | 54 | 55 | def test_list_gte_zero(): 56 | controls = [0, 1] 57 | obj = DoubleControl(controls=controls) 58 | assert obj.controls == controls 59 | 60 | 61 | def test_list_extra_params(): 62 | DoubleControl(controls=[0, 1], foo="bar") 63 | -------------------------------------------------------------------------------- /src/braket/device_schema/device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from enum import Enum 15 | from typing import Union 16 | 17 | from pydantic.v1 import BaseModel 18 | 19 | 20 | class DeviceActionType(str, Enum): 21 | """ 22 | These are the actions supported by Braket. 23 | """ 24 | 25 | OPENQASM = "braket.ir.openqasm.program" 26 | OPENQASM_PROGRAM_SET = "braket.ir.openqasm.program_set" 27 | JAQCD = "braket.ir.jaqcd.program" 28 | BLACKBIRD = "braket.ir.blackbird.program" 29 | ANNEALING = "braket.ir.annealing.problem" 30 | AHS = "braket.ir.ahs.program" 31 | 32 | 33 | class DeviceActionProperties(BaseModel): 34 | """ 35 | This class defines the actions that can be performed by a device 36 | 37 | Attributes: 38 | version (list[str]): List of versions for the actions the device supports 39 | actionType (Union[DeviceActionType, str]): Enum for the action type. 40 | Type of the action to be performed. 41 | 42 | Examples: 43 | >>> import json 44 | >>> input_json = { 45 | ... "actionType": "braket.ir.jaqcd.program", 46 | ... "version": ["1"], 47 | ... } 48 | >>> DeviceActionProperties.parse_raw(json.dumps(input_json)) 49 | """ 50 | 51 | version: list[str] 52 | actionType: Union[DeviceActionType, str] 53 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/iqm/test_iqm_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.iqm.iqm_device_parameters_v1 import IqmDeviceParameters 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.iqm.iqm_device_parameters", 27 | "version": "1", 28 | }, 29 | "paradigmParameters": { 30 | "braketSchemaHeader": { 31 | "name": "braket.device_schema.gate_model_parameters", 32 | "version": "1", 33 | }, 34 | "qubitCount": 20, 35 | }, 36 | } 37 | return input 38 | 39 | 40 | def test_valid(valid_input): 41 | result = IqmDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 42 | assert result.braketSchemaHeader.name == "braket.device_schema.iqm.iqm_device_parameters" 43 | 44 | 45 | @pytest.mark.parametrize("missing_field", ["braketSchemaHeader", "paradigmParameters"]) 46 | def test__missing_paradigmProperties(valid_input, missing_field): 47 | with pytest.raises(ValidationError): 48 | valid_input.pop(missing_field) 49 | IqmDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 50 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/oqc/test_oqc_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.oqc.oqc_device_parameters_v1 import OqcDeviceParameters 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.oqc.oqc_device_parameters", 27 | "version": "1", 28 | }, 29 | "paradigmParameters": { 30 | "braketSchemaHeader": { 31 | "name": "braket.device_schema.gate_model_parameters", 32 | "version": "1", 33 | }, 34 | "qubitCount": 1, 35 | }, 36 | } 37 | return input 38 | 39 | 40 | def test_valid(valid_input): 41 | result = OqcDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 42 | assert result.braketSchemaHeader.name == "braket.device_schema.oqc.oqc_device_parameters" 43 | 44 | 45 | @pytest.mark.parametrize("missing_field", ["braketSchemaHeader", "paradigmParameters"]) 46 | def test__missing_paradigmProperties(valid_input, missing_field): 47 | with pytest.raises(ValidationError): 48 | valid_input.pop(missing_field) 49 | OqcDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 50 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_blackbird_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.blackbird_device_action_properties import BlackbirdDeviceActionProperties 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "actionType": "braket.ir.blackbird.program", 26 | "version": ["1"], 27 | "supportedOperations": ["BSGate", "XGate"], 28 | "supportedResultTypes": [], 29 | } 30 | return input 31 | 32 | 33 | def test_valid(valid_input): 34 | result = BlackbirdDeviceActionProperties.parse_raw(json.dumps(valid_input)) 35 | assert result.actionType == "braket.ir.blackbird.program" 36 | assert result.supportedOperations == ["BSGate", "XGate"] 37 | assert result.supportedResultTypes == [] 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_missing_action_type(valid_input): 42 | valid_input.pop("actionType") 43 | BlackbirdDeviceActionProperties.parse_raw(json.dumps(valid_input)) 44 | 45 | 46 | @pytest.mark.xfail(raises=ValidationError) 47 | def test_invalid_supported_operations(valid_input): 48 | valid_input.pop("supportedOperations") 49 | BlackbirdDeviceActionProperties.parse_raw(json.dumps(valid_input)) 50 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_damping_probability.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import DampingProbability 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_probability(): 22 | DampingProbability() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_float(): 27 | DampingProbability(gamma="foo") 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_nan_float(): 32 | DampingProbability(gamma=float("nan")) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_inf_float(): 37 | DampingProbability(gamma=float("inf")) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_negative_inf_float(): 42 | DampingProbability(gamma=float("-inf")) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_negative_float(): 47 | DampingProbability(gamma=float(-1.5)) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_greater_than_one_float(): 52 | DampingProbability(gamma=float(2.1)) 53 | 54 | 55 | def test_float(): 56 | gamma = 0.15 57 | obj = DampingProbability(gamma=gamma) 58 | assert obj.gamma == gamma 59 | 60 | 61 | def test_extra_params(): 62 | DampingProbability(gamma=0, foo="bar") 63 | -------------------------------------------------------------------------------- /src/braket/device_schema/oqc/oqc_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 17 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 18 | 19 | 20 | class OqcDeviceParameters(BraketSchemaBase): 21 | """ 22 | This defines the parameters common to all the OQC devices. 23 | 24 | Attributes: 25 | paradigmParameters: Parameters that are common to gatemodel paradigm 26 | 27 | Examples: 28 | >>> import json 29 | >>> input_json = { 30 | ... "braketSchemaHeader": { 31 | ... "name": "braket.device_schema.oqc.oqc_device_parameters", 32 | ... "version": "1", 33 | ... }, 34 | ... "paradigmParameters": {"braketSchemaHeader": { 35 | ... "name": "braket.device_schema.gate_model_parameters", 36 | ... "version": "1", 37 | ... },"qubitCount": 1}, 38 | ... } 39 | >>> OqcDeviceParameters.parse_raw_schema(json.dumps(input_json)) 40 | """ 41 | 42 | _PROGRAM_HEADER = BraketSchemaHeader( 43 | name="braket.device_schema.oqc.oqc_device_parameters", version="1" 44 | ) 45 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 46 | paradigmParameters: GateModelParameters 47 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/ahs/test_physical_field.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from decimal import Decimal 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.ir.ahs.physical_field import PhysicalField 20 | 21 | valid_time_series = {"values": [Decimal(0), Decimal(0)], "times": [Decimal(0.0), Decimal(3.0e-6)]} 22 | valid_pattern_str = "uniform" 23 | valid_pattern_list = [ 24 | Decimal(0.5), 25 | Decimal(1.0), 26 | Decimal(0.5), 27 | Decimal(0.5), 28 | Decimal(0.5), 29 | Decimal(0.5), 30 | ] 31 | 32 | 33 | def test_valid_default_pattern(): 34 | physical_field = PhysicalField(time_series=valid_time_series, pattern=valid_pattern_str) 35 | assert physical_field.time_series == valid_time_series 36 | assert physical_field.pattern == valid_pattern_str 37 | 38 | 39 | def test_valid_list_pattern(): 40 | physical_field = PhysicalField(time_series=valid_time_series, pattern=valid_pattern_list) 41 | assert physical_field.time_series == valid_time_series 42 | assert physical_field.pattern == valid_pattern_list 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test__missing_pattern(): 47 | PhysicalField( 48 | time_series=valid_time_series, 49 | ) 50 | 51 | 52 | @pytest.mark.xfail(raises=ValidationError) 53 | def test__missing_time_series(): 54 | PhysicalField( 55 | pattern=valid_pattern_str, 56 | ) 57 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_probability.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import SingleProbability 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_probability(): 22 | SingleProbability() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_float(): 27 | SingleProbability(probability="foo") 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_nan_float(): 32 | SingleProbability(probability=float("nan")) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_inf_float(): 37 | SingleProbability(probability=float("inf")) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_negative_inf_float(): 42 | SingleProbability(probability=float("-inf")) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_negative_float(): 47 | SingleProbability(probability=float(-1.5)) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_greater_than_one_float(): 52 | SingleProbability(probability=float(2.1)) 53 | 54 | 55 | def test_float(): 56 | probability = 0.15 57 | obj = SingleProbability(probability=probability) 58 | assert obj.probability == probability 59 | 60 | 61 | def test_extra_params(): 62 | SingleProbability(probability=0, foo="bar") 63 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/annealing/test_problem_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.annealing.problem_v1 import Problem, ProblemType 18 | 19 | 20 | def test_creation(): 21 | problem = Problem( 22 | type=ProblemType.QUBO, 23 | linear={0: 0.3333, 1: -0.333, 4: -0.333, 5: 0.333}, 24 | quadratic={"0,4": 0.667, "0,5": -1, "1,4": 0.667, "1,5": 0.667}, 25 | ) 26 | assert problem.type == ProblemType.QUBO 27 | assert problem.linear == {0: 0.3333, 1: -0.333, 4: -0.333, 5: 0.333} 28 | assert problem.quadratic == {"0,4": 0.667, "0,5": -1, "1,4": 0.667, "1,5": 0.667} 29 | assert Problem.parse_raw(problem.json()) == problem 30 | assert problem == Problem.parse_raw_schema(problem.json()) 31 | 32 | 33 | @pytest.mark.xfail(raises=ValidationError) 34 | def test__missing_type(): 35 | Problem( 36 | linear={0: 0.3333, 1: -0.333, 4: -0.333, 5: 0.333}, 37 | quadratic={"0,4": 0.667, "0,5": -1, (1, 4): 0.667, "1,5": 0.667}, 38 | ) 39 | 40 | 41 | @pytest.mark.xfail(raises=ValidationError) 42 | def test_missing_linear(): 43 | Problem(type=ProblemType.QUBO, quadratic={"0,4": 0.667, "0,5": -1, "1,4": 0.667, "1,5": 0.667}) 44 | 45 | 46 | @pytest.mark.xfail(raises=ValidationError) 47 | def test_missing_quadratic(): 48 | Problem(type=ProblemType.ISING, linear={0: 0.3333, 1: -0.333, 4: -0.333, 5: 0.333}) 49 | -------------------------------------------------------------------------------- /src/braket/device_schema/gate_model_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field, conint 15 | 16 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 17 | 18 | 19 | class GateModelParameters(BraketSchemaBase): 20 | """ 21 | Defines parameters common to all gate model devices. 22 | 23 | Attributes: 24 | qubitCount: Number of qubits used by the circuit. 25 | disableQubitRewiring: Whether to run the circuit with the exact qubits chosen, 26 | without any rewiring downstream. 27 | If ``True``, no qubit rewiring is allowed; if ``False``, qubit rewiring is allowed. 28 | 29 | Examples: 30 | >>> import json 31 | >>> input_json = { 32 | ... "braketSchemaHeader": { 33 | ... "name": "braket.device_schema.gate_model_parameters", 34 | ... "version": "1", 35 | ... }, 36 | ... "qubitCount": 1, 37 | ... "disableQubitRewiring": True 38 | ... } 39 | >>> GateModelParameters.parse_raw_schema(json.dumps(input_json)) 40 | """ 41 | 42 | _PROGRAM_HEADER = BraketSchemaHeader( 43 | name="braket.device_schema.gate_model_parameters", version="1" 44 | ) 45 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 46 | qubitCount: conint(strict=True, ge=0) 47 | disableQubitRewiring: bool = False 48 | -------------------------------------------------------------------------------- /src/braket/device_schema/rigetti/rigetti_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 17 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 18 | 19 | 20 | class RigettiDeviceParameters(BraketSchemaBase): 21 | """ 22 | This defines the parameters common to all the Rigetti devices. 23 | 24 | Attributes: 25 | paradigmParameters: Parameters that are common to gatemodel paradigm 26 | 27 | Examples: 28 | >>> import json 29 | >>> input_json = { 30 | ... "braketSchemaHeader": { 31 | ... "name": "braket.device_schema.rigetti.rigetti_device_parameters", 32 | ... "version": "1", 33 | ... }, 34 | ... "paradigmParameters": {"braketSchemaHeader": { 35 | ... "name": "braket.device_schema.gate_model_parameters", 36 | ... "version": "1", 37 | ... },"qubitCount": 1}, 38 | ... } 39 | >>> RigettiDeviceParameters.parse_raw_schema(json.dumps(input_json)) 40 | """ 41 | 42 | _PROGRAM_HEADER = BraketSchemaHeader( 43 | name="braket.device_schema.rigetti.rigetti_device_parameters", version="1" 44 | ) 45 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 46 | paradigmParameters: GateModelParameters 47 | -------------------------------------------------------------------------------- /bin/apply-header.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | """ 4 | Run from the root of the git repository, will apply contents of header to the beginning of 5 | all *.py files in the chosen directories. Script is idempotent, meaning it won't apply the 6 | header to a file that already contains it. 7 | 8 | Usage: python bin/apply-header.py 9 | """ 10 | 11 | HEADER = """# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 12 | # 13 | # Licensed under the Apache License, Version 2.0 (the "License"). You 14 | # may not use this file except in compliance with the License. A copy of 15 | # the License is located at 16 | # 17 | # http://aws.amazon.com/apache2.0/ 18 | # 19 | # or in the "license" file accompanying this file. This file is 20 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 21 | # ANY KIND, either express or implied. See the License for the specific 22 | # language governing permissions and limitations under the License. 23 | 24 | """ 25 | 26 | ROOT_DIRS = ["src", "test", "."] 27 | 28 | 29 | def main(): 30 | for root_dir in ROOT_DIRS: 31 | for root, dirs, files in os.walk(root_dir): 32 | for py_file in python_files(files): 33 | idempotent_prepend(os.path.join(root, py_file), HEADER) 34 | 35 | # don't recurse "." directory, just look at local files 36 | if root_dir == ".": 37 | break 38 | 39 | 40 | def python_files(files): 41 | return [file for file in files if file.endswith("py")] 42 | 43 | 44 | def idempotent_prepend(filename: str, new_content: str) -> None: 45 | with open(filename, "r+") as file: 46 | existing_content = file.read() 47 | 48 | if existing_content.startswith(new_content): 49 | print(f"Skipping {filename}, already contains the content.") 50 | else: 51 | print(f"Applying content to {filename}...") 52 | file.seek(0, 0) 53 | file.write(new_content + existing_content) 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/hamiltonian.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import BaseModel, Field 15 | 16 | from braket.ir.ahs.driving_field import DrivingField 17 | from braket.ir.ahs.local_detuning import LocalDetuning 18 | 19 | 20 | class Hamiltonian(BaseModel): 21 | """ 22 | Specifies the Hamiltonian 23 | 24 | Attributes: 25 | drivingFields: An externally controlled force 26 | that drives coherent transitions between selected levels of certain atom types 27 | localDetuning: An externally controlled polarizing force 28 | the effect of which is accurately described by a frequency shift of certain levels. 29 | 30 | Examples: 31 | >>> Hamiltonian(drivingFields=[DrivingField],localDetuning=[LocalDetuning]) 32 | """ 33 | 34 | drivingFields: list[DrivingField] 35 | localDetuning: list[LocalDetuning] = Field(alias="shiftingFields") 36 | 37 | def __getattr__(self, name): 38 | return self.__dict__[name] if name != "shiftingFields" else self.__dict__["localDetuning"] 39 | 40 | def __setattr__(self, name, value): 41 | if name == "shiftingFields": 42 | name = "localDetuning" 43 | self.__dict__[name] = value 44 | 45 | def __delattr__(self, name): 46 | if name == "shiftingFields": 47 | name = "localDetuning" 48 | del self.__dict__[name] 49 | 50 | class Config: 51 | allow_population_by_field_name = True 52 | -------------------------------------------------------------------------------- /src/braket/ir/openqasm/program_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from typing import Optional, Union 15 | 16 | from pydantic.v1 import Field, confloat, constr 17 | 18 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 19 | 20 | # support 1d array input for now 21 | leaf_io_type = Union[ 22 | constr(regex="^[01]+$", min_length=1, strict=True), confloat(ge=-float("inf"), strict=True), int 23 | ] 24 | io_type = Union[leaf_io_type, list[leaf_io_type]] 25 | 26 | 27 | class Program(BraketSchemaBase): 28 | """ 29 | Root object of the OpenQASM IR. 30 | 31 | Attributes: 32 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 33 | to set this value. Only default is allowed. 34 | source (str): OpenQASM source program. 35 | inputs (Dict): Inputs for the OpenQASM program. 36 | 37 | Examples: 38 | >>> Program(source='OPENQASM 3.0; cx $0, $1') 39 | >>> Program(source='OPENQASM 3.0; input float alpha; qubit[2] q; bit[2] c; \ 40 | rx(alpha) q[0]; h q[0]; cx q[0], q[1]; c = measure q;', inputs={"alpha": 0.0}) 41 | """ 42 | 43 | _PROGRAM_HEADER = BraketSchemaHeader(name="braket.ir.openqasm.program", version="1") 44 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 45 | source: str 46 | inputs: Optional[ 47 | dict[ 48 | constr(min_length=1), 49 | io_type, 50 | ] 51 | ] 52 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/xanadu/test_xanadu_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.xanadu.xanadu_device_parameters_v1 import XanaduDeviceParameters 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.xanadu.xanadu_device_parameters", 27 | "version": "1", 28 | }, 29 | "paradigmParameters": { 30 | "braketSchemaHeader": { 31 | "name": "braket.device_schema.photonic_model_parameters", 32 | "version": "1", 33 | }, 34 | }, 35 | } 36 | return input 37 | 38 | 39 | def test_valid(valid_input): 40 | result = XanaduDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 41 | assert result.braketSchemaHeader.name == "braket.device_schema.xanadu.xanadu_device_parameters" 42 | 43 | 44 | def test_missing_schemaHeader(valid_input): 45 | valid_input.pop("braketSchemaHeader") 46 | with pytest.raises(ValidationError): 47 | XanaduDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 48 | 49 | 50 | def test_missing_paradigmProperties(valid_input): 51 | valid_input.pop("paradigmParameters") 52 | with pytest.raises(ValidationError): 53 | XanaduDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 54 | -------------------------------------------------------------------------------- /src/braket/ir/ahs/program_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | 15 | from decimal import Decimal 16 | 17 | from pydantic.v1 import BaseModel, Field 18 | 19 | from braket.ir.ahs.atom_arrangement import AtomArrangement 20 | from braket.ir.ahs.hamiltonian import Hamiltonian 21 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 22 | 23 | 24 | class Setup(BaseModel): 25 | """ 26 | The initial setup of the quantum register 27 | Attributes: 28 | ahs_register: The spatial setup of the neutral atom program 29 | """ 30 | 31 | ahs_register: AtomArrangement 32 | 33 | 34 | class Program(BraketSchemaBase): 35 | """Specifies an AHS program 36 | 37 | Attributes: 38 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 39 | to set this value. Only default is allowed 40 | setup: Neutral atom lattice set up 41 | hamiltonian: rydberg hamiltonian 42 | 43 | Examples: 44 | >>> Program( 45 | ... setup={"ahs_register":AtomArrangement}, 46 | ... hamiltonian={"drivingFields":DrivingField,"localDetuning":LocalDetuning} 47 | ... ) 48 | """ 49 | 50 | _PROGRAM_HEADER = BraketSchemaHeader(name="braket.ir.ahs.program", version="1") 51 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 52 | setup: Setup 53 | hamiltonian: Hamiltonian 54 | 55 | class Config: 56 | json_encoders = {Decimal: str} 57 | -------------------------------------------------------------------------------- /src/braket/device_schema/simulators/gate_model_simulator_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 17 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 18 | 19 | 20 | class GateModelSimulatorDeviceParameters(BraketSchemaBase): 21 | """ 22 | This defines the parameters common to all the gatemodel devices. 23 | 24 | Attributes: 25 | paradigmParameters: Parameters that are common to gatemodel paradigm 26 | 27 | Examples: 28 | >>> import json 29 | >>> input_json = { 30 | ... "braketSchemaHeader": { 31 | ... "name": "braket.device_schema.simulators.gate_model_simulator_device_parameters", 32 | ... "version": "1", 33 | ... }, 34 | ... "paradigmParameters": {"braketSchemaHeader": { 35 | ... "name": "braket.device_schema.gate_model_parameters", 36 | ... "version": "1", 37 | ... },"qubitCount": 1}, 38 | ... } 39 | >>> GateModelSimulatorDeviceParameters.parse_raw_schema(json.dumps(input_json)) 40 | """ 41 | 42 | _PROGRAM_HEADER = BraketSchemaHeader( 43 | name="braket.device_schema.simulators.gate_model_simulator_device_parameters", version="1" 44 | ) 45 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 46 | paradigmParameters: GateModelParameters 47 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/simulator/test_gate_model_simulator_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.simulators.gate_model_simulator_device_parameters_v1 import ( 20 | GateModelSimulatorDeviceParameters, 21 | ) 22 | 23 | 24 | @pytest.fixture(scope="module") 25 | def valid_input(): 26 | input = { 27 | "braketSchemaHeader": { 28 | "name": "braket.device_schema.simulators.gate_model_simulator_device_parameters", 29 | "version": "1", 30 | }, 31 | "paradigmParameters": { 32 | "braketSchemaHeader": { 33 | "name": "braket.device_schema.gate_model_parameters", 34 | "version": "1", 35 | }, 36 | "qubitCount": 1, 37 | }, 38 | } 39 | return input 40 | 41 | 42 | def test_valid(valid_input): 43 | assert GateModelSimulatorDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 44 | 45 | 46 | @pytest.mark.xfail(raises=ValidationError) 47 | def test__missing_schemaHeader(valid_input): 48 | valid_input.pop("braketSchemaHeader") 49 | GateModelSimulatorDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 50 | 51 | 52 | @pytest.mark.xfail(raises=ValidationError) 53 | def test__missing_paradigmProperties(valid_input): 54 | valid_input.pop("paradigmParameters") 55 | GateModelSimulatorDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 56 | -------------------------------------------------------------------------------- /src/braket/task_result/photonic_model_task_result_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import Field, conint, conlist 17 | 18 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 19 | from braket.task_result.additional_metadata import AdditionalMetadata 20 | from braket.task_result.task_metadata_v1 import TaskMetadata 21 | 22 | 23 | class PhotonicModelTaskResult(BraketSchemaBase): 24 | """ 25 | The photonic model task result schema 26 | 27 | Attributes: 28 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 29 | to set this value. Only default is allowed. 30 | measurements (List[List[List[int]]]: List of lists of lists of int, where each 31 | int is bound between 0-255. Default is `None`. 32 | taskMetadata (TaskMetadata): The task metadata 33 | additionalMetadata (AdditionalMetadata): Additional metadata of the task 34 | """ 35 | 36 | _PHOTONIC_MODEL_TASK_RESULT_HEADER = BraketSchemaHeader( 37 | name="braket.task_result.photonic_model_task_result", version="1" 38 | ) 39 | 40 | braketSchemaHeader: BraketSchemaHeader = Field( 41 | default=_PHOTONIC_MODEL_TASK_RESULT_HEADER, const=_PHOTONIC_MODEL_TASK_RESULT_HEADER 42 | ) 43 | measurements: Optional[ 44 | conlist(conlist(conlist(conint(ge=0, le=256), min_items=1), min_items=1), min_items=1) 45 | ] 46 | taskMetadata: TaskMetadata 47 | additionalMetadata: AdditionalMetadata 48 | -------------------------------------------------------------------------------- /src/braket/ir/annealing/problem_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from enum import Enum 15 | from typing import Union 16 | 17 | from pydantic.v1 import Field, conint 18 | 19 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 20 | 21 | 22 | class ProblemType(str, Enum): 23 | """The type of annealing problem. 24 | 25 | QUBO: Quadratic Unconstrained Binary Optimization, with values 1 and 0 26 | ISING: Ising model, with values +/-1 27 | """ 28 | 29 | QUBO = "QUBO" 30 | ISING = "ISING" 31 | 32 | 33 | class Problem(BraketSchemaBase): 34 | """Specifies a quantum annealing problem. 35 | 36 | Attributes: 37 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 38 | to set this value. Only default is allowed. 39 | type (Union[ProblemType, str]): The type of problem; can be either "QUBO" or "ISING" 40 | linear (Dict[int, float]): Linear terms of the model. 41 | quadratic (Dict[str, float]): Quadratic terms of the model, keyed on comma-separated 42 | variables as strings 43 | 44 | Examples: 45 | >>> Problem(type=ProblemType.QUBO, linear={0: 0.3, 4: -0.3}, quadratic={"0,5": 0.667}) 46 | """ 47 | 48 | _PROBLEM_HEADER = BraketSchemaHeader(name="braket.ir.annealing.problem", version="1") 49 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROBLEM_HEADER, const=_PROBLEM_HEADER) 50 | type: Union[ProblemType, str] 51 | linear: dict[conint(ge=0), float] 52 | quadratic: dict[str, float] 53 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/rigetti/test_rigetti_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.rigetti.rigetti_device_parameters_v1 import RigettiDeviceParameters 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.rigetti.rigetti_device_parameters", 27 | "version": "1", 28 | }, 29 | "paradigmParameters": { 30 | "braketSchemaHeader": { 31 | "name": "braket.device_schema.gate_model_parameters", 32 | "version": "1", 33 | }, 34 | "qubitCount": 1, 35 | }, 36 | } 37 | return input 38 | 39 | 40 | def test_valid(valid_input): 41 | result = RigettiDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 42 | assert ( 43 | result.braketSchemaHeader.name == "braket.device_schema.rigetti.rigetti_device_parameters" 44 | ) 45 | 46 | 47 | @pytest.mark.xfail(raises=ValidationError) 48 | def test__missing_schemaHeader(valid_input): 49 | valid_input.pop("braketSchemaHeader") 50 | RigettiDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 51 | 52 | 53 | @pytest.mark.xfail(raises=ValidationError) 54 | def test__missing_paradigmProperties(valid_input): 55 | valid_input.pop("paradigmParameters") 56 | RigettiDeviceParameters.parse_raw_schema(json.dumps(valid_input)) 57 | -------------------------------------------------------------------------------- /src/braket/task_result/program_set_task_result_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Optional, Union 15 | 16 | from pydantic.v1 import Field 17 | 18 | from braket.schema_common.schema_base import BraketSchemaBase 19 | from braket.schema_common.schema_header import BraketSchemaHeader 20 | from braket.task_result.program_result_v1 import ProgramResult 21 | from braket.task_result.program_set_task_metadata_v1 import ProgramSetTaskMetadata 22 | 23 | 24 | class ProgramSetTaskResult(BraketSchemaBase): 25 | """ 26 | The result of a program set task. 27 | 28 | Attributes: 29 | programResults (Union[list[str], list[ProgramResult]]): The relative S3 paths 30 | of the program result files, or a list of the program results themselves. 31 | s3Location (Optional[tuple[str, str]]): The S3 bucket and prefix where this result 32 | and all associated files are saved; blank if all data is inlined in the result file. 33 | taskMetadata (ProgramSetTaskMetadata): The relative S3 paths of the metadata file, 34 | or the task metadata itself. 35 | """ 36 | 37 | _PROGRAM_SET_TASK_RESULT_HEADER = BraketSchemaHeader( 38 | name="braket.task_result.program_set_task_result", version="1" 39 | ) 40 | braketSchemaHeader: BraketSchemaHeader = Field( 41 | default=_PROGRAM_SET_TASK_RESULT_HEADER, const=_PROGRAM_SET_TASK_RESULT_HEADER 42 | ) 43 | 44 | programResults: Union[list[str], list[ProgramResult]] 45 | taskMetadata: Union[str, ProgramSetTaskMetadata] 46 | s3Location: Optional[tuple[str, str]] 47 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_two_dimensional_matrix_list.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import TwoDimensionalMatrixList 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_targets(): 22 | TwoDimensionalMatrixList() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_list_partial_non_int(): 27 | TwoDimensionalMatrixList(matrices=[[0, "foo"]]) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_empty_nested_list(): 32 | TwoDimensionalMatrixList(matrices=[[]]) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_element_list_size_gt_two(): 37 | TwoDimensionalMatrixList(matrices=[[[0, 1, 2]]]) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_empty_list(): 42 | TwoDimensionalMatrixList(matrices=[]) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_single_matrix(): 47 | TwoDimensionalMatrixList( 48 | matrices=[[[1, 0], [0, 0]], [[0, 0], [1, 0]], [[0, 0], [1, 0]], [[1, 0], [0, 0]]] 49 | ) 50 | 51 | 52 | def test_list_gte_zero(): 53 | matrices = [[[[1, 0], [0, 0]], [[0, 0], [1, 0]]], [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]] 54 | obj = TwoDimensionalMatrixList(matrices=matrices) 55 | assert obj.matrices == matrices 56 | 57 | 58 | def test_list_extra_params(): 59 | TwoDimensionalMatrixList( 60 | matrices=[[[[1, 0], [0, 0]], [[0, 0], [1, 0]]], [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]], 61 | foo="bar", 62 | ) 63 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_optional_nested_multi_target.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import OptionalNestedMultiTarget 18 | 19 | 20 | def test_missing_targets(): 21 | OptionalNestedMultiTarget() 22 | 23 | 24 | @pytest.mark.xfail(raises=ValidationError) 25 | def test_list_partial_non_int(): 26 | OptionalNestedMultiTarget(targets=[[0, "foo"]]) 27 | 28 | 29 | @pytest.mark.xfail(raises=ValidationError) 30 | def test_list_partial_non_list(): 31 | OptionalNestedMultiTarget(targets=[[0, 1], 2]) 32 | 33 | 34 | @pytest.mark.xfail(raises=ValidationError) 35 | def test_list_lt_zero(): 36 | OptionalNestedMultiTarget(targets=[[-1, -2]]) 37 | 38 | 39 | @pytest.mark.parametrize("targets", [[[0, -1]], [[0], [-1]]]) 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_list_partial_lt_zero(targets): 42 | OptionalNestedMultiTarget(targets=targets) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_empty_list(): 47 | OptionalNestedMultiTarget(targets=[]) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_empty_inner_list(): 52 | OptionalNestedMultiTarget(targets=[[]]) 53 | 54 | 55 | def test_list_gte_zero(): 56 | targets = [[0, 1], [2]] 57 | obj = OptionalNestedMultiTarget(targets=targets) 58 | assert obj.targets == targets 59 | 60 | 61 | def test_list_extra_params(): 62 | OptionalNestedMultiTarget(targets=[[0, 1], [2]], foo="bar") 63 | 64 | 65 | def test_nested_list(): 66 | OptionalNestedMultiTarget(targets=[[0, 1], [2], [3, 4, 5]]) 67 | -------------------------------------------------------------------------------- /src/braket/schema_common/schema_header.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from importlib import import_module 15 | 16 | from pydantic.v1 import BaseModel, constr 17 | 18 | 19 | class BraketSchemaHeader(BaseModel): 20 | """ 21 | BraketSchemaHeader which dictates the schema and the version. 22 | 23 | Attributes: 24 | name (str): name of the schema 25 | version (str): version of the schema 26 | 27 | Examples: 28 | >>> BraketSchemaHeader(name="braket.task_result.annealing_task_result", version="1.0") 29 | """ 30 | 31 | name: constr(min_length=1) 32 | version: constr(min_length=1, max_length=50) 33 | 34 | def get_module_name(self): 35 | return self.name + "_v" + self.version 36 | 37 | def get_package_name(self): 38 | return ".".join(self.name.split(".")[:-1]) 39 | 40 | def import_schema_module(self): 41 | """ 42 | Imports the module that holds the schema given by the header 43 | 44 | Returns: 45 | Module of the corresponding schema 46 | 47 | Raises: 48 | ModuleNotFoundError: If the schema module cannot be found according to 49 | schema header 50 | """ 51 | module_name = self.get_module_name() 52 | package_name = self.get_package_name() 53 | try: 54 | return import_module(module_name, package=package_name) 55 | except ModuleNotFoundError: 56 | raise ModuleNotFoundError( 57 | f"Amazon Braket could not find the module, {module_name}. " 58 | "To continue, upgrade your installation of amazon-braket-schemas." 59 | ) 60 | -------------------------------------------------------------------------------- /src/braket/task_result/program_set_executable_failure_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from enum import Enum 15 | 16 | from pydantic.v1 import BaseModel, Field 17 | 18 | from braket.schema_common.schema_base import BraketSchemaBase 19 | from braket.schema_common.schema_header import BraketSchemaHeader 20 | 21 | 22 | class FailureCategory(str, Enum): 23 | COMPILATION = "COMPILATION" 24 | DEVICE = "DEVICE" 25 | SERVICE = "SERVICE" 26 | 27 | 28 | class ProgramSetExecutableFailureMetadata(BaseModel): 29 | """ 30 | Attributes: 31 | failureReason (str): The reason stating why the executable failed. 32 | retryable (bool): Indicates whether the executable can be retried. 33 | category (FailureCategory): The enum representing where the executable failed. 34 | """ 35 | 36 | failureReason: str 37 | retryable: bool 38 | category: FailureCategory 39 | 40 | 41 | class ProgramSetExecutableFailure(BraketSchemaBase): 42 | """ 43 | Represents a failed program set executable. 44 | 45 | Attributes: 46 | inputsIndex (int): A reference to the inputs the program was run with. 47 | failureMetadata (ProgramSetExecutableFailureMetadata): Metadata about the failure 48 | of the executable 49 | """ 50 | 51 | _EXECUTABLE_FAILURE_HEADER = BraketSchemaHeader( 52 | name="braket.task_result.program_set_executable_failure", version="1" 53 | ) 54 | braketSchemaHeader: BraketSchemaHeader = Field( 55 | default=_EXECUTABLE_FAILURE_HEADER, const=_EXECUTABLE_FAILURE_HEADER 56 | ) 57 | 58 | inputsIndex: int 59 | failureMetadata: ProgramSetExecutableFailureMetadata 60 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_gate_model_qpu_paradigm_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.gate_model_qpu_paradigm_properties_v1 import ( 20 | GateModelQpuParadigmProperties, 21 | ) 22 | 23 | 24 | @pytest.fixture(scope="module") 25 | def valid_input(): 26 | input = { 27 | "braketSchemaHeader": { 28 | "name": "braket.device_schema.gate_model_qpu_paradigm_properties", 29 | "version": "1", 30 | }, 31 | "qubitCount": 32, 32 | "nativeGateSet": ["ccnot", "cy"], 33 | "connectivity": {"fullyConnected": False, "connectivityGraph": {"1": ["2", "3"]}}, 34 | } 35 | return input 36 | 37 | 38 | def test_valid(valid_input): 39 | result = GateModelQpuParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 40 | assert result.nativeGateSet == ["ccnot", "cy"] 41 | 42 | 43 | @pytest.mark.xfail(raises=ValidationError) 44 | def test__missing_schemaHeader(valid_input): 45 | valid_input.pop("braketSchemaHeader") 46 | GateModelQpuParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 47 | 48 | 49 | @pytest.mark.xfail(raises=ValidationError) 50 | def test__missing_qubitCount(valid_input): 51 | valid_input.pop("qubitCount") 52 | GateModelQpuParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 53 | 54 | 55 | @pytest.mark.xfail(raises=ValidationError) 56 | def test__invalid_connectivity(valid_input): 57 | valid_input["connectivity"]["fullyConnected"] = 1 58 | GateModelQpuParadigmProperties.parse_raw_schema(json.dumps(valid_input)) 59 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/iqm/test_iqm_provider_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.iqm.iqm_provider_properties_v1 import IqmProviderProperties 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.iqm.iqm_provider_properties", 27 | "version": "1", 28 | }, 29 | "properties": { 30 | "one_qubit": { 31 | "1": { 32 | "T1": 3.943757e-05, 33 | "T2": 8.2903e-06, 34 | "T2_echo": 1.523113e-05, 35 | "fRO": 0.9797, 36 | "f1Q_simultaneous_RB": 0.99479, 37 | } 38 | }, 39 | "two_qubit": { 40 | "1-2": { 41 | "fCZ": 0.99479, 42 | "f2Q_simultaneous_RB_Clifford": 0.9991423, 43 | } 44 | }, 45 | }, 46 | } 47 | return input 48 | 49 | 50 | def test_valid(valid_input): 51 | result = IqmProviderProperties.parse_raw_schema(json.dumps(valid_input)) 52 | assert result.braketSchemaHeader.name == "braket.device_schema.iqm.iqm_provider_properties" 53 | 54 | 55 | @pytest.mark.parametrize("missing_field", ["braketSchemaHeader", "properties"]) 56 | def test_missing_field(valid_input, missing_field): 57 | with pytest.raises(ValidationError): 58 | valid_input.pop(missing_field) 59 | IqmProviderProperties.parse_raw_schema(json.dumps(valid_input)) 60 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/dwave/test_dwave_device_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from jsonschema import validate 18 | from pydantic.v1 import ValidationError 19 | 20 | from braket.device_schema.dwave.dwave_device_parameters_v1 import DwaveDeviceParameters 21 | 22 | 23 | def test_valid(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.dwave.dwave_device_parameters", 27 | "version": "1", 28 | }, 29 | "providerLevelParameters": { 30 | "braketSchemaHeader": { 31 | "name": "braket.device_schema.dwave.dwave_provider_level_parameters", 32 | "version": "1", 33 | } 34 | }, 35 | } 36 | assert DwaveDeviceParameters.parse_raw_schema(json.dumps(input)) 37 | 38 | 39 | @pytest.mark.xfail(raises=ValidationError) 40 | def test_missing_header(): 41 | input = '{"providerLevelParameters": {"annealingOffsets": [1]}}' 42 | DwaveDeviceParameters.parse_raw_schema(input) 43 | 44 | 45 | def test_validation(): 46 | input = { 47 | "braketSchemaHeader": { 48 | "name": "braket.device_schema.dwave.dwave_device_parameters", 49 | "version": "1", 50 | }, 51 | "providerLevelParameters": { 52 | "braketSchemaHeader": { 53 | "name": "braket.device_schema.dwave.dwave_provider_level_parameters", 54 | "version": "1", 55 | }, 56 | "autoScale": False, 57 | }, 58 | } 59 | assert DwaveDeviceParameters.parse_raw_schema(json.dumps(input)) 60 | validate(input, DwaveDeviceParameters.schema()) 61 | -------------------------------------------------------------------------------- /src/braket/jobs_data/persisted_job_data_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from enum import Enum 15 | from typing import Any, Union 16 | 17 | from pydantic.v1 import Field 18 | 19 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 20 | 21 | 22 | class PersistedJobDataFormat(str, Enum): 23 | """ 24 | Enum class for the required formats. 25 | """ 26 | 27 | PLAINTEXT = "plaintext" 28 | # Pickle data format with protocol version 4 (Data is base64 encoded after pickling) 29 | PICKLED_V4 = "pickled_v4" 30 | 31 | 32 | class PersistedJobData(BraketSchemaBase): 33 | """ 34 | The schema used for persisting data during Amazon Braket job executions. 35 | 36 | Attributes: 37 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 38 | to set this value. 39 | dataDictionary (dict[str, Any]): Dict representing the data to be persisted. 40 | dataFormat (Union[PersistedJobDataFormat, str]): Data format used for persisting the 41 | values in `dataDictionary`. 42 | 43 | Examples: 44 | >>> data_to_persist = {"some_key": "some_value", "more_keys": True} 45 | >>> PersistedJobData(dataDictionary=data_to_persist, 46 | >>> dataFormat=PersistedJobDataFormat.PLAINTEXT) 47 | """ 48 | 49 | _PERSISTED_JOB_DATA_HEADER = BraketSchemaHeader( 50 | name="braket.jobs_data.persisted_job_data", version="1" 51 | ) 52 | 53 | braketSchemaHeader: BraketSchemaHeader = Field( 54 | default=_PERSISTED_JOB_DATA_HEADER, const=_PERSISTED_JOB_DATA_HEADER 55 | ) 56 | dataDictionary: dict[str, Any] 57 | dataFormat: Union[PersistedJobDataFormat, str] 58 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_gate_model_parameters_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.gate_model_parameters_v1 import GateModelParameters 20 | 21 | 22 | def test_valid(): 23 | input = { 24 | "braketSchemaHeader": { 25 | "name": "braket.device_schema.gate_model_parameters", 26 | "version": "1", 27 | }, 28 | "qubitCount": 1, 29 | "disableQubitRewiring": True, 30 | } 31 | result = GateModelParameters.parse_raw_schema(json.dumps(input)) 32 | assert result.qubitCount == 1 33 | assert result.disableQubitRewiring 34 | 35 | 36 | def test_no_qubit_rewiring_unspecified(): 37 | input = { 38 | "braketSchemaHeader": { 39 | "name": "braket.device_schema.gate_model_parameters", 40 | "version": "1", 41 | }, 42 | "qubitCount": 1, 43 | } 44 | result = GateModelParameters.parse_raw_schema(json.dumps(input)) 45 | assert not result.disableQubitRewiring 46 | 47 | 48 | @pytest.mark.xfail(raises=ValidationError) 49 | def test__missing_header(): 50 | input = "{} " 51 | assert GateModelParameters.parse_raw_schema(input) 52 | 53 | 54 | def test_string_for_int_value(): 55 | input = { 56 | "braketSchemaHeader": { 57 | "name": "braket.device_schema.gate_model_parameters", 58 | "version": "1", 59 | }, 60 | "qubitCount": "1", 61 | } 62 | with pytest.raises(ValidationError) as e: 63 | GateModelParameters.parse_raw_schema(json.dumps(input)) 64 | assert "value is not a valid integer" in str(e.value) 65 | -------------------------------------------------------------------------------- /src/braket/device_schema/gate_model_qpu_paradigm_properties_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from pydantic.v1 import Field 15 | 16 | from braket.device_schema.device_connectivity import DeviceConnectivity 17 | from braket.schema_common import BraketSchemaBase, BraketSchemaHeader 18 | 19 | 20 | class GateModelQpuParadigmProperties(BraketSchemaBase): 21 | """ 22 | This class defines the properties that are specific to gate model devices 23 | 24 | Attributes: 25 | connectivity: defines the connectivity if a gate model device. 26 | tells the graph and connection type. 27 | qubitCount: number of qubits the gate model device contains 28 | nativeGateSet: list of native gates 29 | 30 | Examples: 31 | >>> import json 32 | >>> input_json = { 33 | ... "braketSchemaHeader": { 34 | ... "name": "braket.device_schema.gate_model_qpu_paradigm_properties", 35 | ... "version": "1", 36 | ... }, 37 | ... "qubitCount": 32, 38 | ... "nativeGateSet": ["ccnot", "cy"], 39 | ... "connectivity": { 40 | ... "fullyConnected": False, 41 | ... "connectivityGraph": {"1": ["2", "3"]}, 42 | ... }, 43 | ... } 44 | >>> GateModelQpuParadigmProperties.parse_raw_schema(json.dumps(input_json)) 45 | """ 46 | 47 | _PROGRAM_HEADER = BraketSchemaHeader( 48 | name="braket.device_schema.gate_model_qpu_paradigm_properties", version="1" 49 | ) 50 | braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER) 51 | connectivity: DeviceConnectivity 52 | qubitCount: int 53 | nativeGateSet: list[str] 54 | -------------------------------------------------------------------------------- /src/braket/device_schema/jaqcd_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import constr 17 | 18 | from braket.device_schema.device_action_properties import DeviceActionProperties 19 | from braket.device_schema.result_type import ResultType 20 | 21 | 22 | class JaqcdDeviceActionProperties(DeviceActionProperties): 23 | """ 24 | Defines the schema for properties for the actions that can be supported by JAQCD devices. 25 | 26 | Attributes: 27 | supportedOperations: Operations supported by the JAQCD action. 28 | supportedResultTypes: Result types that are supported by the JAQCD action. 29 | disabledQubitRewiringSupported: Whether the device supports the ability to run 30 | circuits with the exact qubits chosen, without any rewiring downstream. 31 | 32 | 33 | Examples: 34 | >>> import json 35 | >>> input_json = { 36 | ... "actionType": "braket.ir.jaqcd.program", 37 | ... "version": ["1"], 38 | ... "supportedOperations": ["x", "y"], 39 | ... "supportedResultTypes": [{ 40 | ... "name": "resultType1", 41 | ... "observables": ["observable1"], 42 | ... "minShots": 0, 43 | ... "maxShots": 4, 44 | ... }], 45 | ... "disabledQubitRewiringSupported": True 46 | ... } 47 | >>> JaqcdDeviceActionProperties.parse_raw(json.dumps(input_json)) 48 | 49 | """ 50 | 51 | actionType: constr(regex=r"^braket\.ir\.jaqcd\.program$") 52 | supportedOperations: list[str] 53 | supportedResultTypes: Optional[list[ResultType]] 54 | disabledQubitRewiringSupported: Optional[bool] = None 55 | -------------------------------------------------------------------------------- /test/unit_tests/braket/ir/jaqcd/test_triple_probability.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import pytest 15 | from pydantic.v1 import ValidationError 16 | 17 | from braket.ir.jaqcd.shared_models import TripleProbability 18 | 19 | 20 | @pytest.mark.xfail(raises=ValidationError) 21 | def test_missing_probability(): 22 | TripleProbability() 23 | 24 | 25 | @pytest.mark.xfail(raises=ValidationError) 26 | def test_non_float(): 27 | TripleProbability(probX="foo", probY=0, probZ=0) 28 | 29 | 30 | @pytest.mark.xfail(raises=ValidationError) 31 | def test_nan_float(): 32 | TripleProbability(probX=float("nan"), probY=0, probZ=0) 33 | 34 | 35 | @pytest.mark.xfail(raises=ValidationError) 36 | def test_inf_float(): 37 | TripleProbability(probX=float("inf"), probY=0, probZ=0) 38 | 39 | 40 | @pytest.mark.xfail(raises=ValidationError) 41 | def test_negative_inf_float(): 42 | TripleProbability(probX=float("-inf"), probY=0, probZ=0) 43 | 44 | 45 | @pytest.mark.xfail(raises=ValidationError) 46 | def test_negative_float(): 47 | TripleProbability(probX=float(-1.5), probY=0, probZ=0) 48 | 49 | 50 | @pytest.mark.xfail(raises=ValidationError) 51 | def test_greater_than_one_float(): 52 | TripleProbability(probX=float(2.1), probY=0, probZ=0) 53 | 54 | 55 | @pytest.mark.xfail(raises=ValueError) 56 | def test_too_large_probability(): 57 | TripleProbability(probX=float(0.6), probY=float(0.4), probZ=float(0.1)) 58 | 59 | 60 | def test_float(): 61 | probX = 0.15 62 | probY = 0.2 63 | probZ = 0.25 64 | obj = TripleProbability(probX=probX, probY=probY, probZ=probZ) 65 | assert obj.probX == probX 66 | assert obj.probY == probY 67 | assert obj.probZ == probZ 68 | 69 | 70 | def test_extra_params(): 71 | TripleProbability(probX=0, probY=0, probZ=0, foo="bar") 72 | -------------------------------------------------------------------------------- /src/braket/task_result/annealing_task_result_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Optional 15 | 16 | from pydantic.v1 import Field, conint, conlist 17 | 18 | from braket.schema_common.schema_base import BraketSchemaBase, BraketSchemaHeader 19 | from braket.task_result.additional_metadata import AdditionalMetadata 20 | from braket.task_result.task_metadata_v1 import TaskMetadata 21 | 22 | 23 | class AnnealingTaskResult(BraketSchemaBase): 24 | """ 25 | The annealing task result schema. 26 | 27 | Attributes: 28 | braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need 29 | to set this value. Only default is allowed. 30 | solutions (list[int]): Solutions of task result. Default is `None`. 31 | solutionCounts (list[int]): The number of times the solutions occurred. 32 | Default is `None`. 33 | values (list[float]): Output or energy of the solutions. Default is `None`. 34 | variableCount (int): The number of variables. Default is `None`. 35 | taskMetadata (TaskMetadata): The task metadata. 36 | additionalMetadata (AdditionalMetadata): Additional metadata of the task. 37 | 38 | """ 39 | 40 | _ANNEALING_TASK_RESULT_HEADER = BraketSchemaHeader( 41 | name="braket.task_result.annealing_task_result", version="1" 42 | ) 43 | braketSchemaHeader: BraketSchemaHeader = Field( 44 | default=_ANNEALING_TASK_RESULT_HEADER, const=_ANNEALING_TASK_RESULT_HEADER 45 | ) 46 | solutions: Optional[list[conlist(conint(ge=-1, le=3), min_items=1)]] 47 | solutionCounts: Optional[list[conint(ge=0)]] 48 | values: Optional[list[float]] 49 | variableCount: Optional[conint(ge=0)] 50 | taskMetadata: TaskMetadata 51 | additionalMetadata: AdditionalMetadata 52 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/test_openqasm_program_set_device_action_properties.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.openqasm_program_set_device_action_properties import ( 20 | OpenQASMProgramSetDeviceActionProperties, 21 | ) 22 | 23 | 24 | @pytest.fixture() 25 | def valid_input(): 26 | input = { 27 | "actionType": "braket.ir.openqasm.program_set", 28 | "version": ["1"], 29 | "maximumExecutables": 500, 30 | "maximumTotalShots": 1_000_000, 31 | } 32 | return input 33 | 34 | 35 | def test_valid(valid_input): 36 | result = OpenQASMProgramSetDeviceActionProperties.parse_raw(json.dumps(valid_input)) 37 | assert result.actionType == "braket.ir.openqasm.program_set" 38 | assert result.maximumExecutables == 500 39 | assert result.maximumTotalShots == 1_000_000 40 | 41 | 42 | @pytest.mark.xfail(raises=ValidationError) 43 | def test_missing_action_type(valid_input): 44 | valid_input.pop("actionType") 45 | OpenQASMProgramSetDeviceActionProperties.parse_raw(json.dumps(valid_input)) 46 | 47 | 48 | @pytest.mark.parametrize("field", ["maximumExecutables", "maximumTotalShots"]) 49 | @pytest.mark.xfail(raises=ValidationError) 50 | def test_missing_field(valid_input, field): 51 | valid_input.pop(field) 52 | OpenQASMProgramSetDeviceActionProperties.parse_raw(json.dumps(valid_input)) 53 | 54 | 55 | @pytest.mark.parametrize("field", ["maximumExecutables", "maximumTotalShots"]) 56 | @pytest.mark.xfail(raises=ValidationError, reason="ensure this value is greater than or equal to 0") 57 | def test_negative_field(valid_input, field): 58 | valid_input[field] = -1 59 | OpenQASMProgramSetDeviceActionProperties.parse_raw(json.dumps(valid_input)) 60 | -------------------------------------------------------------------------------- /src/braket/task_result/program_result_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License 13 | 14 | from typing import Union 15 | 16 | from pydantic.v1 import Field 17 | 18 | from braket.ir.openqasm import Program 19 | from braket.schema_common.schema_base import BraketSchemaBase 20 | from braket.schema_common.schema_header import BraketSchemaHeader 21 | from braket.task_result.additional_metadata import AdditionalMetadata 22 | from braket.task_result.program_set_executable_failure_v1 import ProgramSetExecutableFailure 23 | from braket.task_result.program_set_executable_result_v1 import ProgramSetExecutableResult 24 | 25 | 26 | class ProgramResult(BraketSchemaBase): 27 | """ 28 | The results of single program of a program set. 29 | 30 | Attributes: 31 | executableResults (Union[list[str], list[ProgramSetExecutableResult | ProgramSetExecutableFailure]]): # noqa 32 | The relative S3 paths of the executable result files, 33 | or a list of the executable results or failures themselves. 34 | source (Union[str, Program]): The program that was run or the relative S3 path of 35 | the program file; if the program is parametrized, this includes all input values 36 | the program was run with. 37 | additionalMetadata (AdditionalMetadata): Additional metadata of the task. 38 | """ 39 | 40 | _PROGRAM_SET_PROGRAM_RESULT_HEADER = BraketSchemaHeader( 41 | name="braket.task_result.program_result", version="1" 42 | ) 43 | braketSchemaHeader: BraketSchemaHeader = Field( 44 | default=_PROGRAM_SET_PROGRAM_RESULT_HEADER, const=_PROGRAM_SET_PROGRAM_RESULT_HEADER 45 | ) 46 | 47 | executableResults: Union[ 48 | list[str], list[Union[ProgramSetExecutableResult, ProgramSetExecutableFailure]] 49 | ] 50 | source: Union[str, Program] 51 | additionalMetadata: AdditionalMetadata 52 | -------------------------------------------------------------------------------- /test/unit_tests/braket/device_schema/rigetti/test_rigetti_provider_properties_v2.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from pydantic.v1 import ValidationError 18 | 19 | from braket.device_schema.rigetti.rigetti_provider_properties_v2 import RigettiProviderProperties 20 | 21 | 22 | @pytest.fixture(scope="module") 23 | def valid_input(): 24 | input = { 25 | "braketSchemaHeader": { 26 | "name": "braket.device_schema.rigetti.rigetti_provider_properties", 27 | "version": "2", 28 | }, 29 | "specs": { 30 | "name": "Ankaa-9Q-3", 31 | "architecture": { 32 | "family": "Ankaa", 33 | "nodes": [{"node_id": 0}, {"node_id": 1}], 34 | "edges": [{"node_ids": [0, 1]}], 35 | }, 36 | "instructions": [ 37 | { 38 | "name": "I", 39 | "node_count": 1, 40 | "parameters": [], 41 | "sites": [{"node_ids": [0], "characteristics": []}], 42 | "characteristics": [], 43 | } 44 | ], 45 | }, 46 | } 47 | return input 48 | 49 | 50 | def test_valid(valid_input): 51 | result = RigettiProviderProperties.parse_raw_schema(json.dumps(valid_input)) 52 | assert ( 53 | result.braketSchemaHeader.name == "braket.device_schema.rigetti.rigetti_provider_properties" 54 | ) 55 | 56 | 57 | def test__missing_schemaHeader(valid_input): 58 | valid_input.pop("braketSchemaHeader") 59 | with pytest.raises(ValidationError): 60 | RigettiProviderProperties.parse_raw_schema(json.dumps(valid_input)) 61 | 62 | 63 | def test__missing_specs(valid_input): 64 | valid_input.pop("specs") 65 | with pytest.raises(ValidationError): 66 | RigettiProviderProperties.parse_raw_schema(json.dumps(valid_input)) 67 | -------------------------------------------------------------------------------- /test/unit_tests/braket/jobs_data/test_persisted_job_data_v1.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"). You 4 | # may not use this file except in compliance with the License. A copy of 5 | # the License is located at 6 | # 7 | # http://aws.amazon.com/apache2.0/ 8 | # 9 | # or in the "license" file accompanying this file. This file is 10 | # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 11 | # ANY KIND, either express or implied. See the License for the specific 12 | # language governing permissions and limitations under the License. 13 | 14 | import json 15 | 16 | import pytest 17 | from jsonschema import validate 18 | from pydantic.v1 import ValidationError 19 | 20 | from braket.jobs_data.persisted_job_data_v1 import PersistedJobData, PersistedJobDataFormat 21 | 22 | 23 | def test_persisted_job_data_fields(): 24 | data_dict = {"key_1": "value_1", "iterations": 2, "more_keys": True} 25 | data_format = PersistedJobDataFormat.PLAINTEXT 26 | persisted = PersistedJobData(dataDictionary=data_dict, dataFormat=data_format) 27 | assert persisted.dataDictionary == data_dict 28 | assert persisted.dataFormat == data_format 29 | 30 | 31 | @pytest.mark.xfail(raises=ValidationError) 32 | def test_persisted_job_data_missing_data_format(): 33 | PersistedJobData(dataDictionary={"a": 1}) 34 | 35 | 36 | @pytest.mark.xfail(raises=ValidationError) 37 | def test_persisted_job_data_missing_data_dictionary(): 38 | PersistedJobData(dataFormat=PersistedJobDataFormat.PLAINTEXT) 39 | 40 | 41 | def test_json_validates_against_schema(): 42 | persisted_job_data = PersistedJobData( 43 | dataDictionary={"a": 1}, dataFormat=PersistedJobDataFormat.PLAINTEXT 44 | ) 45 | validate(json.loads(persisted_job_data.json()), persisted_job_data.schema()) 46 | 47 | 48 | def test_persisted_job_data_parses_json(): 49 | json_str = json.dumps( 50 | { 51 | "braketSchemaHeader": { 52 | "name": "braket.jobs_data.persisted_job_data", 53 | "version": "1", 54 | }, 55 | "dataDictionary": {"converged": True, "energy": -0.2}, 56 | "dataFormat": "plaintext", 57 | } 58 | ) 59 | persisted_data = PersistedJobData.parse_raw(json_str) 60 | assert persisted_data.dataDictionary == {"converged": True, "energy": -0.2} 61 | assert persisted_data.dataFormat == PersistedJobDataFormat.PLAINTEXT 62 | --------------------------------------------------------------------------------