-
Notifications
You must be signed in to change notification settings - Fork 2.6k
CSP layout selector #3043
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
CSP layout selector #3043
Conversation
nice! |
With our benchmarks? Sure.. let me try. |
or just any random circuit. Also... There are a couple other projects in the pipeline that use Z3. Can you use that instead? It's probably faster than |
So I am guessing that this is in essence finding if there is a sub-graph of the device topology in which the circuit fits exactly. That would make it equivalent to the sub-graph isomorphism problem that is NP-Complete. |
Yes this is a satisfiability problem and should be exponential in the number of constraints, but I would like to put some numbers to the overheads so we can decide on a cutoff to use this pass vs. switching to a more scalable pass. |
I tried with cmap20 = CouplingMap(FakeTokyo().configuration().coupling_map)
nqubits = [4, 8, 12, 16, 20]
depths = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
for nqubit in nqubits:
for depth in depths:
circuit = random_circuit(nqubit, depth)
dag = circuit_to_dag(circuit)
pass_ = CSPLayout(cmap20)
import time
start = time.process_time()
pass_.run(dag)
print('nqubit:', nqubit, 'depth:', depth, time.process_time() - start)
print('None' if pass_.property_set['layout'] is None else 'not None') After |
|
While I agree z3 will probably be faster I just took a look at what the packaging story is for z3 since it's a C++ library with a Python API and that can be problematic in some cases especially for lesser used libs. It's not great besides not publishing releases to pypi match every project release https://pypi.org/project/z3-solver/#history vs https://github.com/Z3Prover/z3/releases (conda's in an even worse state: https://anaconda.org/asmeurer/z3/files the last release there was >3years ago). Then on the pypi side they don't publish osx wheels at all: https://pypi.org/project/z3-solver/#files which means we're making every mac user build it from source everytime we install qiskit. If we want to depend on z3 in the future, we'll probably have to work with them to improve their packaging. |
If at some stage we want to go heavyweight with this, we have a couple of in-house of CSP and SAT engines at our disposal - though C++, none Python. One comment though - both CSP and SAT are supposed exponential in the number of variables, but linear in number of constraints - in fact adding constraints many times greatly reduce runtime to solution because it efficiently prunes the search tree. Also, in our case the challenge is optimization - not satisfaction per se, so may need to consider engines which deal efficiently with soft constraints hierarchies. The other option is to do a log-search with adding an upper-bound constraint after each run, but this is a constraint CSP engines don't deal with very well. Z3 has an interface to soft constraints, but I never checked to what extent it can actually deal with them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reviewed all the code in depth yet, but the release notes (which are great details thanks for writing them) are in the wrong format. You need to use ResStructured Text: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html not markdown. The release notes get aggregated and put in an rst file which is then built by sphinx, and markdown won't match what sphinx is expecting.
Ups! Fixed in b445b41 |
requirements.txt
Outdated
@@ -7,3 +7,4 @@ ply>=3.10 | |||
psutil>=5 | |||
scipy>=1.0 | |||
sympy>=1.3 | |||
python-constraint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pass looks good to me, but it's adding an extra dependency for something that is not even invoked during the standard compilation/execution flow. can this be made optional or upon-request or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to put in the default pipeline, since its relatively fast. However, we can discuss it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 5faf45c
* some utf8 art * CSP layout * add dependency and test * bug in undirected cm * release notes and changelog * rest * docstring * optional req * lint * disable * import * lint
This PR models the layout selection problem as a constraint satisfaction problem.