-
Notifications
You must be signed in to change notification settings - Fork 21
Separate QPE circuit builder with simulator #471
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7be089d
initial commit
YingrongChen 1f36805
fix pre-commit
YingrongChen 4415b95
add tests for circuit builder
YingrongChen 04cee6c
run pre-commit
YingrongChen 8042f51
add QiskitStandardPhaseEstimationBuilder
YingrongChen 69ca7ef
rm create_iteration_circuit and get_circuits
YingrongChen a5359e0
rename the circuit builder and update _run_impl
RushiGong e701ae1
Merge branch 'main' into feature/cyr/qpe_builder
RushiGong 9fd8f31
resolve AI code review comments
RushiGong 4cf8ecc
merge main
RushiGong 2c1c66a
add num bits check in standard qpe
RushiGong b657adf
Merge branch 'main' into feature/cyr/qpe_builder
RushiGong cf51a2a
apply AI code review comment
RushiGong 59e59f4
Merge branch 'main' into feature/cyr/qpe_builder
RushiGong ece7e3b
apply AI code review comment
RushiGong a028f81
separate circuit builders
RushiGong b4550d3
fix test
RushiGong 706284d
fix example and notebook
RushiGong 293966d
fix tests
RushiGong fbc9cb4
fix standard qpe test and AI comments
RushiGong 453a1c0
merge main
RushiGong 4bd8d46
fix pre-commit and tests
RushiGong 56559c0
add documentation
RushiGong 7230ed6
fix failed example python script
RushiGong a5760ff
fix AI comments and skipped tests
RushiGong d03d8d6
add qdk to algorithm name
RushiGong 3e06838
merge main
RushiGong ea88920
apply AI code review comment
RushiGong 2231222
Merge branch 'main' into feature/cyr/qpe_builder
RushiGong f2c6b6c
Merge branch 'main' into feature/cyr/qpe_builder
RushiGong 8ee92ef
apply AI code review comments
RushiGong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
docs/source/_static/examples/python/qpe_circuit_builder.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """QpeCircuitBuilder usage examples.""" | ||
|
|
||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| ################################################################################ | ||
| # start-cell-configure-iqpe | ||
| from qdk_chemistry.algorithms import create | ||
| from qdk_chemistry.data import AlgorithmRef | ||
|
|
||
| # Create iterative QPE with circuit builder configuration | ||
| controlled_circuit_mapper = AlgorithmRef("controlled_circuit_mapper", "pauli_sequence") | ||
| unitary_builder = AlgorithmRef("hamiltonian_unitary_builder", "trotter", time=0.1) | ||
| iqpe_circuit_builder = create("qpe_circuit_builder", "qdk_iterative", num_bits=10) | ||
| iqpe_circuit_builder.settings().set( | ||
| "controlled_circuit_mapper", controlled_circuit_mapper | ||
| ) | ||
| iqpe_circuit_builder.settings().set("unitary_builder", unitary_builder) | ||
| # end-cell-configure-iqpe | ||
| ################################################################################ | ||
|
|
||
| ################################################################################ | ||
| # start-cell-configure-standard | ||
| from qdk_chemistry.algorithms import create | ||
| from qdk_chemistry.data import AlgorithmRef | ||
|
|
||
| # Create standard QPE with circuit builder configuration | ||
| controlled_circuit_mapper = AlgorithmRef("controlled_circuit_mapper", "pauli_sequence") | ||
| unitary_builder = AlgorithmRef("hamiltonian_unitary_builder", "trotter", time=0.1) | ||
| qpe_circuit_builder = create( | ||
| "qpe_circuit_builder", "qiskit_standard", num_bits=10, qft_do_swaps=True | ||
| ) | ||
| qpe_circuit_builder.settings().set( | ||
| "controlled_circuit_mapper", controlled_circuit_mapper | ||
| ) | ||
| qpe_circuit_builder.settings().set("unitary_builder", unitary_builder) | ||
| # end-cell-configure-standard | ||
| ################################################################################ | ||
|
|
||
| ################################################################################ | ||
| # start-cell-run | ||
| import numpy as np | ||
| from qdk_chemistry.algorithms import create | ||
| from qdk_chemistry.data import Structure | ||
|
|
||
| # 1. Setup molecule | ||
| coords = np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 1.4]]) | ||
| symbols = ["H", "H"] | ||
| structure = Structure(coords, symbols=symbols) | ||
|
|
||
| # 2. SCF | ||
| scf_solver = create("scf_solver") | ||
| E_scf, wfn_scf = scf_solver.run( | ||
| structure, charge=0, spin_multiplicity=1, basis_or_guess="sto-3g" | ||
| ) | ||
|
|
||
| # 3. Hamiltonian construction | ||
| hamiltonian_constructor = create("hamiltonian_constructor") | ||
| hamiltonian = hamiltonian_constructor.run(wfn_scf.get_orbitals()) | ||
|
|
||
| # 4. Multi-configuration calculation (reference state) | ||
| cas_solver = create("multi_configuration_calculator") | ||
| E_cas, wfn_cas = cas_solver.run(hamiltonian, 1, 1) | ||
|
|
||
| # 5. Qubit mapping | ||
| from qdk_chemistry.data import MajoranaMapping | ||
|
|
||
| n_spin_orbitals = 2 * hamiltonian.get_orbitals().get_num_molecular_orbitals() | ||
| qubit_mapper = create("qubit_mapper") | ||
| qubit_ham = qubit_mapper.run( | ||
| hamiltonian, MajoranaMapping.jordan_wigner(n_spin_orbitals) | ||
| ) | ||
|
|
||
| # 6. State preparation | ||
| state_prep = create("state_prep", "sparse_isometry_gf2x") | ||
| circuit = state_prep.run(wfn_cas) | ||
|
|
||
| # 7. Create and run IQPE circuit builder with nested algorithm settings | ||
| from qdk_chemistry.data import AlgorithmRef | ||
|
|
||
| controlled_circuit_mapper = AlgorithmRef("controlled_circuit_mapper", "pauli_sequence") | ||
| unitary_builder = AlgorithmRef("hamiltonian_unitary_builder", "trotter", time=0.1) | ||
| iqpe_circuit_builder = create("qpe_circuit_builder", "qdk_iterative", num_bits=4) | ||
| iqpe_circuit_builder.settings().set( | ||
| "controlled_circuit_mapper", controlled_circuit_mapper | ||
| ) | ||
| iqpe_circuit_builder.settings().set("unitary_builder", unitary_builder) | ||
|
|
||
| iqpe_circuits = iqpe_circuit_builder.run( | ||
| state_preparation=circuit, | ||
| qubit_hamiltonian=qubit_ham, | ||
| ) | ||
|
|
||
| # 8. Print the generated circuits for each bit | ||
| for idx, circ in enumerate(iqpe_circuits): | ||
| print(f"Bit {idx}:") | ||
| print(circ.get_qsharp_circuit()) | ||
| # end-cell-run | ||
| ################################################################################ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.