This repository has been archived by the owner on Nov 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
190 additions
and
346 deletions.
There are no files selected for viewing
This file contains 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 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,21 @@ | ||
""" | ||
Example synthesis of a 4-qubit QFT program | ||
using QFAST and the QSearch Tool. | ||
""" | ||
|
||
|
||
import numpy as np | ||
|
||
from qfast import synthesize | ||
|
||
|
||
# You can enable verbose logging with the following two lines. | ||
# import logging | ||
# logging.getLogger( "qfast" ).setLevel( logging.DEBUG ) | ||
|
||
# Read the qft4 file in | ||
qft4 = np.loadtxt( "qft4.unitary", dtype = np.complex128 ) | ||
|
||
# Synthesize the qft4 unitary and print the resulting qasm code | ||
print( synthesize( qft4, tool = "QSearchTool" ) ) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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,63 @@ | ||
""" | ||
This module implements QSearch's Leap Compiler | ||
as a native tool plugin to QFAST. | ||
""" | ||
|
||
import qsearch | ||
import qsearch | ||
from qsearch import unitaries, advanced_unitaries, leap_compiler, multistart_solvers, parallelizers, reoptimizing_compiler | ||
|
||
from qfast import utils | ||
from qfast.instantiation import nativetool | ||
|
||
|
||
class QSearchTool ( nativetool.NativeTool ): | ||
"""Synthesize tool built on QSearch's Leap Compiler.""" | ||
|
||
def get_maximum_size ( self ): | ||
""" | ||
The maximum size of a unitary matrix (in qubits) that can be | ||
decomposed with this tool. | ||
Returns: | ||
(int): The qubit count this tool can handle. | ||
""" | ||
|
||
# Larger unitaries can be decomposed with this tool, | ||
# however, solution quality is best at 3 qubits. | ||
return 3 | ||
|
||
def synthesize ( self, utry ): | ||
""" | ||
Synthesis function with this tool. | ||
Args: | ||
utry (np.ndarray): The unitary to synthesize. | ||
Returns | ||
qasm (str): The synthesized QASM output. | ||
Raises: | ||
TypeError: If utry is not a valid unitary. | ||
ValueError: If the utry has invalid dimensions. | ||
""" | ||
|
||
if not utils.is_unitary( utry, tol = 1e-14 ): | ||
raise TypeError( "utry must be a valid unitary." ) | ||
|
||
if utry.shape[0] > 2 ** self.get_maximum_size(): | ||
raise ValueError( "utry has incorrect dimensions." ) | ||
|
||
solver = qsearch.solvers.LeastSquares_Jac_SolverNative() | ||
assembler_style = qsearch.assembler.ASSEMBLY_IBMOPENQASM | ||
options = qsearch.options.Options() | ||
options.target = utry | ||
options.verbosity = 0 | ||
compiler = qsearch.leap_compiler.LeapCompiler( solver = solver ) | ||
output = compiler.compile( options ) | ||
output = qsearch.assembler.assemble( output["structure"], | ||
output["vector"], | ||
assembler_style ) | ||
return output | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
qfast>=1.0.0 | ||
search_compiler>=1.2.0 | ||
qfast>=2.0.0 | ||
qsearch>=2.0.0a1 |
This file contains 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
File renamed without changes.
File renamed without changes.
Empty file.
This file contains 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,16 @@ | ||
import numpy as np | ||
import unittest as ut | ||
|
||
from qfast.instantiation.native.qs import QSearchTool | ||
|
||
|
||
class TestQSGetMaximumSize ( ut.TestCase ): | ||
|
||
def test_qs_get_maximum_size ( self ): | ||
qtool = QSearchTool() | ||
block_size = qtool.get_maximum_size() | ||
self.assertEqual( block_size, 3 ) | ||
|
||
|
||
if __name__ == '__main__': | ||
ut.main() |
Oops, something went wrong.