Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Windows support redux
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatyping committed Jul 25, 2020
1 parent b2378dc commit cc13aac
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
43 changes: 22 additions & 21 deletions examples/average_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
from qsearch import unitaries, advanced_unitaries
import time

with qsearch.Project("benchmarks") as project:
project.add_compilation("qft2", unitaries.qft(4))
project.add_compilation("qft3", unitaries.qft(8))
project.add_compilation("fredkin", unitaries.fredkin)
project.add_compilation("toffoli", unitaries.toffoli)
project.add_compilation("peres", unitaries.peres)
project.add_compilation("or", unitaries.logical_or)
if __name__ == "__main__":
with qsearch.Project("benchmarks") as project:
project.add_compilation("qft2", unitaries.qft(4))
project.add_compilation("qft3", unitaries.qft(8))
project.add_compilation("fredkin", unitaries.fredkin)
project.add_compilation("toffoli", unitaries.toffoli)
project.add_compilation("peres", unitaries.peres)
project.add_compilation("or", unitaries.logical_or)

project.add_compilation("miro", advanced_unitaries.mirogate)
project.add_compilation("hhl", advanced_unitaries.HHL)
project.add_compilation("miro", advanced_unitaries.mirogate)
project.add_compilation("hhl", advanced_unitaries.HHL)

# run the benchmarks script with default settings 10x and average the timing results
# reported times are between 0.1s and 5s on my 2018 Macbook Pro
# run the benchmarks script with default settings 10x and average the timing results
# reported times are between 0.1s and 5s on my 2018 Macbook Pro

times = {}
for compilation in project.compilations:
times[compilation] = 0

for _ in range(10):
project.reset()
project.run()
times = {}
for compilation in project.compilations:
times[compilation] += project.get_time(compilation)
times[compilation] = 0

for _ in range(10):
project.reset()
project.run()
for compilation in project.compilations:
times[compilation] += project.get_time(compilation)

for compilation in project.compilations:
print(f'Compilation {compilation} took {times[compilation]/10}s on average.')
for compilation in project.compilations:
print(f'Compilation {compilation} took {times[compilation]/10}s on average.')
55 changes: 28 additions & 27 deletions examples/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
from qsearch import unitaries, advanced_unitaries, leap_compiler, multistart_solver, parallelizer
import time

# create the project
with qsearch.Project("benchmarks") as project:
# add a unitaries to compile
project.add_compilation("qft2", unitaries.qft(4))
project.add_compilation("qft3", unitaries.qft(8))
project.add_compilation("fredkin", unitaries.fredkin)
project.add_compilation("toffoli", unitaries.toffoli)
project.add_compilation("peres", unitaries.peres)
project.add_compilation("or", unitaries.logical_or)
if __name__ == "__main__":
# create the project
with qsearch.Project("benchmarks") as project:
# add a unitaries to compile
project.add_compilation("qft2", unitaries.qft(4))
project.add_compilation("qft3", unitaries.qft(8))
project.add_compilation("fredkin", unitaries.fredkin)
project.add_compilation("toffoli", unitaries.toffoli)
project.add_compilation("peres", unitaries.peres)
project.add_compilation("or", unitaries.logical_or)

project.add_compilation("miro", advanced_unitaries.mirogate)
project.add_compilation("hhl", advanced_unitaries.HHL)
project.add_compilation("miro", advanced_unitaries.mirogate)
project.add_compilation("hhl", advanced_unitaries.HHL)

# 4 qubit benchmarks (WARNING: These may take days to run.)
#project.add_compilation("qft4", unitaries.qft(16))
#project.add_compilation("full adder", unitaries.full_adder)
#project.add_compilation("ethylene", advanced_unitaries.ethylene)
# 4 qubit benchmarks (WARNING: These may take days to run.)
#project.add_compilation("qft4", unitaries.qft(16))
#project.add_compilation("full adder", unitaries.full_adder)
#project.add_compilation("ethylene", advanced_unitaries.ethylene)

# compiler configuration example
#project["gateset"] = qsearch.gatesets.QubitCNOTRing() # use this to synthesize for the ring topology instead of the default line topology
#project["solver"] = qsearch.solver.BFGS_Jac_Solver() # use this to force the compiler to use the BFGS solver instead of using the default setting
#project["verbosity"] = 2 # use this to have more information reported to stdout and the log files, or set it to 0 to disable logging altogether
# once everything is set up, let the project run!
project.run()
# compiler configuration example
#project["gateset"] = qsearch.gatesets.QubitCNOTRing() # use this to synthesize for the ring topology instead of the default line topology
#project["solver"] = qsearch.solver.BFGS_Jac_Solver() # use this to force the compiler to use the BFGS solver instead of using the default setting
#project["verbosity"] = 2 # use this to have more information reported to stdout and the log files, or set it to 0 to disable logging altogether
# once everything is set up, let the project run!
project.run()


# once its done you can use the following functions to get output
# compilation_names = project.compilations # returns a list of the names that were specified when adding unitaries
# circuit, vector = project.get_result(compilation_names[0]) # get a circuit/vector combination, which is the search_compiler format for describing finished circuits
# project.assemble(compilation_names[0], write_location="my_circuit.qasm") # export the circuit as openqasm
# project.assemble(compilation_names[0], language=assembly.ASSEMBLY_QISKIT, write_location="my_circuit.py") # export the circuit as a qiskit script
# once its done you can use the following functions to get output
# compilation_names = project.compilations # returns a list of the names that were specified when adding unitaries
# circuit, vector = project.get_result(compilation_names[0]) # get a circuit/vector combination, which is the search_compiler format for describing finished circuits
# project.assemble(compilation_names[0], write_location="my_circuit.qasm") # export the circuit as openqasm
# project.assemble(compilation_names[0], language=assembly.ASSEMBLY_QISKIT, write_location="my_circuit.py") # export the circuit as a qiskit script

# Read the wiki for more information and more features: https://github.com/WolfLink/search_compiler/wiki
# Read the wiki for more information and more features: https://github.com/WolfLink/search_compiler/wiki
9 changes: 6 additions & 3 deletions qsearch/parallelizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def done(self):

class MultiprocessingParallelizer(Parallelizer):
def __init__(self, options):
ctx = get_context("fork")
if sys.platform != 'win32':
ctx = get_context('fork')
else:
ctx = get_context()
options.set_smart_defaults(num_tasks=default_num_tasks)
self.pool = ctx.Pool(options.num_tasks)
self.process_func = partial(evaluate_step, options=options)
Expand All @@ -42,8 +45,8 @@ def done(self):
class ProcessPoolParallelizer(Parallelizer):
def __init__(self, options):
options.set_smart_defaults(num_tasks=default_num_tasks)
if sys.version_info >= (3, 8, 0):
ctx = get_context("fork")
if sys.version_info >= (3, 8, 0) and sys.platform != 'win32':
ctx = get_context('fork')
self.pool = ProcessPoolExecutor(options.num_tasks, mp_context=ctx)
else:
self.pool = ProcessPoolExecutor(options.num_tasks)
Expand Down

0 comments on commit cc13aac

Please sign in to comment.