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

MPS Implementation p4: Two qubit gates. #372

Merged
merged 12 commits into from
Jul 14, 2021

Conversation

MichaelBroughton
Copy link
Collaborator

Adds the two qubit gate application functionality along with tests. Other changes done in this PR:

  1. Added explicit SHA and COMMIT variables in case we need to move around the bazel eigen version for TFQ compatibility.
  2. Upped the scratch space size to the equivalent of three internal blocks worth of scratch space.
  3. Changed the using MPS = .... to using State = ... in order to work with ApplyGate in gate_appl.h.

@google-cla google-cla bot added the cla: yes Override CLA status to unblock PR. label Jul 2, 2021
Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of review comments. Sergei is out for a couple of weeks - can a thorough review on this wait until he gets back?

C.noalias() = A * B.transpose();
memcpy(raw_state + offset, raw_state + end, sizeof(fp_type) * bd * 4);
}

void ApplyGate2(const std::vector<unsigned>& qs, const fp_type* matrix,
State& state) const {
// TODO: micro-benchmark this function and improve performance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO resolved? If not, please open an issue for it and reference that issue here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not resolved. Opened issue here: #373

};
sim.ApplyGate({0, 1}, mat.data(), mps);

float *wf = new float[32];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as the previous PR - a clarifying comment on how these wf values are generated could be helpful.

For sections with Cirq equivalents, something like this might provide the best comparison:

The results are obtained with the following Cirq code:

(includes an equivalent Cirq code snippet)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a link to Cirq code that regenerates the fuzz test as well as diagrams and explanations for the other tests. Was this what you had in mind ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you!

Copy link
Collaborator

@sergeisakov sergeisakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. There are a number of formatting issues.

tests/mps_simulator_test.cc Outdated Show resolved Hide resolved
tests/mps_simulator_test.cc Outdated Show resolved Hide resolved
tests/mps_simulator_test.cc Outdated Show resolved Hide resolved
tests/mps_simulator_test.cc Outdated Show resolved Hide resolved
tests/mps_simulator_test.cc Outdated Show resolved Hide resolved
lib/mps_simulator.h Outdated Show resolved Hide resolved
lib/mps_simulator.h Show resolved Hide resolved
lib/mps_simulator.h Outdated Show resolved Hide resolved
lib/mps_simulator.h Outdated Show resolved Hide resolved
lib/mps_simulator.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@sergeisakov sergeisakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@95-martin-orion 95-martin-orion added the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@qsim-qsimh-bot qsim-qsimh-bot removed the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@95-martin-orion
Copy link
Collaborator

Looks like the Windows build encountered an error:

ERROR: {...}/qsim/tests/BUILD:575:1: C++ compilation of rule '//tests:mps_simulator_test' failed (Exit 2)
{...}\lib\mps_statespace.h(53): error C2039: 'free': is not a member of 'qsim::detail'
{...}\lib\gate.h(27): note: see declaration of 'qsim::detail'
{...}\tests\../lib/mps_simulator.h(42): note: see reference to class template instantiation 'qsim::mps::MPSStateSpace<For,fp_type>' being compiled
        with
        [
            For=qsim::For,
            fp_type=float
        ]
tests/mps_simulator_test.cc(28): note: see reference to class template instantiation 'qsim::mps::MPSSimulator<qsim::For,float>' being compiled

@MichaelBroughton MichaelBroughton added the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@qsim-qsimh-bot qsim-qsimh-bot removed the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@MichaelBroughton MichaelBroughton added the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@qsim-qsimh-bot qsim-qsimh-bot removed the kokoro:run Trigger Kokoro builds for this PR. label Jul 14, 2021
@MichaelBroughton MichaelBroughton merged commit 0514a02 into quantumlib:master Jul 14, 2021
@MichaelBroughton MichaelBroughton deleted the mps branch July 14, 2021 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Override CLA status to unblock PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants