From 89c03b81c1f0911b770a8150b1d242e29e0b0825 Mon Sep 17 00:00:00 2001 From: Anthony <125415978+apchytr@users.noreply.github.com> Date: Mon, 20 Jan 2025 12:04:10 -0500 Subject: [PATCH] Windows fixes (#538) **Context:** Attempting to install MrMustard on a Windows system revealed some bugs **Description of the Change:** Including a dependency for tf-intel. Fixing an issue with hermite_renormalized where `shape` could be of type `Tuple(Int32, Int64, Int64, Int64,...)` causing numba issues --------- Co-authored-by: Matthew Silverman --- mrmustard/math/backend_numpy.py | 2 +- mrmustard/math/tensor_networks/networks.py | 2 +- poetry.lock | 84 ++++++++++++++++++++-- pyproject.toml | 5 ++ tests/test_lab_dev/test_states/test_dm.py | 10 +-- tests/test_lab_dev/test_states/test_ket.py | 2 +- 6 files changed, 93 insertions(+), 12 deletions(-) diff --git a/mrmustard/math/backend_numpy.py b/mrmustard/math/backend_numpy.py index 434a682a8..d04eaeaba 100644 --- a/mrmustard/math/backend_numpy.py +++ b/mrmustard/math/backend_numpy.py @@ -519,7 +519,7 @@ def hermite_renormalized( """ precision_bits = settings.PRECISION_BITS_HERMITE_POLY - + shape = tuple(int(i) for i in shape) # ensure each item in the tuple is of the same dtype if precision_bits == 128: # numba if settings.STABLE_FOCK_CONVERSION: G = vanilla_stable(tuple(shape), A, b, c) diff --git a/mrmustard/math/tensor_networks/networks.py b/mrmustard/math/tensor_networks/networks.py index b14cf26e7..7850b5626 100644 --- a/mrmustard/math/tensor_networks/networks.py +++ b/mrmustard/math/tensor_networks/networks.py @@ -174,7 +174,7 @@ def draw( labels=mode_labels, font_size=12, font_color="black", - font_family="FreeMono", + font_family="Monospace", ) plt.title("Mr Mustard Network") diff --git a/poetry.lock b/poetry.lock index f0a4d9627..78c50ca3f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1572,6 +1572,7 @@ description = "Clang Python Bindings, mirrored from the official LLVM repo: http optional = false python-versions = "*" files = [ + {file = "libclang-18.1.1-1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:0b2e143f0fac830156feb56f9231ff8338c20aecfe72b4ffe96f19e5a1dbb69a"}, {file = "libclang-18.1.1-py2.py3-none-macosx_10_9_x86_64.whl", hash = "sha256:6f14c3f194704e5d09769108f03185fce7acaf1d1ae4bbb2f30a72c2400cb7c5"}, {file = "libclang-18.1.1-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:83ce5045d101b669ac38e6da8e58765f12da2d3aafb3b9b98d88b286a60964d8"}, {file = "libclang-18.1.1-py2.py3-none-manylinux2010_x86_64.whl", hash = "sha256:c533091d8a3bbf7460a00cb6c1a71da93bffe148f172c7d03b1c31fbf8aa2a0b"}, @@ -1892,8 +1893,8 @@ files = [ numpy = [ {version = ">=1.21.2", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, {version = ">1.20", markers = "python_version < \"3.10\""}, - {version = ">=1.26.0", markers = "python_version >= \"3.12\""}, {version = ">=1.23.3", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, + {version = ">=1.26.0", markers = "python_version >= \"3.12\""}, ] [package.extras] @@ -2325,8 +2326,8 @@ files = [ [package.dependencies] numpy = [ {version = ">=1.22.4", markers = "python_version < \"3.11\""}, - {version = ">=1.26.0", markers = "python_version >= \"3.12\""}, {version = ">=1.23.2", markers = "python_version == \"3.11\""}, + {version = ">=1.26.0", markers = "python_version >= \"3.12\""}, ] python-dateutil = ">=2.8.2" pytz = ">=2020.1" @@ -2816,8 +2817,8 @@ astroid = ">=3.3.4,<=3.4.0-dev0" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} dill = [ {version = ">=0.2", markers = "python_version < \"3.11\""}, - {version = ">=0.3.7", markers = "python_version >= \"3.12\""}, {version = ">=0.3.6", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, + {version = ">=0.3.7", markers = "python_version >= \"3.12\""}, ] isort = ">=4.2.5,<5.13.0 || >5.13.0,<6" mccabe = ">=0.6,<0.8" @@ -3791,6 +3792,81 @@ wrapt = ">=1.11.0" [package.extras] and-cuda = ["nvidia-cublas-cu12 (==12.5.3.2)", "nvidia-cuda-cupti-cu12 (==12.5.82)", "nvidia-cuda-nvcc-cu12 (==12.5.82)", "nvidia-cuda-nvrtc-cu12 (==12.5.82)", "nvidia-cuda-runtime-cu12 (==12.5.82)", "nvidia-cudnn-cu12 (==9.3.0.75)", "nvidia-cufft-cu12 (==11.2.3.61)", "nvidia-curand-cu12 (==10.3.6.82)", "nvidia-cusolver-cu12 (==11.6.3.83)", "nvidia-cusparse-cu12 (==12.5.1.3)", "nvidia-nccl-cu12 (==2.21.5)", "nvidia-nvjitlink-cu12 (==12.5.82)"] +[[package]] +name = "tensorflow-intel" +version = "2.18.0" +description = "TensorFlow is an open source machine learning framework for everyone." +optional = false +python-versions = ">=3.9" +files = [ + {file = "tensorflow_intel-2.18.0-cp310-cp310-win_amd64.whl", hash = "sha256:34701c988f3e20415a8e450a1384339e9f013950db70fa0361b79cddd1e8431b"}, + {file = "tensorflow_intel-2.18.0-cp311-cp311-win_amd64.whl", hash = "sha256:af380d326e146f2d184a940ccf8350e9b6dc06a0530bfaa3a557b73819c4017b"}, + {file = "tensorflow_intel-2.18.0-cp312-cp312-win_amd64.whl", hash = "sha256:a5818043f565cf74179b67eb52fc060587ccecb9540141c39d84fbcb37ecff8c"}, + {file = "tensorflow_intel-2.18.0-cp39-cp39-win_amd64.whl", hash = "sha256:87d39ffc68539c5ed464543ce18a72fdc37098356d60484eb1cde9409cc22267"}, +] + +[package.dependencies] +absl-py = ">=1.0.0" +astunparse = ">=1.6.0" +flatbuffers = ">=24.3.25" +gast = ">=0.2.1,<0.5.0 || >0.5.0,<0.5.1 || >0.5.1,<0.5.2 || >0.5.2" +google-pasta = ">=0.1.1" +grpcio = ">=1.24.3,<2.0" +h5py = ">=3.11.0" +keras = ">=3.5.0" +libclang = ">=13.0.0" +ml-dtypes = ">=0.4.0,<0.5.0" +numpy = ">=1.26.0,<2.1.0" +opt-einsum = ">=2.3.2" +packaging = "*" +protobuf = ">=3.20.3,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<6.0.0dev" +requests = ">=2.21.0,<3" +setuptools = "*" +six = ">=1.12.0" +tensorboard = ">=2.18,<2.19" +tensorflow-io-gcs-filesystem = {version = ">=0.23.1", markers = "python_version < \"3.12\""} +termcolor = ">=1.1.0" +typing-extensions = ">=3.6.6" +wrapt = ">=1.11.0" + +[package.extras] +and-cuda = ["nvidia-cublas-cu12 (==12.5.3.2)", "nvidia-cuda-cupti-cu12 (==12.5.82)", "nvidia-cuda-nvcc-cu12 (==12.5.82)", "nvidia-cuda-nvrtc-cu12 (==12.5.82)", "nvidia-cuda-runtime-cu12 (==12.5.82)", "nvidia-cudnn-cu12 (==9.3.0.75)", "nvidia-cufft-cu12 (==11.2.3.61)", "nvidia-curand-cu12 (==10.3.6.82)", "nvidia-cusolver-cu12 (==11.6.3.83)", "nvidia-cusparse-cu12 (==12.5.1.3)", "nvidia-nccl-cu12 (==2.21.5)", "nvidia-nvjitlink-cu12 (==12.5.82)"] + +[[package]] +name = "tensorflow-io-gcs-filesystem" +version = "0.31.0" +description = "TensorFlow IO" +optional = false +python-versions = ">=3.7, <3.12" +files = [ + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:a71421f8d75a093b6aac65b4c8c8d2f768c3ca6215307cf8c16192e62d992bcf"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:359134ecbd3bf938bb0cf65be4526106c30da461b2e2ce05446a229ed35f6832"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b658b33567552f155af2ed848130f787bfda29381fa78cd905d5ee8254364f3c"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp310-cp310-win_amd64.whl", hash = "sha256:961353b38c76471fa296bb7d883322c66b91415e7d47087236a6706db3ab2758"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp311-cp311-macosx_10_14_x86_64.whl", hash = "sha256:8909c4344b0e96aa356230ab460ffafe5900c33c1aaced65fafae71d177a1966"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp311-cp311-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:e417faf8755aafe52d8f8c6b5ae5bae6e4fae8326ee3acd5e9181b83bbfbae87"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:37c40e3c4ee1f8dda3b545deea6b8839192c82037d8021db9f589908034ad975"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp311-cp311-win_amd64.whl", hash = "sha256:4bb37d23f21c434687b11059cb7ffd094d52a7813368915ba1b7057e3c16e414"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:a7e8d4bd0a25de7637e562997c011294d7ea595a76f315427a5dd522d56e9d49"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:fbcfb4aa2eaa9a3038d2487e570ff93feb1dbe51c3a4663d7d9ab9f9a9f9a9d8"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp37-cp37m-win_amd64.whl", hash = "sha256:e3933059b1c53e062075de2e355ec136b655da5883c3c26736c45dfeb1901945"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:f0adfbcd264262797d429311843733da2d5c1ffb119fbfa6339269b6c0414113"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:20e3ee5df01f2bd81d37fc715816c329b7533ccca967c47946eb458a5b7a7280"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bd628609b77aee0e385eadf1628222486f19b8f1d81b5f0a344f2470204df116"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp38-cp38-win_amd64.whl", hash = "sha256:b4ebb30ad7ce5f3769e3d959ea99bd95d80a44099bcf94da6042f9755ac6e850"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:68b89ef9f63f297de1cd9d545bc45dddc7d8fe12bcda4266279b244e8cf3b7c0"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:e6d8cc7b14ade870168b9704ee44f9c55b468b9a00ed40e12d20fffd321193b5"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:97ebb9a8001a38f615aa1f90d2e998b7bd6eddae7aafc92897833610b039401b"}, + {file = "tensorflow_io_gcs_filesystem-0.31.0-cp39-cp39-win_amd64.whl", hash = "sha256:cb7459c15608fe42973a78e4d3ad7ac79cfc7adae1ccb1b1846db3165fbc081a"}, +] + +[package.extras] +tensorflow = ["tensorflow (>=2.11.0,<2.12.0)"] +tensorflow-aarch64 = ["tensorflow-aarch64 (>=2.11.0,<2.12.0)"] +tensorflow-cpu = ["tensorflow-cpu (>=2.11.0,<2.12.0)"] +tensorflow-gpu = ["tensorflow-gpu (>=2.11.0,<2.12.0)"] +tensorflow-rocm = ["tensorflow-rocm (>=2.11.0,<2.12.0)"] + [[package]] name = "tensorflow-io-gcs-filesystem" version = "0.37.1" @@ -4211,4 +4287,4 @@ ray = ["ray", "scikit-optimize"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "b16d77f26dfd571664e4577ae0a0cfe7bd50c69f1185c790afe77c2296c227b5" +content-hash = "1e119b47477c660785711a20bda14c7e5934074e8f5db62ee4082b0a1f63187f" diff --git a/pyproject.toml b/pyproject.toml index a7d57b17d..4bf9d768c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,11 @@ ipywidgets = "^8.1.3" ###################### The Tensorflow Section ###################### tensorflow = {version = "^2.15.0, <2.19.0" } tensorflow-probability = {version = ">=0.22.0,<1.0", extras = ["tf"]} +tensorflow-intel = { version = "^2.15.0", platform = "win32" } +tensorflow-io-gcs-filesystem = [ + { version = ">= 0.23.1", markers = "platform_machine!='arm64' or platform_system!='Darwin'", python = ">=3.9,<3.12" }, + { version = "< 0.32.0", markers = "platform_system == 'Windows'", python = ">=3.9,<3.12" } +] semantic-version = "^2.10.0" [tool.poetry.extras] diff --git a/tests/test_lab_dev/test_states/test_dm.py b/tests/test_lab_dev/test_states/test_dm.py index 340deef5a..53230ee40 100644 --- a/tests/test_lab_dev/test_states/test_dm.py +++ b/tests/test_lab_dev/test_states/test_dm.py @@ -134,7 +134,7 @@ def test_to_from_fock(self, modes): def test_to_from_phase_space(self): state0 = Coherent([0], x=1, y=2) >> Attenuator([0], 1.0) cov, means, coeff = state0.phase_space(s=0) # batch = 1 - assert coeff == 1.0 + assert math.allclose(coeff, math.atleast_1d(1.0)) assert math.allclose(cov[0], np.eye(2) * settings.HBAR / 2) assert math.allclose(means[0], np.array([1.0, 2.0]) * np.sqrt(settings.HBAR * 2)) @@ -167,15 +167,15 @@ def test_L2_norms(self): def test_L2_norm(self): state = Coherent([0], x=1).dm() - assert state.L2_norm == 1 + assert math.allclose(state.L2_norm, 1) def test_probability(self): state1 = Coherent([0], x=1).dm() - assert state1.probability == 1 - assert state1.to_fock(20).probability == 1 + assert math.allclose(state1.probability, 1) + assert math.allclose(state1.to_fock(20).probability, 1) state2 = Coherent([0], x=1).dm() / 3 + 2 * Coherent([0], x=-1).dm() / 3 - assert state2.probability == 1 + assert math.allclose(state2.probability, 1) assert math.allclose(state2.to_fock(20).probability, 1) state3 = Number([0], n=1, cutoffs=2).dm() / 2 + Number([0], n=2).dm() / 2 diff --git a/tests/test_lab_dev/test_states/test_ket.py b/tests/test_lab_dev/test_states/test_ket.py index 36d0f6967..f848ef63a 100644 --- a/tests/test_lab_dev/test_states/test_ket.py +++ b/tests/test_lab_dev/test_states/test_ket.py @@ -168,7 +168,7 @@ def test_to_from_quadrature(self): def test_L2_norm(self): state = Coherent([0], x=1) - assert state.L2_norm == 1 + assert math.allclose(state.L2_norm, 1) def test_probability(self): state1 = Coherent([0], x=1) / 3