Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Hadamard-test circuit generator algorithm (Q# + Qiskit backends) and wires it into the algorithm registry, along with Q# utility code and end-to-end-ish tests using a small water benchmark pipeline.
Changes:
- Introduces
HadamardTestGeneratorabstractions plusQsharpHadamardGenerator/QiskitHadamardGeneratorimplementations. - Adds Q# utility operation
MakeHadamardCircuitand registers it for lazy Q# utils loading. - Registers the new factory/algorithms and adds tests validating observable measurement + input validation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_hadamard_test_generator.py | New tests + benchmark fixture for Hadamard-test generators (Q# and Qiskit). |
| python/src/qdk_chemistry/utils/qsharp/HadamardTest.qs | New Q# operation for constructing Hadamard test circuits. |
| python/src/qdk_chemistry/utils/qsharp/init.py | Adds the new Q# file to the lazy-loaded utility bundle. |
| python/src/qdk_chemistry/algorithms/registry.py | Registers the new factory + algorithms in the global registry. |
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py | Implements Q# and Qiskit Hadamard-test generators. |
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py | Adds base HadamardTestGenerator and HadamardTestFactory. |
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/init.py | Exposes the factory at the package level. |
| python/src/qdk_chemistry/algorithms/init.py | Exports HadamardTestGenerator from the algorithms package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Adds a new “Hadamard test generator” algorithm type with Q# and Qiskit-backed implementations, wires it into the algorithm registry, and introduces integration tests + Q# utility code to build the corresponding circuits.
Changes:
- Introduce
HadamardTestGenerator+ factory, plusQsharpHadamardGenerator/QiskitHadamardGeneratorimplementations. - Register the new algorithm type and default implementations in the central registry and algorithm exports.
- Add Q# utility operation (
MakeHadamardCircuit) and a new Python integration test module that validates expectations on a water benchmark.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py | Adds abstract generator + factory for the new algorithm type. |
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py | Implements Q# and Qiskit Hadamard-test circuit generators. |
| python/src/qdk_chemistry/algorithms/hadamard_test_generator/init.py | Exposes the factory for registry integration. |
| python/src/qdk_chemistry/algorithms/registry.py | Registers the new factory and built-in generator instances. |
| python/src/qdk_chemistry/algorithms/init.py | Exports HadamardTestGenerator in the public algorithms API surface. |
| python/src/qdk_chemistry/utils/qsharp/HadamardTest.qs | Adds Q# operation to construct a Hadamard test circuit in X/Y/Z bases. |
| python/src/qdk_chemistry/utils/qsharp/init.py | Ensures the new Q# file is loaded via the Q# utils lazy loader. |
| python/tests/test_hadamard_test_generator.py | Adds integration tests for Q# and Qiskit generators + input validation tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
📊 Coverage Summary
Detailed Coverage ReportsC++ Coverage DetailsPython Coverage DetailsPybind11 Coverage Details |
python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
| statePrep(system_q); | ||
|
|
||
| H(control_q); | ||
| repControlledEvolution(control_q, system_q); |
There was a problem hiding this comment.
@RushiGong @swernli is there a benefit for using the within statement over this?
There was a problem hiding this comment.
within {...} apply {...} will automatically append the adjoint of the within block after the apply block complete.
The useful things here are that Q# has MResetX and MResetY for X and Y basis measurements, we do not have to apply basis changes ourselves.
There was a problem hiding this comment.
One trivial issue, within {H(control_q)} apply {...} cannot be used together with MResetX or MResetY.
There was a problem hiding this comment.
just catching up on this one, missed it in my notifications...
Within-apply has some subtle benefits in addition to the automatic uncompute applied to the within-block. For example, Controlled and Adjoint generation are enlightened to recognize within-apply and not add any functor application to invocations within that block. The simplest example of this is imagining an implementation of SWAP in terms of CNOT. If you implement it this way:
CNOT(a, b);
CNOT(b, a);
CNOT(a, b);Then when you apply a Controlled functor to that operation it will effectively put the controls on all three operations, becoming the equivalent of:
Controlled CNOT(ctrls, (a, b));
Controlled CNOT(ctrls, (b, a));
Controlled CNOT(ctrls, (a, b));But if you wrote the original using within-apply:
within {
CNOT(a, b);
} apply {
CNOT(b, a);
}Then the controlled generation logic recognizes the compute-uncompute pattern and only propagates controls onto apply-block, becoming the equivalent of:
CNOT(a, b);
Controlled CNOT(ctrls, (b, a));
CNOT(a, b);which ends up being cheaper and saving instructions overall. The same is true of generated adjoints, where the within-block does not need to be adjointed and only the calls in the apply-block are modified.
It's overall a nice way to convey intent of the algorithm such that the compiler can then understand how to handle that code.
python/src/qdk_chemistry/algorithms/hadamard_test_generator/hadamard_test_generator.py
Outdated
Show resolved
Hide resolved
python/src/qdk_chemistry/algorithms/hadamard_test_generator/base.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Adds a new Hadamard-test circuit-generation algorithm to QDK/Chemistry, with both Q# and Qiskit backends, wired into the algorithm registry/plugin system and covered by new functional/validation tests.
Changes:
- Introduce
HadamardTestabstractions (HadamardTestBasis, factory, shared execution flow) plus a Q#-backed implementation (QdkHadamardTest). - Add a Qiskit-backed implementation (
QiskitHadamardTest) and register it via the Qiskit plugin loader. - Add a new Q# utility operation (
HadamardTest.qs) and a new Python test module for functional/validation coverage.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_hadamard_test.py | Adds functional and input-validation tests for Hadamard test (water benchmark, X/Y bases). |
| python/src/qdk_chemistry/utils/qsharp/HadamardTest.qs | New Q# operation implementing the Hadamard test measurement workflow. |
| python/src/qdk_chemistry/utils/qsharp/init.py | Loads the new Q# utility source file as part of QSHARP_UTILS. |
| python/src/qdk_chemistry/plugins/qiskit/hadamard_test.py | Adds Qiskit implementation for building Hadamard-test circuits and returning OpenQASM3. |
| python/src/qdk_chemistry/plugins/qiskit/init.py | Registers the new Qiskit Hadamard-test algorithm when Qiskit is available. |
| python/src/qdk_chemistry/algorithms/registry.py | Registers the new Hadamard-test factory and default QDK implementation in the global registry. |
| python/src/qdk_chemistry/algorithms/hadamard_test/base.py | Defines the Hadamard-test algorithm base class, basis enum, and factory. |
| python/src/qdk_chemistry/algorithms/hadamard_test/hadamard_test.py | Implements the Q#-backed QdkHadamardTest circuit generator. |
| python/src/qdk_chemistry/algorithms/hadamard_test/init.py | Exposes the Hadamard-test factory module entrypoint. |
| python/src/qdk_chemistry/algorithms/init.py | Updates algorithm package exports (but currently introduces an export/import mismatch). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.