示例#1
0
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()
示例#2
0
    def _qft_operations(qubit_count):
        qft_ops = []
        for target_qubit in range(qubit_count):
            angle = np.pi / 2
            qft_ops.append(jaqcd.H(target=target_qubit))
            for control_qubit in range(target_qubit + 1, qubit_count):
                qft_ops.append(
                    jaqcd.CPhaseShift(control=control_qubit,
                                      target=target_qubit,
                                      angle=angle))
                angle /= 2

        amplitudes = [
            "".join([str(random.randint(0, 1)) for _ in range(qubit_count)])
            for _ in range(2**(qubit_count // 2))
        ]
        return jaqcd.Program(
            instructions=qft_ops,
            results=[
                jaqcd.StateVector(),
                jaqcd.Amplitude(states=amplitudes),
                jaqcd.Expectation(observable=["x"]),
            ],
        )
示例#3
0
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,
    )
示例#4
0
def test_from_braket_result_type_amplitude():
    translated = from_braket_result_type(jaqcd.Amplitude(states=["01", "10"]))
    assert isinstance(translated, Amplitude)
    assert translated._states == ["01", "10"]