Ejemplo n.º 1
0
def test_ir_non_empty_instructions_result_types_basis_rotation_instructions():
    circ = Circuit().h(0).cnot(0, 1).sample(observable=Observable.X(),
                                            target=[0])
    expected = jaqcd.Program(
        instructions=[jaqcd.H(target=0),
                      jaqcd.CNot(control=0, target=1)],
        results=[jaqcd.Sample(observable=["x"], targets=[0])],
        basis_rotation_instructions=[jaqcd.H(target=0)],
    )
    assert circ.to_ir() == expected
Ejemplo n.º 2
0
        taskMetadata=task_metadata_shots,
        additionalMetadata=additional_metadata,
    ).json()


test_ir_results = [
    (jaqcd.Probability(targets=[1]), np.array([0.6, 0.4])),
    (jaqcd.Probability(targets=[1, 2]), np.array([0.4, 0.2, 0.0, 0.4])),
    (
        jaqcd.Probability(),
        np.array([
            0.1, 0.2, 0.2, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.1, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.2
        ]),
    ),
    (jaqcd.Sample(targets=[1], observable=["z"]),
     np.array([1, -1, 1, 1, -1, -1, 1, -1, 1, 1])),
    (
        jaqcd.Sample(targets=[1, 2], observable=["x", "y"]),
        np.array([-1, 1, 1, -1, 1, 1, 1, 1, 1, 1]),
    ),
    (
        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),
Ejemplo n.º 3
0
def test_openqasm_shots_calculate_result_types(openqasm_result_obj_shots):
    result = GateModelQuantumTaskResult._from_object_internal_computational_basis_sampling(
        openqasm_result_obj_shots
    )
    assert result.result_types[0].type == jaqcd.Probability()
    assert np.array_equal(result.result_types[0].value, [0.25, 0.75, 0, 0])


test_ir_results = [
    (jaqcd.Probability(targets=[1]), np.array([0.6, 0.4])),
    (jaqcd.Probability(targets=[1, 2]), np.array([0.4, 0.2, 0.0, 0.4])),
    (
        jaqcd.Probability(),
        np.array([0.1, 0.2, 0.2, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2]),
    ),
    (jaqcd.Sample(targets=[1], observable=["z"]), np.array([1, -1, 1, 1, -1, -1, 1, -1, 1, 1])),
    (
        jaqcd.Sample(targets=[1, 2], observable=["x", "y"]),
        np.array([-1, 1, 1, -1, 1, 1, 1, 1, 1, 1]),
    ),
    (
        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),