Skip to content
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

Concatenate Quantum Registers #2645

Open
1 task done
MatteoBarbieriE4 opened this issue Feb 21, 2025 · 1 comment
Open
1 task done

Concatenate Quantum Registers #2645

MatteoBarbieriE4 opened this issue Feb 21, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@MatteoBarbieriE4
Copy link

MatteoBarbieriE4 commented Feb 21, 2025

Required prerequisites

  • Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.

Describe the feature

I suggest there should be a function that allows to merge quantum registers.
With the current features of cudaq one, for instance, can do the following:

 __qpu__ void myFucntion(cudaq::qview<> qc)
{
    cudaq::qview<> qc_1 = qc.front(qc.size()-1);
    cudaq::qubit &q = qc[qc.size()-1];
    DoSomething(qc_1,q);
}

namely I can separate a quantum register. However I cannot merge quantum registers. This can be very useful when one has numerous quantum functions which handle the input registers differently. Suppose I have a function that works as follows:

__qpu__ void Func1(cudaq::qview<> qc)
{    
   cudaq::x(qc);
}

Then I have another function that takes as input two quantum registers. Inside this function I want to apply Func1() to both the two registers together. In this case there is not, to my knowledge, a possibility to merge the two input quantum registers and apply the other function to the register which is the result of the merge. What I would liike to do is:

__qpu__ void Func2(cudaq::qview<> qc_1, cudaq::qview<> qc_2)
{
    cudaq::y(qc_1);
    cudaq::qview<> qc_merge = cudaq::concatenate(qc_1,qc_2);
    Func1(qc_merge);
}

Is there the option to do so? If yes what is it? If not, it would be nice to have it.
Best regards!

@MatteoBarbieriE4 MatteoBarbieriE4 added the enhancement New feature or request label Feb 21, 2025
@ParamThakkar123
Copy link

How about something like this :

namespace cudaq {

template <std::size_t Levels = 2>
qview<Levels> concatenate(const qview<Levels> &qc1, const qview<Levels> &qc2) {
    std::vector<qudit<Levels>> merged_qudits;
    merged_qudits.reserve(qc1.size() + qc2.size());

    for (std::size_t i = 0; i < qc1.size(); ++i) {
        merged_qudits.push_back(qc1[i]);
    }
    for (std::size_t i = 0; i < qc2.size(); ++i) {
        merged_qudits.push_back(qc2[i]);
    }

    return qview<Levels>(merged_qudits.begin(), merged_qudits.size());
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants