def result_str_4(task_metadata_zero_shots, additional_metadata): result = GateModelTaskResult( resultTypes=[ ResultTypeValue(type=jaqcd.Probability(targets=[0]), value=[0.5, 0.5]), ResultTypeValue( type=jaqcd.StateVector(), value=[(0.70710678, 0), (0, 0), (0, 0), (0.70710678, 0)] ), ResultTypeValue(type=jaqcd.Expectation(observable=["y"], targets=[0]), value=0.0), ResultTypeValue(type=jaqcd.Variance(observable=["y"], targets=[0]), value=0.1), ResultTypeValue(type=jaqcd.Amplitude(states=["00"]), value={"00": (0.70710678, 0)}), ], measuredQubits=list(range(2)), taskMetadata=task_metadata_zero_shots, additionalMetadata=additional_metadata, ) return result.json()
def result_obj_4(task_metadata_zero_shots, additional_metadata): return GateModelTaskResult( resultTypes=[ ResultTypeValue.construct(type=jaqcd.Probability(targets=[0]), value=np.array([0.5, 0.5])), ResultTypeValue.construct( type=jaqcd.StateVector(), value=np.array( [complex(0.70710678, 0), 0, 0, complex(0.70710678, 0)]), ), ResultTypeValue.construct(type=jaqcd.Expectation(observable=["y"], targets=[0]), value=0.0), ResultTypeValue.construct(type=jaqcd.Variance(observable=["y"], targets=[0]), value=0.1), ResultTypeValue.construct(type=jaqcd.Amplitude(states=["00"]), value={"00": complex(0.70710678, 0)}), ], measuredQubits=list(range(2)), taskMetadata=task_metadata_zero_shots, additionalMetadata=additional_metadata, )
import itertools import json import random import numpy as np import pytest import braket.ir.jaqcd as jaqcd from braket.default_simulator.simulator import DefaultSimulator results_data = [ ([jaqcd.Expectation(observable=["x"])]), ([jaqcd.Probability(targets=[0, 1])]), ([jaqcd.Probability(), jaqcd.Variance(observable=["x"])]), ([jaqcd.Variance(observable=["z"], targets=[0])]), ] @pytest.fixture def generate_continuous_gates_circuit(): def _generate_circuit(num_qubits, num_layers, results): instructions = [] for layer in range(num_layers): for qubit in range(num_qubits): instructions.extend([ jaqcd.Rx(target=qubit, angle=0.15), jaqcd.Ry(target=qubit, angle=0.16), jaqcd.Rz(target=qubit, angle=0.17), ])
def test_from_braket_result_type_tensor_product_insufficient(): from_braket_result_type(jaqcd.Variance(targets=[0], observable=["h", "i"]))
from braket.default_simulator.result_types import ( Amplitude, Expectation, Probability, StateVector, Variance, from_braket_result_type, ) from braket.ir import jaqcd from braket.ir.jaqcd import shared_models NUM_SAMPLES = 1000 observable_type_testdata = [ (jaqcd.Expectation(targets=[1], observable=["x"]), Expectation), (jaqcd.Variance(targets=[1], observable=["y"]), Variance), (jaqcd.Variance(targets=[1], observable=["z"]), Variance), (jaqcd.Expectation(observable=["h"]), Expectation), (jaqcd.Variance(targets=[0], observable=[[[[0, 0], [1, 0]], [[1, 0], [0, 0]]]]), Variance), (jaqcd.Expectation(targets=[0, 1], observable=["h", "i"]), Expectation), ( jaqcd.Variance(targets=[0, 1], observable=["h", [[[0, 0], [1, 0]], [[1, 0], [0, 0]]]]), Variance, ), ] @pytest.fixture def state_vector(): multiplier = np.concatenate([np.ones(8), np.ones(8) * 1j]) return ((np.arange(16) / 120) ** (1 / 2)) * multiplier
( jaqcd.Sample(observable=["z"]), [ np.array([1, -1, -1, 1, -1, 1, 1, 1, 1, 1]), np.array([1, -1, 1, 1, -1, -1, 1, -1, 1, 1]), np.array([-1, -1, 1, -1, -1, -1, 1, -1, 1, 1]), np.array([1, -1, -1, 1, -1, -1, -1, -1, 1, -1]), ], ), (jaqcd.Expectation(targets=[1], observable=["z"]), 0.2), (jaqcd.Expectation(targets=[1], observable=[[[[-1, 0], [0, 0]], [[0, 0], [1, 0]]]]), -0.2), (jaqcd.Expectation(targets=[1, 2], observable=["z", "y"]), 0.6), (jaqcd.Expectation(observable=["z"]), [0.4, 0.2, -0.2, -0.4]), (jaqcd.Variance(targets=[1], observable=["z"]), 0.96), (jaqcd.Variance(targets=[1], observable=[[[[-1, 0], [0, 0]], [[0, 0], [1, 0]]]]), 0.96), (jaqcd.Variance(targets=[1, 2], observable=["z", "y"]), 0.64), (jaqcd.Variance(observable=["z"]), [0.84, 0.96, 0.96, 0.84]), ] def test_measurement_counts_from_measurements(): measurements: np.ndarray = np.array([[1, 0, 1, 0], [0, 0, 0, 0], [1, 0, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 1, 0]]) measurement_counts = GateModelQuantumTaskResult.measurement_counts_from_measurements( measurements) expected_counts: Counter = {"1010": 3, "0000": 1, "1000": 2} assert expected_counts == measurement_counts