diff --git a/examples/job.py b/examples/job.py deleted file mode 100644 index 87b06bf49..000000000 --- a/examples/job.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"). You -# may not use this file except in compliance with the License. A copy of -# the License is located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF -# ANY KIND, either express or implied. See the License for the specific -# language governing permissions and limitations under the License. - -from braket.aws import AwsDevice, AwsQuantumJob -from braket.circuits import Circuit -from braket.devices import Devices -from braket.jobs import get_job_device_arn, save_job_result - - -def run_job(): - device = AwsDevice(get_job_device_arn()) - - bell = Circuit().h(0).cnot(0, 1) - num_tasks = 10 - results = [] - - for i in range(num_tasks): - task = device.run(bell, shots=100) - result = task.result().measurement_counts - results.append(result) - print(f"iter {i}: {result}") - - save_job_result({"results": results}) - - -if __name__ == "__main__": - job = AwsQuantumJob.create( - device=Devices.Amazon.SV1, - source_module="job.py", - entry_point="job:run_job", - wait_until_complete=True, - ) - print(job.result()) diff --git a/src/braket/jobs/hybrid_job.py b/src/braket/jobs/hybrid_job.py index a45b094d4..7fd9617c4 100644 --- a/src/braket/jobs/hybrid_job.py +++ b/src/braket/jobs/hybrid_job.py @@ -306,15 +306,14 @@ def _sanitize(hyperparameter: Any) -> str: sanitized = ( string_hp - # replace newlines with spaces + # replace forbidden characters with close matches .replace("\n", " ") - # replace forbidden characters with "?" .replace("$", "?") - .replace("(", "?") - .replace("&", "?") - .replace("`", "?") + .replace("(", "{") + .replace("&", "+") + .replace("`", "'") # not technically forbidden, but to avoid mismatched parens - .replace(")", "?") + .replace(")", "}") ) # max allowed length for a hyperparameter is 2500 diff --git a/test/integ_tests/test_create_quantum_job.py b/test/integ_tests/test_create_quantum_job.py index ec75c23eb..5364c8e3b 100644 --- a/test/integ_tests/test_create_quantum_job.py +++ b/test/integ_tests/test_create_quantum_job.py @@ -220,7 +220,7 @@ def decorator_job(a, b: int, c=0, d: float = 1.0, **extras): with open(hp_file, "r") as f: hyperparameters = json.load(f) assert hyperparameters == { - "a": "MyClass(value)", + "a": "MyClass{value}", "b": "2", "c": "0", "d": "5", diff --git a/test/unit_tests/braket/jobs/test_hybrid_job.py b/test/unit_tests/braket/jobs/test_hybrid_job.py index f1159f9ce..56a5f30ef 100644 --- a/test/unit_tests/braket/jobs/test_hybrid_job.py +++ b/test/unit_tests/braket/jobs/test_hybrid_job.py @@ -481,7 +481,7 @@ def my_job(): ), ( "with weird chars: (&$`)", - "with weird chars: ?????", + "with weird chars: {+?'}", ), ( "?" * 2600,