Giter Site home page Giter Site logo

xanaduai / blackbird Goto Github PK

View Code? Open in Web Editor NEW
68.0 15.0 27.0 3.11 MB

Blackbird is a quantum assembly language for continuous-variable quantum computation, that can be used to program Xanadu's quantum photonics hardware and Strawberry Fields simulator.

Home Page: https://quantum-blackbird.readthedocs.io

License: Apache License 2.0

ANTLR 1.06% Python 31.91% C++ 66.09% Makefile 0.45% CMake 0.48%
quantum quantum-computing quantum-programming-language quantum-optics quantum-algorithms parser antlr4

blackbird's Introduction

Blackbird Quantum Assembly Language

GitHub Workflow Status (branch)

Codecov coverage

Read the Docs

Blackbird is a quantum assembly language for continuous-variable quantum computation, that can be used to program Xanadu's quantum photonics hardware and Strawberry Fields simulator.

Features

The Blackbird repository contains three separate packages:

  • src: The Blackbird grammar specification in enhanced Brackus-Naur form
  • blackbird_python: to develop Blackbird parsers for integration with Python programs
  • blackbird_cpp: libraries and header files needed to develop Blackbird parsers for integration with C++ programs

All of these packages are independent, and can be installed separately without depending on one-another. However, if the grammar is ever modified, there is a command for updating the autogenerated parts of the Python and C++ parsers.

In addition, this repository contains:

  • example: Example Blackbird scripts
  • apps: Example Python/C++ applications using the above parsers

Getting started

Blackbird is a development library, designed to easily integrate Blackbird code into applications and interfaces.

To get the Blackbird grammar installed and running on your system, begin at the grammar installation guide. Then, familiarize yourself with the Blackbird's syntax and grammar for specifying photonic quantum circuits. You can even generate Blackbird parsers for any target language supported by ANTLR, including Java, C#, JavaScript, Go, and Swift.

If you only want to develop an application that makes use of the Python parser or the C++ parser, you can go directly to those sections and their corresponding installation guides.

How to cite

If you are doing research using Blackbird, please cite

Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. Strawberry Fields: A Software Platform for Photonic Quantum Computing 2018. arXiv:1804.03159

Support

If you are having issues, please let us know by posting the issue on our Github issue tracker.

License

Blackbird is free and open source, released under the Apache License, Version 2.0.

blackbird's People

Contributors

co9olguy avatar josh146 avatar kshitijc avatar sduquemesa avatar thisac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blackbird's Issues

[openSUSE] Build failed Visitor.cpp:558:5: error: control reaches end of non-void function

Hello,

I am trying to package python-quantum-blackbird to openSUSE Tumbleweed.
There was a suggesting that code at Visitor.cpp line 262 might have something to do with it.

python3-antlr4-python3-runtime-4.8-1
python3-numpy-1.18.4
python3-sympy-1.6
cmake-3.18.0
doxygen-1.8.18
gcc-c++-10-1
libantlr4-runtime-devel-4.8
antlr-devel-2.7.7
uuid-devel-1.6.2

Full log: https://build.opensuse.org/package/live_build_log/home:andythe_great/python-quantum-blackbird/openSUSE_Tumbleweed/x86_64

[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp:558:5: error: control reaches end of non-void function [-Werror=return-type]
[   42s]   558 |     }
[   42s]       |     ^
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp: In member function 'O* blackbird::Visitor::_create_operation(blackbirdParser::ArgumentsContext*, intvec) [with O = blackbird::Squeezed]':
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp:558:5: error: control reaches end of non-void function [-Werror=return-type]
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp: In member function 'O* blackbird::Visitor::_create_operation(blackbirdParser::ArgumentsContext*, intvec) [with O = blackbird::Thermal]':
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp:558:5: error: control reaches end of non-void function [-Werror=return-type]
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp: In member function 'O* blackbird::Visitor::_create_operation(blackbirdParser::ArgumentsContext*, intvec) [with O = blackbird::Fock]':
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp:558:5: error: control reaches end of non-void function [-Werror=return-type]
[   42s] /home/abuild/rpmbuild/BUILD/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp: In member function 'O* blackbird::Visitor::_create_operation(blackbirdParser::ArgumentsContext*, intvec) [with O = blackbird::Rgate]':

Thanks

Add requirements-test.txt file

Add a requirements-test.txt file, so that users that want to run the test suite can easily install all required dependencies.

In addition, the documentation regarding how to run the tests should be made clearer.

blackbird_python: Parse errors raise inappropriate SystemExit

Calls to blackbird.load or blackbird.loads that pass in a malformed Blackbird script raise a SystemExit error. This is a problem because SystemExit is a special error class that causes the Python program to quit, which can have unintended consequences. For example, running blackbird.loads('invalid script') in a python REPL causes the REPL to quit, whereas other exception classes print the traceback and allow the user to continue. This could have other unintentional effects when used with other software.

The ideal solution would be to define a base BlackbirdException class that all blackbird errors inherit from, and then define a BlackbirdParseError that derives from BlackbirdException.

Tests fails on numpy >= 1.24

With numpy 1.24 some tests are failing when mixing scalar with arrays:

FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_plus_scalar_array[n10] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_plus_scalar_array[n11] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_plus_scalar_array[n12] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_plus_scalar_array[n13] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_plus_scalar_array[n14] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_minus_scalar_array[n10] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_minus_scalar_array[n11] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_minus_scalar_array[n12] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_minus_scalar_array[n13] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_minus_scalar_array[n14] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_multiply_scalar_array[n10] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_multiply_scalar_array[n11] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_multiply_scalar_array[n12] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_multiply_scalar_array[n13] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_multiply_scalar_array[n14] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n10] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n11] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n12] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n13] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n14] - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
FAILED blackbird_python/blackbird/tests/test_listener.py::TestParsingVariables::test_array_variable_expression - ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

Please provide quantum-blackbird 0.2.4 with test suite

Hello,

I am packaging quantum-blackbird 0.2.4 on openSUSE, but I noticed the version 0.2.4 on pypi does not have test suite.
The github release does have test suite, would you mind release 0.2.4 with test?

Thank you very much.

Handling of arrays in templates

I have two questions / feature request regarding template matching and arrays.

Below there is a code example that uses a blackbird template to extract the gate parameters a user might request in a blackbird program.

Q1: There is a line in the example blow that seems to define a 2-D array:

float array squeezing_amplitudes[1, 4] =
    {squeezing_amplitudes}

I couldn't get it working with a 1-D array, and did not find anything related in the docs. Is there a way to define a 1-D array instead?

float array squeezing_amplitudes[4] =
    {squeezing_amplitudes}

Q2: Q2: While my template defines an array parameter (e.g. squeezing_ampltidues), the template matching returns the individual elements (squeezing_ampltidutes_0_0, ..._0_1, and so on). Is there a trick to get an array or list back from the template matching?

Code example

import blackbird
from blackbird.utils import match_template

prog = blackbird.loads("""
name prog
version 1.0
target X8 (shots=1)
S2gate(0, 0.0) | [0, 4]
S2gate(0, 0.0) | [1, 5]
S2gate(0, 0.0) | [2, 6]
S2gate(0, 0.0) | [3, 7]
MZgate(1.1, 1.1) | [0, 1]
MZgate(1.1, 1.1) | [2, 3]
MZgate(1.1, 1.1) | [1, 2]
MZgate(1.1, 1.1) | [0, 1]
MZgate(1.1, 1.1) | [2, 3]
MZgate(1.1, 1.1) | [1, 2]
MZgate(1.1, 1.1) | [4, 5]
MZgate(1.1, 1.1) | [6, 7]
MZgate(1.1, 1.1) | [5, 6]
MZgate(1.1, 1.1) | [4, 5]
MZgate(1.1, 1.1) | [6, 7]
MZgate(1.1, 1.1) | [5, 6]
Rgate(0.2) | 0
Rgate(0.2) | 1
Rgate(0.2) | 2
Rgate(0.2) | 3
Rgate(0.2) | 4
Rgate(0.2) | 5
Rgate(0.2) | 6
Rgate(0.2) | 7
MeasureFock() | [0, 1, 2, 3, 4, 5, 6, 7]
""")

template = blackbird.loads(
"""
name template
version 1.0
target X8 (shots=1)
float array squeezing_amplitudes[1, 4] =
    {squeezing_amplitudes}
float array phases[1, 12] =
    {phases}
float array final_phases[1, 8] =
    {final_phases}
# for n spatial degrees, first n signal modes, then n idler modes, all phases zero
S2gate(squeezing_amplitudes[0], 0.0) | [0, 4]
S2gate(squeezing_amplitudes[1], 0.0) | [1, 5]
S2gate(squeezing_amplitudes[2], 0.0) | [2, 6]
S2gate(squeezing_amplitudes[3], 0.0) | [3, 7]
# standard 4x4 interferometer for the signal modes (the lower ones in frequency)
# even phase indices correspond to internal Mach-Zehnder interferometer phases
# odd phase indices correspond to external Mach-Zehnder interferometer phases
MZgate(phases[0], phases[1]) | [0, 1]
MZgate(phases[2], phases[3]) | [2, 3]
MZgate(phases[4], phases[5]) | [1, 2]
MZgate(phases[6], phases[7]) | [0, 1]
MZgate(phases[8], phases[9]) | [2, 3]
MZgate(phases[10], phases[11]) | [1, 2]
# duplicate the interferometer for the idler modes (the higher ones in frequency)
MZgate(phases[0], phases[1]) | [4, 5]
MZgate(phases[2], phases[3]) | [6, 7]
MZgate(phases[4], phases[5]) | [5, 6]
MZgate(phases[6], phases[7]) | [4, 5]
MZgate(phases[8], phases[9]) | [6, 7]
MZgate(phases[10], phases[11]) | [5, 6]
# add final dummy phases to allow mapping any unitary to this template (these do not
# affect the photon number measurement)
Rgate(final_phases[0]) | [0]
Rgate(final_phases[1]) | [1]
Rgate(final_phases[2]) | [2]
Rgate(final_phases[3]) | [3]
Rgate(final_phases[4]) | [4]
Rgate(final_phases[5]) | [5]
Rgate(final_phases[6]) | [6]
Rgate(final_phases[7]) | [7]
# measurement in Fock basis
MeasureFock() | [0, 1, 2, 3, 4, 5, 6, 7]
""")

match_template(template, prog)

Output produced by the example

{'squeezing_amplitudes_0_0': 0,
 'phases_0_0': 1.1,
 'phases_0_1': 1.1,
 'phases_0_6': 1.1,
 'phases_0_7': 1.1,
 'final_phases_0_0': 0.2,
 'final_phases_0_4': 0.2,
 'phases_0_4': 1.1,
 ...

Deprecate strawberry_fields_listener.py

The current version of the listener app does not work on my system:

$ python apps/strawberry_fields_listener.py examples/example_gbs.xbb 
Traceback (most recent call last):
  File "apps/strawberry_fields_listener.py", line 103, in <module>
    run(sys.argv[1])
  File "apps/strawberry_fields_listener.py", line 98, in run
    simulation.run()
AttributeError: 'BlackbirdProgram' object has no attribute 'run'

The listener should be updated to the new commands in version 0.1.0

2 test failures on aarch64

I have 2 test failures on aarch64, due to precision issues:

[   58s] =================================== FAILURES ===================================
[   58s] ____________________ TestExpression.test_brackets[n23-n12] _____________________
[   58s] 
[   58s] self = <test_auxiliary.TestExpression object at 0xffff9def0520>
[   58s] parser = <blackbird.blackbirdParser.blackbirdParser object at 0xffff9de86af0>
[   58s] num = <function num.<locals>._number_label at 0xffff9de86550>
[   58s] n1 = ('0.54+0.21j', (0.54+0.21j)), n2 = ('13.', 13)
[   58s] ctx = <antlr4.ParserRuleContext.ParserRuleContext object at 0xffff9dee4ca0>
[   58s] 
[   58s]     @pytest.mark.parametrize('n1', test_complex)
[   58s]     @pytest.mark.parametrize('n2', test_floats)
[   58s]     def test_brackets(self, parser, num, n1, n2, ctx):
[   58s]         """Test that brackets are correctly parsed"""
[   58s]     
[   58s]         class DummyAddLabel(blackbirdParser.AddLabelContext):
[   58s]             """Dummy add label"""
[   58s]             expression = lambda self: (num(n1[0]), num(n2[0]))
[   58s]     
[   58s]         class DummyBracketsLabel(blackbirdParser.BracketsLabelContext):
[   58s]             """Dummy brackets"""
[   58s]             def expression(self):
[   58s]                 """Returns a Blackbird abstract syntax tree section corresponding to an expression"""
[   58s]                 e = DummyAddLabel(parser, ctx)
[   58s]                 e.PLUS = lambda: True
[   58s]                 return e
[   58s]     
[   58s]         class DummyPowerLabel(blackbirdParser.PowerLabelContext):
[   58s]             """Dummy power"""
[   58s]             expression = lambda self: (DummyBracketsLabel(parser, ctx), num(2))
[   58s]     
[   58s]         expr = DummyPowerLabel(parser, ctx)
[   58s] >       assert _expression(expr) == (n1[1]+n2[1])**2
[   58s] E       assert (183.28749999999997+5.6868j) == (183.2875+5.6868j)
[   58s] E         +(183.28749999999997+5.6868j)
[   58s] E         -(183.2875+5.6868j)
[   58s] 
[   58s] blackbird_python/blackbird/tests/test_auxiliary.py:369: AssertionError
[   58s] ---------------------------- Captured stdout setup -----------------------------
[   58s] ANTLR runtime and generated code versions disagree: 4.9.1!=4.8
[   58s] ____________________ TestExpression.test_brackets[n24-n12] _____________________
[   58s] 
[   58s] self = <test_auxiliary.TestExpression object at 0xffff9de68070>
[   58s] parser = <blackbird.blackbirdParser.blackbirdParser object at 0xffff9ded4a60>
[   58s] num = <function num.<locals>._number_label at 0xffff9ded4ee0>
[   58s] n1 = ('0.54+0.21j', (0.54+0.21j)), n2 = ('-1', -1)
[   58s] ctx = <antlr4.ParserRuleContext.ParserRuleContext object at 0xffff9dea58e0>
[   58s] 
[   58s]     @pytest.mark.parametrize('n1', test_complex)
[   58s]     @pytest.mark.parametrize('n2', test_floats)
[   58s]     def test_brackets(self, parser, num, n1, n2, ctx):
[   58s]         """Test that brackets are correctly parsed"""
[   58s]     
[   58s]         class DummyAddLabel(blackbirdParser.AddLabelContext):
[   58s]             """Dummy add label"""
[   58s]             expression = lambda self: (num(n1[0]), num(n2[0]))
[   58s]     
[   58s]         class DummyBracketsLabel(blackbirdParser.BracketsLabelContext):
[   58s]             """Dummy brackets"""
[   58s]             def expression(self):
[   58s]                 """Returns a Blackbird abstract syntax tree section corresponding to an expression"""
[   58s]                 e = DummyAddLabel(parser, ctx)
[   58s]                 e.PLUS = lambda: True
[   58s]                 return e
[   58s]     
[   58s]         class DummyPowerLabel(blackbirdParser.PowerLabelContext):
[   58s]             """Dummy power"""
[   58s]             expression = lambda self: (DummyBracketsLabel(parser, ctx), num(2))
[   58s]     
[   58s]         expr = DummyPowerLabel(parser, ctx)
[   58s] >       assert _expression(expr) == (n1[1]+n2[1])**2
[   58s] E       assert (0.1674999999...999999999998j) == (0.1674999999...999999999998j)
[   58s] E         +(0.16749999999999998-0.19319999999999998j)
[   58s] E         -(0.16749999999999995-0.19319999999999998j)
[   58s] 
[   58s] blackbird_python/blackbird/tests/test_auxiliary.py:369: AssertionError

TestExpressionArray::test_divide_scalar_array fails on i586

When running the packaging scripts for openSUSE package of python-quantum-blackbird I get this failure in the test suite:

[   26s] + PYTHONPATH=/home/abuild/rpmbuild/BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages
[   26s] + PYTHONDONTWRITEBYTECODE=1
[   26s] + pytest-3.9 --ignore=_build. --ignore=_build.python39 --ignore=_build.python38 -v
[   27s] ============================= test session starts ==============================
[   27s] platform linux -- Python 3.9.4, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3.9
[   27s] cachedir: .pytest_cache
[   27s] rootdir: /home/abuild/rpmbuild/BUILD/blackbird-0.3.0
[   28s] collecting ... collected 490 items
[   28s]
[ ... plenty of passing tests removed from the report ...]
[   30s]
[   30s] =================================== FAILURES ===================================
[   30s] ______________ TestExpressionArray.test_divide_scalar_array[n10] _______________
[   30s]
[   30s] self = <test_auxiliary.TestExpressionArray object at 0xf42bd5f8>
[   30s] parser = <blackbird.blackbirdParser.blackbirdParser object at 0xf42976a0>
[   30s] ctx = <antlr4.ParserRuleContext.ParserRuleContext object at 0xf429f358>
[   30s] n1 = ('0+5j', 5j), num = <function num.<locals>._number_label at 0xf4297a48>
[   30s] var = <function var.<locals>._var_label at 0xf4297538>
[   30s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xf42e3838>
[   30s]
[   30s]     @pytest.mark.parametrize('n1', test_complex)
[   30s]     def test_divide_scalar_array(self, parser, ctx, n1, num, var, monkeypatch):
[   30s]         """Test division of a number and an array"""
[   30s]
[   30s]         class DummyMulLabel(blackbirdParser.MulLabelContext):
[   30s]             """Dummy mul label"""
[   30s]             expression = lambda self: (num(n1[0]), var("U"))
[   30s]
[   30s]         with monkeypatch.context() as m:
[   30s]             m.setattr(blackbird.auxiliary, "_VAR", {"U": U})
[   30s]
[   30s]             expr = DummyMulLabel(parser, ctx)
[   30s]             expr.DIVIDE = lambda: True
[   30s] >           assert np.all(_expression(expr) == n1[1]/U)
[   30s] E           AssertionError: assert False
[   30s] E            +  where False = <function all at 0xf6a7b658>(array([[0.  +...0.j        ]]) == array([[ 0.  ...0.j        ]])
[   30s] E            +    where <function all at 0xf6a7b658> = np.all
[   30s] E               +array([[0.  +1.66666667j, 0.  +2.5j       ],\n
[   30s] E               +       [2.5 +2.5j       , 0. -10.j        ]])
[   30s] E               -array([[ 0.  +1.66666667j,  0.  +2.5j       ],\n
[   30s] E               -       [ 2.5 +2.5j       , -0. -10.j        ]])
[   30s] E               Full diff:
[   30s] E               - array([[ 0.  +1.66666667j,  0.  +2.5j       ],
[   30s] E               ?         -                  -...
[   30s] E
[   30s] E               ...Full output truncated (6 lines hidden), use '-vv' to show)
[   30s]
[   30s] blackbird_python/blackbird/tests/test_auxiliary.py:612: AssertionError
[   30s] ---------------------------- Captured stdout setup -----------------------------
[   30s] ANTLR runtime and generated code versions disagree: 4.9.1!=4.8
[   30s] ______________ TestExpressionArray.test_divide_scalar_array[n12] _______________
[   30s]
[   30s] self = <test_auxiliary.TestExpressionArray object at 0xf4325340>
[   30s] parser = <blackbird.blackbirdParser.blackbirdParser object at 0xf42ff7c0>
[   30s] ctx = <antlr4.ParserRuleContext.ParserRuleContext object at 0xf429fe98>
[   30s] n1 = ('0.54+0.21j', (0.54+0.21j))
[   30s] num = <function num.<locals>._number_label at 0xf42ff2b0>
[   30s] var = <function var.<locals>._var_label at 0xf42ffbb0>
[   30s] monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0xf42bda48>
[   30s]
[   30s]     @pytest.mark.parametrize('n1', test_complex)
[   30s]     def test_divide_scalar_array(self, parser, ctx, n1, num, var, monkeypatch):
[   30s]         """Test division of a number and an array"""
[   30s]
[   30s]         class DummyMulLabel(blackbirdParser.MulLabelContext):
[   30s]             """Dummy mul label"""
[   30s]             expression = lambda self: (num(n1[0]), var("U"))
[   30s]
[   30s]         with monkeypatch.context() as m:
[   30s]             m.setattr(blackbird.auxiliary, "_VAR", {"U": U})
[   30s]
[   30s]             expr = DummyMulLabel(parser, ctx)
[   30s]             expr.DIVIDE = lambda: True
[   30s] >           assert np.all(_expression(expr) == n1[1]/U)
[   30s] E           AssertionError: assert False
[   30s] E            +  where False = <function all at 0xf6a7b658>(array([[ 0.18....08 -0.42j ]]) == array([[ 0.18....08 -0.42j ]])
[   30s] E            +    where <function all at 0xf6a7b658> = np.all
[   30s] E               +array([[ 0.18 +0.07j ,  0.27 +0.105j],\n
[   30s] E               +       [ 0.375-0.165j, -1.08 -0.42j ]])
[   30s] E               -array([[ 0.18 +0.07j ,  0.27 +0.105j],\n
[   30s] E               -       [ 0.375-0.165j, -1.08 -0.42j ]])
[   30s] E               Full diff:
[   30s] E                 array([[ 0.18 +0.07j ,  0.27 +0.105j],
[   30s] E                        [ 0.375-0.165j, -1.08 -0.42j ]],...
[   30s] E
[   30s] E               ...Full output truncated (2 lines hidden), use '-vv' to show)
[   30s]
[   30s] blackbird_python/blackbird/tests/test_auxiliary.py:612: AssertionError
[   30s] ---------------------------- Captured stdout setup -----------------------------
[   30s] ANTLR runtime and generated code versions disagree: 4.9.1!=4.8
[   30s] =============================== warnings summary ===============================
[   30s] ../../BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages/blackbird/listener.py:78
[   30s]   /home/abuild/rpmbuild/BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages/blackbird/listener.py:78: DeprecationWarning: `np.str` is a deprecated alias for the builtin `str`. To silence this warning, use `str` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.str_` here.
[   30s]   Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
[   30s]     "str": np.str,
[   30s]
[   30s] ../../BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages/blackbird/listener.py:79
[   30s]   /home/abuild/rpmbuild/BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages/blackbird/listener.py:79: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
[   30s]   Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
[   30s]     "bool": np.bool,
[   30s]
[   30s] blackbird_python/blackbird/tests/test_auxiliary.py: 20 warnings
[   30s] blackbird_python/blackbird/tests/test_listener.py: 1 warning
[   30s]   /usr/lib/python3.9/site-packages/numpy/core/fromnumeric.py:87: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
[   30s]     return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
[   30s]
[   30s] blackbird_python/blackbird/tests/test_listener.py::TestParsingMetadata::test_type_kwarg
[   30s]   /home/abuild/rpmbuild/BUILDROOT/python-quantum-blackbird-0.3.0-0.i386/usr/lib/python3.9/site-packages/blackbird/listener.py:179: SyntaxWarning: Target devices only accept keyword options of the form option=value. All positional arguments without a named option will be ignored.
[   30s]     warnings.warn(
[   30s]
[   30s] -- Docs: https://docs.pytest.org/en/stable/warnings.html
[   30s] =========================== short test summary info ============================
[   30s] FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n10]
[   30s] FAILED blackbird_python/blackbird/tests/test_auxiliary.py::TestExpressionArray::test_divide_scalar_array[n12]
[   30s] ============ 2 failed, 483 passed, 5 skipped, 24 warnings in 2.95s =============

Complete log with all details.

[openSUSE] antlr4-common.h: No such file or directory, but I check and it exist

Hello,

I tried to compile quantum-blackbird on linux openSUSE Tumbleweed.
The problem is that it could not find antlr4-common.h.
However, I have installed libantlr4-runtime-devel package which provide antlr4-common.h
Which I check and found it in /usr/include/antlr4-runtime folder, so I don't know why make cannot see it.

Thank you

kev@linux:/usr/include/antlr4-runtime> ls -l
total 292
-rw-r--r-- 1 root root  3560 Jan 19  2020 antlr4-common.h
-rw-r--r-- 1 root root  5400 Jan 19  2020 antlr4-runtime.h
-rw-r--r-- 1 root root  8375 Jan 19  2020 ANTLRErrorListener.h
-rw-r--r-- 1 root root  5269 Jan 19  2020 ANTLRErrorStrategy.h
-rw-r--r-- 1 root root   874 Jan 19  2020 ANTLRFileStream.h
-rw-r--r-- 1 root root  2276 Jan 19  2020 ANTLRInputStream.h
drwxr-xr-x 1 root root  2392 Aug  4 23:59 atn
-rw-r--r-- 1 root root  2483 Jan 19  2020 BailErrorStrategy.h
-rw-r--r-- 1 root root  1377 Jan 19  2020 BaseErrorListener.h
-rw-r--r-- 1 root root  8014 Jan 19  2020 BufferedTokenStream.h
-rw-r--r-- 1 root root  1479 Jan 19  2020 CharStream.h
-rw-r--r-- 1 root root  2552 Jan 19  2020 CommonTokenFactory.h
-rw-r--r-- 1 root root  4918 Jan 19  2020 CommonToken.h
-rw-r--r-- 1 root root  2713 Jan 19  2020 CommonTokenStream.h
-rw-r--r-- 1 root root  1060 Jan 19  2020 ConsoleErrorListener.h
-rw-r--r-- 1 root root 20289 Jan 19  2020 DefaultErrorStrategy.h
drwxr-xr-x 1 root root   100 Aug  4 23:59 dfa
-rw-r--r-- 1 root root  3600 Jan 19  2020 DiagnosticErrorListener.h
-rw-r--r-- 1 root root  3868 Jan 19  2020 Exceptions.h
-rw-r--r-- 1 root root  1087 Jan 19  2020 FailedPredicateException.h
-rw-r--r-- 1 root root   783 Jan 19  2020 InputMismatchException.h
-rw-r--r-- 1 root root  1604 Jan 19  2020 InterpreterRuleContext.h
-rw-r--r-- 1 root root 10299 Jan 19  2020 IntStream.h
-rw-r--r-- 1 root root  6988 Jan 19  2020 Lexer.h
-rw-r--r-- 1 root root  1996 Jan 19  2020 LexerInterpreter.h
-rw-r--r-- 1 root root   916 Jan 19  2020 LexerNoViableAltException.h
-rw-r--r-- 1 root root  3797 Jan 19  2020 ListTokenSource.h
drwxr-xr-x 1 root root   138 Aug  4 23:59 misc
-rw-r--r-- 1 root root  1693 Jan 19  2020 NoViableAltException.h
-rw-r--r-- 1 root root 19704 Jan 19  2020 Parser.h
-rw-r--r-- 1 root root  7481 Jan 19  2020 ParserInterpreter.h
-rw-r--r-- 1 root root  5418 Jan 19  2020 ParserRuleContext.h
-rw-r--r-- 1 root root  1657 Jan 19  2020 ProxyErrorListener.h
-rw-r--r-- 1 root root  3961 Jan 19  2020 RecognitionException.h
-rw-r--r-- 1 root root  5969 Jan 19  2020 Recognizer.h
-rw-r--r-- 1 root root  5342 Jan 19  2020 RuleContext.h
-rw-r--r-- 1 root root   985 Jan 19  2020 RuleContextWithAltNum.h
-rw-r--r-- 1 root root  7393 Jan 19  2020 RuntimeMetaData.h
drwxr-xr-x 1 root root   128 Aug  4 23:59 support
-rw-r--r-- 1 root root  1217 Jan 19  2020 TokenFactory.h
-rw-r--r-- 1 root root  3419 Jan 19  2020 Token.h
-rw-r--r-- 1 root root  3843 Jan 19  2020 TokenSource.h
-rw-r--r-- 1 root root  6098 Jan 19  2020 TokenStream.h
-rw-r--r-- 1 root root 12471 Jan 19  2020 TokenStreamRewriter.h
drwxr-xr-x 1 root root   426 Aug  4 23:59 tree
-rw-r--r-- 1 root root  4557 Jan 19  2020 UnbufferedCharStream.h
-rw-r--r-- 1 root root  4241 Jan 19  2020 UnbufferedTokenStream.h
-rw-r--r-- 1 root root  7781 Jan 19  2020 Vocabulary.h
-rw-r--r-- 1 root root   676 Jan 19  2020 WritableToken.h
kev@linux:~/Desktop/quantum-blackbird-0.2.4/blackbird_cpp> cmake .
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kev/Desktop/quantum-blackbird-0.2.4/blackbird_cpp
kev@linux:~/Desktop/quantum-blackbird-0.2.4/blackbird_cpp> sudo make install
[sudo] password for root: 
Scanning dependencies of target blackbird
[ 20%] Building CXX object CMakeFiles/blackbird.dir/Visitor.cpp.o
In file included from /usr/include/antlr4-runtime/CharStream.h:9,
                 from /usr/include/antlr4-runtime/ANTLRInputStream.h:8,
                 from /usr/include/antlr4-runtime/ANTLRFileStream.h:8,
                 from /usr/include/antlr4-runtime/antlr4-runtime.h:14,
                 from /home/kev-test/Desktop/quantum-blackbird-0.2.4/blackbird_cpp/Blackbird.h:23,
                 from /home/kev-test/Desktop/quantum-blackbird-0.2.4/blackbird_cpp/Visitor.cpp:16:
/usr/include/antlr4-runtime/misc/Interval.h:8:10: fatal error: antlr4-common.h: No such file or directory
    8 | #include "antlr4-common.h"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/blackbird.dir/build.make:82: CMakeFiles/blackbird.dir/Visitor.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/blackbird.dir/all] Error 2
make: *** [Makefile:149: all] Error 2
kev@linux:~/Desktop/quantum-blackbird-0.2.4/blackbird_cpp> 

Opposite function of match_template

This is a long-term feature request.

It would be nice to have a function that does the opposite of match_template, that is, provided a dictionary of parameters and a template, create a program with template variables replaced by the parameters from the dict.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.