Skip to content

Commit

Permalink
update: adding test metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
krneta committed Nov 3, 2023
1 parent 58e289b commit 88ae48b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/braket_tests/base/test_jobs_qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
from ..common.braket_jobs_util import job_test


Expand All @@ -27,6 +28,7 @@ def test_qaoa_circuit(account, role, s3_bucket, image_list):
"stepsize": "0.1",
"shots": "100",
"interface": "autograd",
"start_time": time.time(),
}
}
for image_path in image_list:
Expand Down
2 changes: 2 additions & 0 deletions test/braket_tests/pytorch/test_jobs_qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
from ..common.braket_jobs_util import job_test


Expand All @@ -27,6 +28,7 @@ def test_qaoa_circuit(account, role, s3_bucket, image_list):
"stepsize": "0.1",
"shots": "100",
"interface": "torch",
"start_time": time.time(),
}
}
for image_path in image_list:
Expand Down
2 changes: 2 additions & 0 deletions test/braket_tests/tensorflow/test_jobs_qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
from ..common.braket_jobs_util import job_test


Expand All @@ -27,6 +28,7 @@ def test_qaoa_circuit(account, role, s3_bucket, image_list):
"stepsize": "0.1",
"shots": "100",
"interface": "tf",
"start_time": time.time(),
}
}
for image_path in image_list:
Expand Down
31 changes: 29 additions & 2 deletions test/resources/qaoa_entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import json
import os
import time
import boto3

import networkx as nx
from pennylane import numpy as np
Expand All @@ -25,6 +26,28 @@
from . import qaoa_utils


def record_test_metrics(metric, start_time, interface):
cw_client = boto3.client("cloudwatch")
cw_client.put_metric_data(
MetricData=[{
'MetricName': metric,
'Dimensions': [
{
'Name': 'TYPE',
'Value': 'braket_tests'
},
{
'Name': 'INTERFACE',
'Value': interface
}
],
'Unit': 'Seconds',
'Value': time.time() - start_time
}],
Namespace='braket-container-metrics'
)


def init_pl_device(device_arn, num_nodes, shots, max_parallel):
return qml.device(
"braket.aws.qubit",
Expand All @@ -51,6 +74,9 @@ def start_function():
stepsize = float(hyperparams["stepsize"])
shots = int(hyperparams["shots"])
pl_interface = hyperparams["interface"]
start_time = float(hyperparams["start_time"])

record_test_metrics('Startup', start_time, pl_interface)

interface = qaoa_utils.QAOAInterface.get_interface(pl_interface)

Expand All @@ -73,7 +99,7 @@ def circuit(params, **kwargs):
dev = init_pl_device(device_arn, num_nodes, shots, max_parallel)

np.random.seed(seed)

@qml.qnode(dev, interface=pl_interface)
def cost_function(params):
circuit(params)
Expand Down Expand Up @@ -130,8 +156,9 @@ def cost_function(params):

save_job_result({"params": np_params.tolist(), "cost": final_cost})

record_test_metrics('Total', start_time, pl_interface)
print("Braket Container Run Success")


if __name__ == "__main__":
start_function()
start_function()

0 comments on commit 88ae48b

Please sign in to comment.