Ejemplo n.º 1
0
def result_obj_5(task_metadata_shots):
    return GateModelTaskResult(
        taskMetadata=task_metadata_shots,
        additionalMetadata=AdditionalMetadata(action=jaqcd.Program(
            instructions=[
                jaqcd.CNot(control=0, target=1),
                jaqcd.CNot(control=2, target=3)
            ],
            results=[
                jaqcd.Probability(targets=[1]),
                jaqcd.Expectation(observable=["z"])
            ],
        )),
        measurements=[
            [0, 0, 1, 0],
            [1, 1, 1, 1],
            [1, 0, 0, 1],
            [0, 0, 1, 0],
            [1, 1, 1, 1],
            [0, 1, 1, 1],
            [0, 0, 0, 1],
            [0, 1, 1, 1],
            [0, 0, 0, 0],
            [0, 0, 0, 1],
        ],
        measuredQubits=[0, 1, 2, 3],
    )
Ejemplo n.º 2
0
def additional_metadata_openqasm():
    program = openqasm.Program(
        source="""
        qubit[2] q;
        bit[2] c;

        h q[0];
        cnot q[0], q[1];

        c = measure q;
        """
    )
    return AdditionalMetadata(action=program)
def test_simulator_bell_pair_result_types(bell_ir_with_result, targets,
                                          batch_size):
    simulator = DefaultSimulator()
    ir = bell_ir_with_result(targets)
    result = simulator.run(ir, qubit_count=2, shots=0, batch_size=batch_size)
    assert len(result.resultTypes) == 2
    assert result.resultTypes[0] == ResultTypeValue.construct(
        type=ir.results[0], value={"11": complex(1 / 2**0.5)})
    assert result.resultTypes[1] == ResultTypeValue.construct(
        type=ir.results[1], value=(0 if targets else [0, 0]))
    assert result.taskMetadata == TaskMetadata(
        id=result.taskMetadata.id,
        deviceId=DefaultSimulator.DEVICE_ID,
        shots=0)
    assert result.additionalMetadata == AdditionalMetadata(action=ir)
Ejemplo n.º 4
0
def additional_metadata(problem_type, dwave_metadata):
    problem = Problem(
        type=problem_type,
        linear={
            0: 0.3333,
            1: -0.333,
            4: -0.333,
            5: 0.333
        },
        quadratic={
            "0,4": 0.667,
            "0,5": -1,
            "1,4": 0.667,
            "1,5": 0.667
        },
    )
    return AdditionalMetadata(action=problem, dwaveMetadata=dwave_metadata)
def test_simulator_run_bell_pair(bell_ir, batch_size):
    simulator = DefaultSimulator()
    shots_count = 10000
    result = simulator.run(bell_ir,
                           qubit_count=2,
                           shots=shots_count,
                           batch_size=batch_size)

    assert all([len(measurement) == 2] for measurement in result.measurements)
    assert len(result.measurements) == shots_count
    counter = Counter(
        ["".join(measurement) for measurement in result.measurements])
    assert counter.keys() == {"00", "11"}
    assert 0.4 < counter["00"] / (counter["00"] + counter["11"]) < 0.6
    assert 0.4 < counter["11"] / (counter["00"] + counter["11"]) < 0.6
    assert result.taskMetadata == TaskMetadata(
        id=result.taskMetadata.id,
        deviceId=DefaultSimulator.DEVICE_ID,
        shots=shots_count)
    assert result.additionalMetadata == AdditionalMetadata(action=bell_ir)
    def _create_results_obj(
        results: List[Dict[str, Any]],
        circuit_ir: Program,
        simulation: StateVectorSimulation,
    ) -> GateModelTaskResult:
        result_dict = {
            "taskMetadata":
            TaskMetadata(id=str(uuid.uuid4()),
                         shots=simulation.shots,
                         deviceId=DefaultSimulator.DEVICE_ID),
            "additionalMetadata":
            AdditionalMetadata(action=circuit_ir),
        }
        if results:
            result_dict["resultTypes"] = results
        if simulation.shots:
            result_dict[
                "measurements"] = DefaultSimulator._formatted_measurements(
                    simulation)
            result_dict[
                "measuredQubits"] = DefaultSimulator._get_measured_qubits(
                    simulation.qubit_count)

        return GateModelTaskResult.construct(**result_dict)
Ejemplo n.º 7
0
def additional_metadata(blackbird_program, xanadu_metadata):
    return AdditionalMetadata(action=blackbird_program, xanaduMetadata=xanadu_metadata)
Ejemplo n.º 8
0
def additional_metadata():
    program = jaqcd.Program(instructions=[jaqcd.CNot(control=0, target=1)])
    return AdditionalMetadata(action=program)