Skip to content

added calcAmpSum backend #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

added calcAmpSum backend #608

wants to merge 1 commit into from

Conversation

TysonRayJones
Copy link
Member

@TysonRayJones TysonRayJones commented May 5, 2025

Example PR A

Sub PR 2

This PR implements the backend of the calcRealAmpSum function from PR #607, to demonstrate how accelerated functions are structured.

Note the backend functions actually implement calcAmpSum which returns both the real and imaginary components of the amplitude sum. This will be leveraged by a subsequent calcAmpSum() API function.

In general, a function in quest/src/api calls a

  1. localiser.cpp routine which communicates data between distributed nodes as necessary.
    It does this by invoking one or more routines within...
  2. comm_routines.cpp
    then proceeds to invoke an
  3. accelerator.cpp routine which decides whether to invoke CPU or GPU code.
    This calls either a...

In this PR, the GPU backend for the function calcAmpSum was implemented using Thrust since it trivially mapped to an existing Thrust routine.

Note that calcRealAmpSum can be called upon both a statevector and density matrix Qureg. Since the simulation logic is agnostic to either, both types of Qureg were passed to backend functions containing the _statevector_ infix. If the statevector and density matrix logic had differed, we would additionally define backend functions

localiser_densmatr_calcAmpSum();
accel_densmatr_calcAmpSum();
cpu_densmatr_calcAmpSum();
gpu_densmatr_calcAmpSum();
thrust_densmatr_calcAmpSum();

and invoke the appropriate localiser function at the top-level:

qreal calcRealAmpSum(Qureg qureg) {
    validate_quregFields(qureg, __func__);
    validate_quregHasEvenNumQubits(qureg, __func__);

    qcomp value = (qureg.isDensityMatrix)?
        localiser_densmatr_calcAmpSum(qureg);
        localiser_statevec_calcAmpSum(qureg);

    return std::real(value);
}

With the frontend and backends defined, the next step is to implement the unit tests like demonstrated in #609.

@TysonRayJones TysonRayJones added the demo A demonstration of a development process label May 5, 2025
@TysonRayJones TysonRayJones deleted the example-pr-2 branch May 6, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo A demonstration of a development process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant