예제 #1
0
def result_str_2(solutions, values, variable_count, task_metadata,
                 additional_metadata):
    result = AnnealingTaskResult(
        solutions=solutions,
        variableCount=variable_count,
        values=values,
        taskMetadata=task_metadata,
        additionalMetadata=additional_metadata,
    )
    return result.json()
예제 #2
0
    def from_string(result: str) -> AnnealingQuantumTaskResult:
        """
        Create AnnealingQuantumTaskResult from string

        Args:
            result (str): JSON object string

        Returns:
            AnnealingQuantumTaskResult: An AnnealingQuantumTaskResult based on the given string
        """
        return AnnealingQuantumTaskResult._from_object(AnnealingTaskResult.parse_raw(result))
예제 #3
0
def test_from_object(
    result_str_1,
    solutions,
    values,
    solution_counts,
    variable_count,
    problem_type,
    task_metadata,
    additional_metadata,
):
    result = AnnealingQuantumTaskResult.from_object(
        AnnealingTaskResult.parse_raw(result_str_1))
    solutions = np.asarray(solutions, dtype=int)
    values = np.asarray(values, dtype=float)
    solution_counts = np.asarray(solution_counts, dtype=int)
    assert result.variable_count == variable_count
    assert result.problem_type == problem_type
    assert result.task_metadata == task_metadata
    assert result.additional_metadata == additional_metadata
    np.testing.assert_equal(
        result.record_array,
        AnnealingQuantumTaskResult._create_record_array(
            solutions, solution_counts, values),
    )
예제 #4
0
def test_from_object_equal_to_from_string(result_str_1):
    assert AnnealingQuantumTaskResult.from_object(
        AnnealingTaskResult.parse_raw(result_str_1)
    ) == AnnealingQuantumTaskResult.from_string(result_str_1)
ANNEALING_RESULT = AnnealingTaskResult(
    **{
        "solutions": [[-1, -1, -1, -1], [1, -1, 1, 1], [1, -1, -1, 1]],
        "solutionCounts": [3, 2, 4],
        "values": [0.0, 1.0, 2.0],
        "variableCount": 4,
        "taskMetadata": {
            "id": "task_arn",
            "shots": 100,
            "deviceId": "device_id",
        },
        "additionalMetadata": {
            "action": {
                "type": "ISING",
                "linear": {
                    "0": 0.3333,
                    "1": -0.333,
                    "4": -0.333,
                    "5": 0.333
                },
                "quadratic": {
                    "0,4": 0.667,
                    "0,5": -1.0,
                    "1,4": 0.667,
                    "1,5": 0.667
                },
            },
            "dwaveMetadata": {
                "activeVariables": [0],
                "timing": {
                    "qpuSamplingTime": 100,
                    "qpuAnnealTimePerSample": 20,
                    "qpuAccessTime": 10917,
                    "qpuAccessOverheadTime": 3382,
                    "qpuReadoutTimePerSample": 274,
                    "qpuProgrammingTime": 9342,
                    "qpuDelayTimePerSample": 21,
                    "postProcessingOverheadTime": 117,
                    "totalPostProcessingTime": 117,
                    "totalRealTime": 10917,
                    "runTimeChip": 1575,
                    "annealTimePerRun": 20,
                    "readoutTimePerRun": 274,
                },
            },
        },
    })