-
Notifications
You must be signed in to change notification settings - Fork 173
QRE Update #3090
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
QRE Update #3090
Changes from 72 commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
98edf5f
Add QRE code owners for PR review assignment. (#2853)
msoeken 24f5344
Merge branch 'main' into feature/qre
msoeken 413cba3
Types to define ISAs and ISA requirements (#2856)
msoeken dcc53ed
Enumerate ISAs with transforms and queries (#2894)
msoeken 0fae825
Initial commit; hypergraph module added (#2909)
brad-lackey c0308e9
Data types for traces, transforms, Pareto frontiers (#2907)
msoeken 4c706d4
Magnets: added greedy edge coloring method, and two simple 1d lattice…
brad-lackey 50d9bbc
Magnets: Base classes for Trotter-Suzuki expansions (#2913)
brad-lackey c8b973a
Base class for magnet models (#2914)
brad-lackey 29c03ba
Magnets: more basic geometries (#2919)
brad-lackey ecd7e23
ISA queries, trace queries, and enumeration. (#2916)
msoeken aee65fa
Magnets: changed implementation of edge coloring (#2925)
brad-lackey b3f5198
Magnets: refactored Trotter step classes and added Suzuki and Yoshida…
brad-lackey b026182
New ISA and ISARequirements function (#2923)
msoeken 289a181
Track instruction origin (#2933)
msoeken 80ec786
Refactor trace and result properties (#2952)
msoeken bcc31d0
Brlackey/magnets ising model (#2955)
brad-lackey e19e6a1
Magnets: added utilities (#2965)
brad-lackey 511c953
Various RE models and some API enhancements (#2963)
msoeken 696f0dc
Merge branch 'main' into feature/qre
msoeken 41bf7b5
Magnets: revisions to (hypergraph) coloring (#2972)
brad-lackey 674124f
Minor changes to colorings and term representation; added Heisenberg …
brad-lackey 1040016
More edits to functionality
brad-lackey 739d087
Merge branch 'feature/qre' of github.com:microsoft/qdk into feature/qre
brad-lackey df1f2c2
Fix magnet tests (#3006)
msoeken bdddb70
Resource estimation results table (#2973)
msoeken a7d15c9
Refactor property keys from string to integer and add estimation impr…
msoeken 8b1b520
QIR interop in QRE (#3018)
msoeken 5ce010a
Split Yoked SC model into two codes (#3019)
msoeken 0c86dbb
Use Rust parallelism for estimation with post processing (#3025)
msoeken dcadb5c
Fixes bucketing logic to distribute rotations to match the right dept…
msoeken 317ff6a
Graph-based ISA pruning for resource estimation (#3031)
msoeken 5de8ec1
Magnets: modified Trotter expansion classes and added Cirq output. (#…
brad-lackey 1d5b568
Two small fixes to QRE 3 (#3041)
msoeken cd308a9
Return ISA as a pandas data frame (#3042)
msoeken 8597d0a
Temporary plotting for estimation results (#3043)
msoeken 232df87
Get the name of a known property ID as a string (#3044)
msoeken f1ceab8
Trace properties for logical qubits (#3045)
msoeken 9d87a9c
Expose ISA requirements of a trace (#3046)
msoeken dabfa32
Trace ISA requirements (#3050)
msoeken c22cf5c
Plot multiple estimation tables in single plot (#3054)
msoeken 0b92123
Create QRE traces from cirq circuits (#3060)
msoeken bc9a3c7
Merge branch 'main' into feature/qre
msoeken 358171d
File missing from previous merge.
msoeken 8f08a2b
Reorganize files and spit up large files in QRE (#3069)
msoeken c1bc4fc
Complete and consistent docs for QRE (#3077)
msoeken 556e8a4
Remove matplotlib from tests (#3078)
msoeken cf70736
Adjust pruning logic for graph based search (#3089)
msoeken 04f1e46
Merge branch 'main' into feature/qre
msoeken e5708d1
Fix CODEOWNERS file.
msoeken 1c3b049
Enhance application models.
msoeken 204c3e0
Address or postpone TODOs.
msoeken 9d63b78
OpenQASM application model.
msoeken 7c24ece
Re-export qre from the qdk package as extra dependency.
msoeken 4b1acbf
Convenience functions for custom properties and property columns.
msoeken 32ce932
API and doc improvements.
msoeken ce85591
Fix problem with negative exponents in cirq interop.
msoeken 923a356
Move magnets module into qre.application.
msoeken 017ebfc
Add telemetry events for QRE.
msoeken fc899f9
Cirq interop handles memory/compute qubits.
msoeken 0f31c20
Make RoundBasedFactory not expose lattice surgery instructions into p…
msoeken ef339bb
Clarify memory qubit tracking in Cirq interop.
msoeken 6d801f2
Addressing reviewer comments.
msoeken 74220b9
Missed pandas dependency in all.
msoeken 3aea86f
Remove spurious commented code
brad-lackey c379b59
Instruction IDs and property keys.
msoeken 42666f3
Properties.
msoeken a4f812c
Instruction IDs.
msoeken 9f00d3b
Add diagnostic code to error type.
msoeken 8674a75
qre extras in qsharp package.
msoeken e6474c3
Move magnets to applications module in qsharp and qdk.
msoeken 2f3b526
Merge branch 'main' into feature/qre
msoeken 3eb898b
PyQIR API updates.
msoeken 543f021
Apply suggestion from @billti
billti 2405dba
Merge remote-tracking branch 'origin/main' into feature/qre
billti ecce077
Exclude cirq on Windows ARM64
billti cd3f5c3
More cirq preconditions
billti 8691f67
Merge remote-tracking branch 'origin/main' into feature/qre
billti 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,105 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import timeit | ||
| from dataclasses import dataclass, KW_ONLY, field | ||
| from qsharp.qre import linear_function, generic_function | ||
| from qsharp.qre._architecture import _make_instruction | ||
| from qsharp.qre.models import ( | ||
| GateBased, | ||
| SurfaceCode, | ||
| TwoDimensionalYokedSurfaceCode, | ||
| Litinski19Factory, | ||
| ) | ||
| from qsharp.qre._enumeration import _enumerate_instances | ||
|
|
||
|
|
||
| def bench_enumerate_instances(): | ||
| # Measure performance of enumerating instances with a large domain | ||
| @dataclass | ||
| class LargeDomain: | ||
| _: KW_ONLY | ||
| param1: int = field(default=0, metadata={"domain": range(1000)}) | ||
| param2: bool | ||
|
|
||
| number = 100 | ||
|
|
||
| duration = timeit.timeit( | ||
| "list(_enumerate_instances(LargeDomain))", | ||
| globals={ | ||
| "_enumerate_instances": _enumerate_instances, | ||
| "LargeDomain": LargeDomain, | ||
| }, | ||
| number=number, | ||
| ) | ||
|
|
||
| print(f"Enumerating instances took {duration / number:.6f} seconds on average.") | ||
|
|
||
|
|
||
| def bench_enumerate_isas(): | ||
| ctx = GateBased(gate_time=50, measurement_time=100).context() | ||
|
|
||
| # Hierarchical factory using from_components | ||
| query = ( | ||
| SurfaceCode.q() | ||
| * TwoDimensionalYokedSurfaceCode.q(source=SurfaceCode.q()) | ||
| * Litinski19Factory.q() | ||
| ) | ||
|
|
||
| number = 100 | ||
| duration = timeit.timeit( | ||
| "list(query.enumerate(ctx))", | ||
| globals={ | ||
| "query": query, | ||
| "ctx": ctx, | ||
| }, | ||
| number=number, | ||
| ) | ||
|
|
||
| print(f"Enumerating ISAs took {duration / number:.6f} seconds on average.") | ||
|
|
||
|
|
||
| def bench_function_evaluation_linear(): | ||
| fl = linear_function(12) | ||
|
|
||
| inst = _make_instruction(42, 0, None, 1, fl, None, 1.0, {}) | ||
| number = 1000 | ||
| duration = timeit.timeit( | ||
| "inst.space(5)", | ||
| globals={ | ||
| "inst": inst, | ||
| }, | ||
| number=number, | ||
| ) | ||
|
|
||
| print( | ||
| f"Evaluating linear function took {duration / number:.6f} seconds on average." | ||
| ) | ||
|
|
||
|
|
||
| def bench_function_evaluation_generic(): | ||
| def func(arity: int) -> int: | ||
| return 12 * arity | ||
|
|
||
| fg = generic_function(func) | ||
|
|
||
| inst = _make_instruction(42, 0, None, 1, fg, None, 1.0, {}) | ||
| number = 1000 | ||
| duration = timeit.timeit( | ||
| "inst.space(5)", | ||
| globals={ | ||
| "inst": inst, | ||
| }, | ||
| number=number, | ||
| ) | ||
|
|
||
| print( | ||
| f"Evaluating linear function took {duration / number:.6f} seconds on average." | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| bench_enumerate_instances() | ||
| bench_enumerate_isas() | ||
| bench_function_evaluation_linear() | ||
| bench_function_evaluation_generic() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. |
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,14 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| # flake8: noqa F403 | ||
| # pyright: ignore[reportWildcardImportFromLibrary] | ||
|
|
||
| """Magnets application module. | ||
|
|
||
| Re-exports from the submodules.""" | ||
|
|
||
| from .geometry import * | ||
| from .models import * | ||
| from .trotter import * | ||
| from .utilities import * |
22 changes: 22 additions & 0 deletions
22
source/pip/qsharp/applications/magnets/geometry/__init__.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,22 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Geometry module for representing quantum system topologies. | ||
|
|
||
| This module provides hypergraph data structures for representing the | ||
| geometric structure of quantum systems, including lattice topologies | ||
| and interaction graphs. | ||
| """ | ||
|
|
||
| from .complete import CompleteBipartiteGraph, CompleteGraph | ||
| from .lattice1d import Chain1D, Ring1D | ||
| from .lattice2d import Patch2D, Torus2D | ||
|
|
||
| __all__ = [ | ||
| "CompleteBipartiteGraph", | ||
| "CompleteGraph", | ||
| "Chain1D", | ||
| "Ring1D", | ||
| "Patch2D", | ||
| "Torus2D", | ||
| ] |
150 changes: 150 additions & 0 deletions
150
source/pip/qsharp/applications/magnets/geometry/complete.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,150 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """Complete graph geometries for quantum simulations. | ||
|
|
||
| This module provides classes for representing complete graphs and complete | ||
| bipartite graphs as hypergraphs. These structures are useful for quantum | ||
| systems with all-to-all or bipartite all-to-all interactions. | ||
| """ | ||
|
|
||
| from ..utilities import ( | ||
| Hyperedge, | ||
| Hypergraph, | ||
| HypergraphEdgeColoring, | ||
| ) | ||
|
|
||
|
|
||
| class CompleteGraph(Hypergraph): | ||
| """A complete graph where every vertex is connected to every other vertex. | ||
|
|
||
| In a complete graph K_n, there are n vertices and n(n-1)/2 edges, | ||
| with each pair of distinct vertices connected by exactly one edge. | ||
|
|
||
| Attributes: | ||
| n: Number of vertices in the graph. | ||
|
|
||
| Example: | ||
|
|
||
| .. code-block:: python | ||
| >>> graph = CompleteGraph(4) | ||
| >>> graph.nvertices | ||
| 4 | ||
| >>> graph.nedges | ||
| 6 | ||
| """ | ||
|
|
||
| def __init__(self, n: int, self_loops: bool = False) -> None: | ||
| """Initialize a complete graph. | ||
|
|
||
| Args: | ||
| n: Number of vertices in the graph. | ||
| self_loops: If True, include self-loop edges on each vertex | ||
| for single-site terms. | ||
| """ | ||
| if self_loops: | ||
| _edges = [Hyperedge([i]) for i in range(n)] | ||
| else: | ||
| _edges = [] | ||
|
|
||
| # Add all pairs of vertices | ||
| for i in range(n): | ||
| for j in range(i + 1, n): | ||
| _edges.append(Hyperedge([i, j])) | ||
| super().__init__(_edges) | ||
|
|
||
| self.n = n | ||
|
|
||
| def edge_coloring(self) -> HypergraphEdgeColoring: | ||
| """Compute edge coloring for this complete graph.""" | ||
| coloring = HypergraphEdgeColoring(self) | ||
| for edge in self.edges(): | ||
| if len(edge.vertices) == 1: | ||
| coloring.add_edge(edge, -1) | ||
| else: | ||
| if self.n % 2 == 0: | ||
| i, j = edge.vertices | ||
| m = self.n - 1 | ||
| if j == m: | ||
| coloring.add_edge(edge, i) | ||
| elif (j - i) % 2 == 0: | ||
| coloring.add_edge(edge, (j - i) // 2) | ||
| else: | ||
| coloring.add_edge(edge, (j - i + m) // 2) | ||
| else: | ||
| m = self.n | ||
| i, j = edge.vertices | ||
| if (j - i) % 2 == 0: | ||
| coloring.add_edge(edge, (j - i) // 2) | ||
| else: | ||
| coloring.add_edge(edge, (j - i + m) // 2) | ||
| return coloring | ||
|
|
||
|
|
||
| class CompleteBipartiteGraph(Hypergraph): | ||
| """A complete bipartite graph with two vertex sets. | ||
|
|
||
| In a complete bipartite graph K_{m,n} (m <= n), there are m + n | ||
| vertices partitioned into two sets of sizes m and n. Every vertex | ||
| in the first set is connected to every vertex in the second set, | ||
| giving m * n edges total. | ||
|
|
||
| Vertices 0 to m-1 form the first set, and vertices m to m+n-1 | ||
| form the second set. | ||
|
|
||
| Attributes: | ||
| m: Number of vertices in the first set. | ||
| n: Number of vertices in the second set. | ||
|
|
||
| Requires: | ||
| m <= n | ||
|
|
||
| Example: | ||
|
|
||
| .. code-block:: python | ||
| >>> graph = CompleteBipartiteGraph(2, 3) | ||
| >>> graph.nvertices | ||
| 5 | ||
| >>> graph.nedges | ||
| 6 | ||
| """ | ||
|
|
||
| def __init__(self, m: int, n: int, self_loops: bool = False) -> None: | ||
| """Initialize a complete bipartite graph. | ||
|
|
||
| Args: | ||
| m: Number of vertices in the first set (vertices 0 to m-1). | ||
| n: Number of vertices in the second set (vertices m to m+n-1). | ||
| self_loops: If True, include self-loop edges on each vertex | ||
| for single-site terms. | ||
| """ | ||
| assert m <= n, "Require m <= n for CompleteBipartiteGraph." | ||
| total_vertices = m + n | ||
|
|
||
| if self_loops: | ||
| _edges = [Hyperedge([i]) for i in range(total_vertices)] | ||
|
|
||
| else: | ||
| _edges = [] | ||
|
|
||
| # Connect every vertex in first set to every vertex in second set | ||
| for i in range(m): | ||
| for j in range(m, m + n): | ||
| _edges.append(Hyperedge([i, j])) | ||
| super().__init__(_edges) | ||
|
|
||
| self.m = m | ||
| self.n = n | ||
|
|
||
| def edge_coloring(self) -> HypergraphEdgeColoring: | ||
| """Compute edge coloring for this complete bipartite graph.""" | ||
| coloring = HypergraphEdgeColoring(self) | ||
| m = self.m | ||
| n = self.n | ||
| for edge in self.edges(): | ||
| if len(edge.vertices) == 1: | ||
| coloring.add_edge(edge, -1) | ||
| else: | ||
| i, j = edge.vertices | ||
| coloring.add_edge(edge, (i + j - m) % n) | ||
| return coloring |
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.