Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Update for QFAST 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
edyounis committed Oct 9, 2020
1 parent 6368663 commit df9276d
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 346 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# QFAST-SC: SearchCompiler Plugin for QFAST
# QFAST-QS: QSearch Plugin for QFAST

QFAST-SC packages the SearchCompiler as a native tool plugin for [QFAST](https://github.com/edyounis/qfast). This package imports the SearchCompiler which can be found [here](https://github.com/WolfLink/search_compiler) and its license [here](https://https://github.com/WolfLink/search_compiler/blob/master/LICENSE).
QFAST-QS packages the SearchCompiler as a native tool plugin for [QFAST](https://github.com/BQSKit/qfast). This package imports the QSearch Compiler which can be found [here](https://github.com/BQSKit/qsearch) and its license [here](https://https://github.com/BQSKit/qsearch/blob/master/LICENSE).

## Installation

The best way to install this python package is with pip.

```
pip install qfast-sc
pip install qfast-qs
```

## Copyright
Expand Down
21 changes: 21 additions & 0 deletions examples/synthesize_qft4_qs.py
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" ) )

174 changes: 0 additions & 174 deletions examples/synthesize_qft4_sc.py

This file was deleted.

63 changes: 63 additions & 0 deletions qfast/instantiation/native/qs.py
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

56 changes: 0 additions & 56 deletions qfast/native/sc.py

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
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
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
if '' in requirements:
requirements.remove( '' )

setup( name = "qfast-sc",
version = "1.0.1",
description = "QFAST SearchCompiler Plugin",
setup( name = "qfast-qs",
version = "2.0.0",
description = "QFAST QSearch Plugin",
long_description = long_description,
long_description_content_type = "text/markdown",
url = "https://github.com/edyounis/qfast-sc",
url = "https://github.com/BQSKit/qfast-qs",
author = "Ed Younis",
author_email = "edyounis@berkeley.edu",
author_email = "edyounis@lbl.gov",
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
Expand All @@ -43,10 +43,10 @@
],
keywords = "quantum synthesis compilation",
project_urls = {
"Bug Tracker": "https://github.com/edyounis/qfast-sc/issues",
"Source Code": "https://github.com/edyounis/qfast-sc"
"Bug Tracker": "https://github.com/BQSKit/qfast-qs/issues",
"Source Code": "https://github.com/BQSKit/qfast-qs"
},
packages = [ "qfast.native" ],
packages = [ "qfast.instantiation.native" ],
install_requires = requirements,
python_requires = ">=3.5, <4",
zip_safe = False
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
16 changes: 16 additions & 0 deletions tests/instantiation/native/qs/test_get_maximum_size.py
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()
Loading

0 comments on commit df9276d

Please sign in to comment.