├── .codecov.yml ├── .coveragerc ├── .github ├── CHALLENGES.md ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.yaml │ └── feature_request.yaml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── docs.yml │ ├── format.yml │ ├── tests.yaml │ └── upload.yml ├── .gitignore ├── .pylintrc ├── .readthedocs.yml ├── DOCS.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── TESTS.rst ├── doc ├── Makefile ├── _ext │ └── edit_on_github.py ├── _images │ ├── shirt.jpg │ ├── sticker.jpg │ ├── sticker2.jpg │ └── sticker_crop.jpg ├── _static │ ├── BSgate.svg │ ├── Dgate.svg │ ├── GBS.png │ ├── GBS.svg │ ├── GateSynthesis.gif │ ├── IQP.svg │ ├── NOON.png │ ├── Rgate.svg │ ├── Sgate.svg │ ├── StateLearning.gif │ ├── Strawberry-fields_white.png │ ├── TF.png │ ├── Vgate.svg │ ├── X8.png │ ├── X8.svg │ ├── borealis_3d.png │ ├── borealis_schematic_advanced.png │ ├── borealis_schematic_simple.png │ ├── boson_sampling.svg │ ├── boson_sampling_ex.png │ ├── boson_sampling_ex.svg │ ├── bs_measure.png │ ├── bs_measure.svg │ ├── cats.png │ ├── chip.png │ ├── chip.svg │ ├── circulant.png │ ├── clements.png │ ├── cloning.png │ ├── cloning.svg │ ├── code.png │ ├── complete_graph.png │ ├── complete_subgraph.png │ ├── dense.png │ ├── favicon.ico │ ├── fock_teleport.png │ ├── fock_teleport.svg │ ├── formic.png │ ├── formic_spec.png │ ├── formic_spectrum.png │ ├── gate_teleport1.svg │ ├── gate_teleport2.svg │ ├── gate_teleport3.svg │ ├── gate_teleport_ex.svg │ ├── gaussian_boson_sampling.png │ ├── gaussian_boson_sampling.svg │ ├── gaussian_cloning_plot.svg │ ├── graph.svg │ ├── graphs │ │ ├── MUTAG_0.png │ │ ├── MUTAG_1.png │ │ ├── MUTAG_2.png │ │ ├── MUTAG_3.png │ │ ├── TACE-AS.png │ │ └── planted.png │ ├── hamsim.svg │ ├── images │ │ ├── sphx_glr_run_gate_synthesis_001.png │ │ ├── sphx_glr_run_gate_synthesis_002.png │ │ ├── sphx_glr_run_minimizing_correlations_001.png │ │ ├── sphx_glr_run_minimizing_correlations_002.png │ │ ├── sphx_glr_run_state_learner_001.png │ │ ├── sphx_glr_run_state_learner_002.png │ │ └── sphx_glr_run_state_learner_003.png │ ├── interactive.png │ ├── laptop.png │ ├── layer.svg │ ├── layer_1mode.svg │ ├── layer_2mode.svg │ ├── layer_3mode.svg │ ├── layer_4mode.svg │ ├── max_clique.png │ ├── minimizing_correlations.gif │ ├── neural_network.svg │ ├── normal_pp.png │ ├── oneloop.svg │ ├── points.png │ ├── pyrrole.png │ ├── qcircuit │ │ ├── BSgate.tex │ │ ├── Dgate.tex │ │ ├── Qcircuit.tex │ │ ├── Rgate.tex │ │ ├── Sgate.tex │ │ ├── boson_sampling_ex.tex │ │ ├── bosonsampling.tex │ │ ├── cloning.tex │ │ ├── gate_teleport1.tex │ │ ├── gate_teleport2.tex │ │ ├── gate_teleport3.tex │ │ ├── gate_teleport_ex.tex │ │ ├── gaussian_boson_sampling.tex │ │ ├── hamiltonian.tex │ │ ├── iqp_circuit.tex │ │ ├── main.tex │ │ ├── measurements.tex │ │ └── teleportation.tex │ ├── readme_panel1.png │ ├── reck.png │ ├── s_measure.svg │ ├── sf_wordmark.png │ ├── sfcomponents.svg │ ├── similarity_svm.png │ ├── strawberry-fields-text.png │ ├── strawberry_fields.png │ ├── teleport.png │ ├── teleport.svg │ ├── thumbs │ │ ├── code.png │ │ ├── photon.png │ │ └── spectrum.png │ ├── water.png │ └── x_p.png ├── _templates │ ├── autosummary │ │ ├── base.rst │ │ ├── class.rst │ │ └── module.rst │ └── autosummary_core │ │ ├── base.rst │ │ ├── class.rst │ │ └── module.rst ├── code │ ├── sf.rst │ ├── sf_apps.rst │ ├── sf_backends.rst │ ├── sf_circuitdrawer.rst │ ├── sf_compilers.rst │ ├── sf_decompositions.rst │ ├── sf_engine.rst │ ├── sf_io.rst │ ├── sf_ops.rst │ ├── sf_parameters.rst │ ├── sf_plot.rst │ ├── sf_program.rst │ ├── sf_program_utils.rst │ ├── sf_tdm.rst │ └── sf_utils.rst ├── conf.py ├── development │ ├── development_guide.rst │ ├── example_module_autosummary.txt │ ├── example_module_rst.txt │ ├── example_package_rst.txt │ ├── migration_guides.rst │ ├── release_notes.md │ └── research.rst ├── index.rst ├── install.rst ├── introduction │ ├── circuits.rst │ ├── data.rst │ ├── introduction.rst │ ├── ops.rst │ ├── photonic_hardware.rst │ └── states.rst ├── macros.tex ├── references.bib ├── requirements.txt └── zreferences.rst ├── examples ├── IQP.py ├── boson_sampling.py ├── bosonic_tutorial_sampling.py ├── custom_operation.py ├── example_job_X8.xbb ├── gate_teleportation.py ├── gaussian_boson_sampling.py ├── gaussian_cloning.py ├── gbs_data_visualization.py ├── gkp_phase_gate.py ├── hamiltonian_simulation.py ├── measurement_based_squeezing.py ├── optimization.py ├── quantum_neural_network.py └── teleportation.py ├── requirements-ci.txt ├── requirements-dev.txt ├── requirements.txt ├── setup.py ├── strawberryfields ├── __init__.py ├── _version.py ├── apps │ ├── __init__.py │ ├── clique.py │ ├── data │ │ ├── __init__.py │ │ ├── feature.py │ │ ├── feature_data │ │ │ ├── MUTAG_exact_fv.npy │ │ │ ├── MUTAG_mat.npy │ │ │ ├── QM9_exact_fv.npy │ │ │ ├── QM9_mat.npy │ │ │ └── QM9_mc_fv.npy │ │ ├── sample.py │ │ └── sample_data │ │ │ ├── MUTAG_0.npz │ │ │ ├── MUTAG_0_A.npz │ │ │ ├── MUTAG_1.npz │ │ │ ├── MUTAG_1_A.npz │ │ │ ├── MUTAG_2.npz │ │ │ ├── MUTAG_2_A.npz │ │ │ ├── MUTAG_3.npz │ │ │ ├── MUTAG_3_A.npz │ │ │ ├── TACE-AS.npz │ │ │ ├── TACE-AS_A.npz │ │ │ ├── formic.npz │ │ │ ├── formic_Ud.npz │ │ │ ├── formic_delta.npz │ │ │ ├── formic_w.npz │ │ │ ├── formic_wp.npz │ │ │ ├── p_hat300-1.npz │ │ │ ├── p_hat300-1_A.npz │ │ │ ├── planted.npz │ │ │ ├── planted_A.npz │ │ │ ├── pyrrole.npz │ │ │ ├── pyrrole_Lf.npz │ │ │ ├── pyrrole_Li.npz │ │ │ ├── pyrrole_U.npz │ │ │ ├── pyrrole_m.npz │ │ │ ├── pyrrole_rf.npz │ │ │ ├── pyrrole_ri.npz │ │ │ ├── pyrrole_wf.npz │ │ │ ├── pyrrole_wi.npz │ │ │ ├── water.npz │ │ │ ├── water_U.npz │ │ │ └── water_w.npz │ ├── plot.py │ ├── points.py │ ├── qchem │ │ ├── __init__.py │ │ ├── dynamics.py │ │ ├── utils.py │ │ └── vibronic.py │ ├── sample.py │ ├── similarity.py │ ├── subgraph.py │ └── train │ │ ├── __init__.py │ │ ├── cost.py │ │ ├── embed.py │ │ └── param.py ├── backends │ ├── __init__.py │ ├── base.py │ ├── bosonicbackend │ │ ├── __init__.py │ │ ├── backend.py │ │ ├── bosoniccircuit.py │ │ └── ops.py │ ├── data │ │ ├── fock_beamsplitter_factors_10.npz │ │ ├── fock_beamsplitter_factors_15.npz │ │ ├── fock_beamsplitter_factors_20.npz │ │ ├── fock_beamsplitter_factors_25.npz │ │ ├── fock_beamsplitter_factors_30.npz │ │ └── fock_beamsplitter_factors_5.npz │ ├── fockbackend │ │ ├── __init__.py │ │ ├── backend.py │ │ ├── circuit.py │ │ └── ops.py │ ├── gaussianbackend │ │ ├── __init__.py │ │ ├── backend.py │ │ ├── gaussiancircuit.py │ │ └── ops.py │ ├── states.py │ └── tfbackend │ │ ├── __init__.py │ │ ├── backend.py │ │ ├── circuit.py │ │ ├── ops.py │ │ └── states.py ├── circuitdrawer.py ├── compilers │ ├── __init__.py │ ├── bosonic.py │ ├── compiler.py │ ├── fock.py │ ├── gaussian.py │ ├── gaussian_merge.py │ ├── gaussian_unitary.py │ ├── gbs.py │ ├── passive.py │ ├── tdm.py │ ├── xcov.py │ ├── xstrict.py │ └── xunitary.py ├── decompositions.py ├── device.py ├── engine.py ├── io │ ├── __init__.py │ ├── blackbird_io.py │ ├── utils.py │ └── xir_io.py ├── logger.py ├── ops.py ├── parameters.py ├── plot.py ├── program.py ├── program_utils.py ├── result.py ├── tdm │ ├── __init__.py │ ├── program.py │ └── utils.py └── utils │ ├── __init__.py │ ├── decorators.py │ ├── gbs_analysis.py │ ├── post_processing.py │ ├── program_functions.py │ ├── random_numbers_matrices.py │ └── states.py └── tests ├── api ├── __init__.py ├── conftest.py ├── test_devicespec.py ├── test_remote_engine.py └── test_result.py ├── apps ├── conftest.py ├── qchem │ ├── BH_frq.out │ ├── gamess_dummy_m.out │ ├── gamess_dummy_r.out │ ├── gamess_dummy_w.out │ ├── lih_hessian_ccsd.out │ ├── test_dynamics.py │ ├── test_utils_qchem.py │ └── test_vibronic.py ├── test_clique.py ├── test_data.py ├── test_plot.py ├── test_points.py ├── test_sample.py ├── test_similarity.py ├── test_subgraph.py └── train │ ├── test_cost.py │ ├── test_embed.py │ └── test_param.py ├── backend ├── test_beamsplitter_operation.py ├── test_bosonic_backend.py ├── test_displaced_squeezed_state_preparation.py ├── test_displacement_operation.py ├── test_fock_measurement.py ├── test_gaussian_cptp.py ├── test_gaussian_gates.py ├── test_heterodyne.py ├── test_homodyne.py ├── test_is_vacuum.py ├── test_loss_channel.py ├── test_mbsqueeze_operation.py ├── test_modes.py ├── test_multimode_state_preparations.py ├── test_mzgate_operation.py ├── test_nongaussian_gates.py ├── test_postselection.py ├── test_rotation_operation.py ├── test_squeeze_operation.py ├── test_squeezed_state_preparation.py ├── test_state_preparations.py ├── test_states.py ├── test_states_polyquad.py ├── test_states_probabilities.py ├── test_states_wigner.py ├── test_tf_import.py ├── test_tf_ops.py ├── test_threshold_measurement.py └── test_twomode_squeezing_operation.py ├── bosonic_files ├── test_backend_bosoniccircuit.py └── test_backend_ops.py ├── conftest.py ├── frontend ├── compilers │ ├── conftest.py │ ├── test_compiler.py │ ├── test_gaussianmerge.py │ ├── test_gaussianunitary.py │ ├── test_passive.py │ ├── test_tdm.py │ ├── test_xcov.py │ ├── test_xstrict.py │ └── test_xunitary.py ├── io │ ├── test_io.py │ ├── test_io_blackbird.py │ └── test_io_xir.py ├── test_about.py ├── test_circuitdrawer.py ├── test_decompositions.py ├── test_engine.py ├── test_logger.py ├── test_ops_channel.py ├── test_ops_decompositions.py ├── test_ops_gate.py ├── test_ops_metaoperation.py ├── test_ops_preparation.py ├── test_parameters.py ├── test_post_processing.py ├── test_program.py ├── test_sf_plot.py ├── test_space_unroll.py ├── test_tdm_utils.py ├── test_tdmprogram.py └── test_utils.py ├── integration ├── test_algorithms.py ├── test_decompositions_integration.py ├── test_engine_integration.py ├── test_hbar_integration.py ├── test_measurement_integration.py ├── test_ops_integration.py ├── test_parameters_integration.py ├── test_tf_integration.py └── test_utils_integration.py └── pytest.ini /.codecov.yml: -------------------------------------------------------------------------------- 1 | fixes: 2 | - "ops.py::strawberryfields/ops.py" 3 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | # .coveragerc to control coverage.py 2 | [run] 3 | source = strawberryfields 4 | 5 | [report] 6 | # Regexes for lines to exclude from consideration 7 | exclude_lines = 8 | # Have to re-enable the standard pragma 9 | pragma: no cover 10 | 11 | # Don't complain about missing debug-only code: 12 | def __repr__ 13 | def __eq__ 14 | if self\.debug 15 | elif self._mode == 'einsum': 16 | 17 | # print statements 18 | def __str__ 19 | def __format__ 20 | def _print_list 21 | 22 | # Don't complain if tests don't hit defensive assertion code: 23 | raise AssertionError 24 | raise NotImplementedError 25 | raise NotApplicableError 26 | raise Exception 27 | raise ValueError 28 | raise ZeroDivisionError 29 | raise TypeError 30 | raise RuntimeError 31 | raise IndexError 32 | raise FileNotFoundError 33 | raise NotADirectoryError 34 | raise MergeFailure 35 | return __version__ 36 | if len(lst) != self._num_modes: 37 | elif max(lst) >= self._trunc: 38 | except NotImplementedError as err 39 | 40 | # Don't complain if non-runnable code isn't run: 41 | if 0: 42 | pass 43 | if __name__ == .__main__.: 44 | 45 | ignore_errors = True 46 | 47 | [html] 48 | directory = coverage_html_report 49 | -------------------------------------------------------------------------------- /.github/CHALLENGES.md: -------------------------------------------------------------------------------- 1 | # :trophy: Strawberry Fields Challenges :trophy: 2 | 3 | Looking for inspiration for contributing to the Strawberry Fields community? Or just in it for the 4 | Xanadu Swag™? Check out some ideas below to get started. If you get stuck, or have any questions, 5 | simply ask over at our [Slack community](https://u.strawberryfields.ai/slack). 6 | 7 | For more details on contributing to Strawberry Fields, see our 8 | [contributing guidelines](CONTRIBUTING.md). 9 | 10 | ## Community :strawberry: 11 | 12 | * **Blog post/tutorial** 13 | - Write a blog post or tutorial exploring your experience with Strawberry Fields, highlighting 14 | any cool results you generate, or unique applications for Strawberry Fields. Send us the link 15 | when you're done at support@xanadu.ai, and we may even add it to the Strawberry Fields gallery. 16 | 17 | ## Quantum theory and research :mortar_board: 18 | 19 | * **Publish results using Strawberry Fields** 20 | - If you've published a paper that utilizes Strawberry Fields for simulations, let us know, 21 | and we will add it to our Strawberry Fields gallery. 22 | 23 | * **Contribute continuous-variable theory or algorithms to our documentation** 24 | - Our aim is for the [Strawberry Fields documentation](http://strawberryfields.readthedocs.io) to 25 | become an open-access online resource for everything continuous-variable. If you have any particular 26 | algorithms or theory you wish to include, simply chat to us on our Slack channel. 27 | 28 | * **Write a non-physicist introduction to CV quantum computation** 29 | - Quantum computation is a tricky field to break into for newcomers. One thing we are currently 30 | missing in our documentation is a non-physicist introduction to CV quantum computation. 31 | That is, a page that introduces the idea of quantum computation with no equations (or very few equations), 32 | few references, lots of figures and pictures, and discusses more the application and potential than the theory. 33 | The main goal for this challenge would be to introduce continuous-variable quantum computing 34 | without having to first introduce the discrete-variable qubit model. 35 | 36 | ## Coding contributions :computer: 37 | 38 | *Note*: please contact us, either via the [Slack channel](https://u.strawberryfields.ai/slack) or at support@xanadu.ai, 39 | to let us know if you want to start working on any coding challenges currently marked as *open*, as well as the 40 | corresponding GitHub repository. We will update the status below with a link to your repository. 41 | 42 | * **Add common expectation values to the state module** 43 | - *Status: open* 44 | - Currently, Strawberry Fields supports the `state.quad_expectation()` method to calculate the quadrature expectation 45 | values x and p, as well as the quadrature variance \Delta x and \Delta p. In this challenge, modify the 46 | Strawberry Fields `states.py` module to calculate other common expectation values, such as , , and others. 47 | 48 | * **Find an accurate and numerically efficient implementation of the cubic phase gate** 49 | - *Status: open* 50 | - This challenge would involve 51 | finding a more accurate and numerically efficient method of implementing the cubic phase gate 52 | in the Fock and/or Tensorflow backends of Strawberry Fields. 53 | 54 | * **Create a new Strawberry Fields backend** 55 | - Strawberry Fields currently includes 3 backends; two Fock-basis backends (using NumPy and Tensorflow), 56 | and one Gaussian backend (using NumPy). Some ideas for a new backend include: 57 | - **Gaussian-Tensorflow**: (*status: open*) Duplicate the included Gaussian backend, and add Tensorflow support 58 | - **MPI support**: (*status: open*) Add MPI support (using mpi4py) to one of the backends 59 | ``` 60 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at research@xanadu.ai. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yaml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: File a bug report 3 | title: '[replace with a short descriptive title for your report]' 4 | labels: "bug" 5 | 6 | body: 7 | - type: checkboxes 8 | id: terms 9 | attributes: 10 | label: | 11 | Before posting a bug report 12 | description: | 13 | Search existing GitHub issues to make sure the issue does not already exist: 14 | https://github.com/XanaduAI/strawberryfields/issues 15 | options: 16 | - label: I have searched exisisting GitHub issues to make sure the issue does not already exist. 17 | required: true 18 | - type: markdown 19 | id: description 20 | attributes: 21 | value: | 22 | For general technical details and contribution guidelines, check out our documentation: 23 | https://strawberryfields.readthedocs.io 24 | 25 | # Issue description 26 | Description of the issue - include code snippets in the Source code section below and screenshots if relevant. 27 | - type: textarea 28 | id: expected 29 | attributes: 30 | label: Expected behavior 31 | description: | 32 | What do you expect to happen? 33 | validations: 34 | required: true 35 | - type: textarea 36 | id: actual 37 | attributes: 38 | label: Actual behavior 39 | description: | 40 | What actually happens? 41 | validations: 42 | required: true 43 | - type: textarea 44 | id: reproduces 45 | attributes: 46 | label: Reproduces how often 47 | description: | 48 | What percentage of the time does it reproduce? 49 | validations: 50 | required: true 51 | - type: textarea 52 | id: system 53 | attributes: 54 | label: System information 55 | description: Please post the output of `import strawberryfields as sf; sf.about()` or, if not possible/relevant, a note on why this is not included. This will be automatically formatted into code, so no need for backticks. 56 | render: shell 57 | validations: 58 | required: true 59 | - type: markdown 60 | id: source-code-and-tracebacks 61 | attributes: 62 | value: | 63 | # Source code and tracebacks 64 | 65 | Any additional code snippets and error tracebacks related to the issue? 66 | - type: textarea 67 | id: sourcecode 68 | attributes: 69 | label: Source code 70 | description: Please include a minimal non-working example, or any other code related to the issue, here. This will be automatically formatted into code, so no need for backticks. 71 | render: shell 72 | - type: textarea 73 | id: tracebacks 74 | attributes: 75 | label: Tracebacks 76 | description: Please include the error tracebacks related to the issue here. This will be automatically formatted into code, so no need for backticks. 77 | render: shell 78 | - type: textarea 79 | id: additional-info 80 | attributes: 81 | label: Additional information 82 | description: Please include any additional information, configuration or data that might be necessary to reproduce the issue. 83 | render: shell 84 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yaml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest a new feature 3 | title: '[replace with a short descriptive title for your request]' 4 | labels: "enhancement" 5 | 6 | body: 7 | - type: checkboxes 8 | id: terms 9 | attributes: 10 | label: | 11 | Before posting a feature request 12 | description: | 13 | Search existing GitHub issues to make sure the request does not already exist: 14 | https://github.com/XanaduAI/strawberryfields/issues 15 | options: 16 | - label: I have searched exisisting GitHub issues to make sure the feature request does not already exist. 17 | required: true 18 | - type: markdown 19 | id: description 20 | attributes: 21 | value: | 22 | # Feature description 23 | Description of the feature request - include code snippets and screenshots here if relevant. 24 | - type: textarea 25 | id: details 26 | attributes: 27 | label: Feature details 28 | description: | 29 | What feature would you like to have? 30 | validations: 31 | required: true 32 | - type: textarea 33 | id: implementation 34 | attributes: 35 | label: Implementation 36 | description: | 37 | Do you have an idea for how this could be implemented? Please include those details here. 38 | - type: dropdown 39 | id: urgency 40 | attributes: 41 | label: How important would you say this feature is? 42 | options: 43 | - "1: Not important. Would be nice to have." 44 | - "2: Somewhat important. Needed this quarter." 45 | - "3: Very important! Blocking work." 46 | validations: 47 | required: true 48 | - type: textarea 49 | id: info 50 | attributes: 51 | label: Additional information 52 | description: | 53 | Please provide any additional information here. Include potential alternative solutions, or workarounds, as well as references, if any. -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Before submitting 2 | 3 | Please complete the following checklist when submitting a PR: 4 | 5 | - [ ] All new features must include a unit test. 6 | If you've fixed a bug or added code that should be tested, add a test to the 7 | test directory! 8 | 9 | - [ ] All new functions and code must be clearly commented and documented. 10 | If you do make documentation changes, make sure that the docs build and 11 | render correctly by running `make docs`. 12 | 13 | - [ ] Ensure that the test suite passes, by running `make test`. 14 | 15 | - [ ] Ensure that code and tests are properly formatted, by running `make format` or `black -l 100 16 | ` on any relevant files. You will need to have the Black code format installed: 17 | `pip install black`. 18 | 19 | - [ ] Add a new entry to the `.github/CHANGELOG.md` file, summarizing the 20 | change, and including a link back to the PR. 21 | 22 | - [ ] The Strawberry Fields source code conforms to 23 | [PEP8 standards](https://www.python.org/dev/peps/pep-0008/). 24 | We check all of our code against [Pylint](https://www.pylint.org/). 25 | To lint modified files, simply `pip install pylint`, and then 26 | run `pylint strawberryfields/path/to/file.py`. 27 | 28 | When all the above are checked, delete everything above the dashed 29 | line and fill in the pull request template. 30 | 31 | ------------------------------------------------------------------------------------------------------------ 32 | 33 | **Context:** 34 | 35 | **Description of the Change:** 36 | 37 | **Benefits:** 38 | 39 | **Possible Drawbacks:** 40 | 41 | **Related GitHub Issues:** 42 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: "Documentation check" 2 | on: 3 | - pull_request 4 | 5 | jobs: 6 | sphinx: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: XanaduAI/sphinx-action@master 11 | with: 12 | docs-folder: "doc/" 13 | pre-build-command: "apt install -y graphviz && pip3 install -r requirements.txt && pip3 install ." 14 | build-command: "sphinx-build -b html . _build -W --keep-going" 15 | -------------------------------------------------------------------------------- /.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | name: Formatting check 2 | on: 3 | - pull_request 4 | 5 | jobs: 6 | black: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - name: Cancel Previous Runs 11 | uses: styfle/cancel-workflow-action@0.4.1 12 | with: 13 | access_token: ${{ github.token }} 14 | 15 | - name: Set up Python 16 | uses: actions/setup-python@v2 17 | with: 18 | python-version: 3.8 19 | 20 | - name: Install dependencies 21 | run: pip install black 22 | 23 | - uses: actions/checkout@v2 24 | 25 | - name: Run Black 26 | run: black -l 100 strawberryfields/ tests/ --check 27 | -------------------------------------------------------------------------------- /.github/workflows/tests.yaml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | 8 | env: 9 | COVERALLS_PARALLEL: true 10 | PURE: 1 11 | BATCHED: 0 12 | LOGGING: info 13 | 14 | jobs: 15 | core-tests: 16 | runs-on: ubuntu-latest 17 | 18 | env: 19 | SYMPY_USE_CACHE: "no" 20 | OPTIONS: ${{ matrix.options }} 21 | BATCHED: ${{ matrix.batched }} 22 | TF_DEPENDENCIES: "tensorflow|tensorboard" 23 | 24 | strategy: 25 | matrix: 26 | include: 27 | - {BATCHED: 0, OPTIONS: "frontend or apps or api or gaussian"} 28 | - {BATCHED: 0, OPTIONS: "fock"} 29 | - {BATCHED: 0, OPTIONS: "tf"} 30 | - {BATCHED: 1, OPTIONS: "tf and pure"} 31 | - {BATCHED: 1, OPTIONS: "tf and mixed"} 32 | - {BATCHED: 0, OPTIONS: "bosonic"} 33 | - {BATCHED: 0, OPTIONS: "not tf"} 34 | steps: 35 | - name: Cancel Previous Runs 36 | uses: styfle/cancel-workflow-action@0.4.1 37 | with: 38 | access_token: ${{ github.token }} 39 | 40 | - uses: actions/checkout@v4 41 | with: 42 | fetch-depth: 2 43 | 44 | - name: Set up Python 45 | uses: actions/setup-python@v2 46 | with: 47 | python-version: 3.12 48 | 49 | - name: Install dependencies 50 | run: | 51 | [ "$OPTIONS" = "not tf" ] && gawk -i inplace '!/('$TF_DEPENDENCIES')/' requirements-ci.txt 52 | python3 -m pip install --upgrade pip 53 | pip install -r requirements-ci.txt 54 | pip install wheel codecov pytest pytest-cov pytest-randomly pytest-mock pytest-logger --upgrade 55 | 56 | - name: Install Strawberry Fields 57 | run: | 58 | pip install -r requirements-ci.txt 59 | python3 setup.py bdist_wheel 60 | pip install dist/strawberryfields*.whl 61 | 62 | - name: Run tests 63 | run: python3 -m pytest tests --cov=strawberryfields --cov-report=term-missing --cov-report=xml -p no:warnings --randomly-seed=42 --tb=native -m "$OPTIONS" 64 | 65 | - name: Adjust coverage file for Codecov 66 | run: bash <(sed -i 's/filename=\"/filename=\"strawberryfields\//g' coverage.xml) 67 | 68 | - name: Upload coverage to Codecov 69 | uses: codecov/codecov-action@v5 70 | with: 71 | # token: ${{ secrets.CODECOV_TOKEN }} # we currently do not have a token for SF 72 | files: ./coverage.xml 73 | disable_search: true 74 | fail_ci_if_error: false -------------------------------------------------------------------------------- /.github/workflows/upload.yml: -------------------------------------------------------------------------------- 1 | name: Upload 2 | on: 3 | release: 4 | types: [published] 5 | 6 | jobs: 7 | upload: 8 | runs-on: ubuntu-latest 9 | 10 | env: 11 | SYMPY_USE_CACHE: "no" 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Python 17 | uses: actions/setup-python@v2 18 | with: 19 | python-version: 3.8 20 | 21 | - name: Build and install Strawberry Fields 22 | run: | 23 | python -m pip install --upgrade pip wheel 24 | python setup.py bdist_wheel 25 | pip install dist/StrawberryFields*.whl 26 | 27 | - name: Install test dependencies 28 | run: | 29 | pip install -r requirements-ci.txt 30 | pip install wheel pytest pytest-cov pytest-mock --upgrade 31 | 32 | - name: Run tests 33 | run: | 34 | python -m pytest tests -p no:warnings --randomly-seed=42 --tb=native 35 | 36 | - name: Publish 37 | uses: pypa/gh-action-pypi-publish@master 38 | with: 39 | user: __token__ 40 | password: ${{ secrets.PYPI }} 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.pyc 3 | doc/_build 4 | build 5 | dist 6 | qit.egg-info 7 | .idea 8 | examples/*ipynp* 9 | *.egg-info* 10 | .coverage 11 | coverage_html_report/* 12 | notebooks/* 13 | examples/.ipynb_checkpoints/* 14 | .pytest_cache/* 15 | pytest/.pytest_cache/ 16 | doc/_static/thumbs/* 17 | !doc/_static/code.png 18 | doc/code/api/* 19 | Pipfile* 20 | .vscode/ 21 | .ipynb_checkpoints/* 22 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | # A comma-separated list of package or module names from where C extensions may 3 | # be loaded. Extensions are loading into the active Python interpreter and may 4 | # run arbitrary code 5 | extension-pkg-whitelist=numpy,tensorflow,scipy,networkx,strawberryfields 6 | 7 | [TYPECHECK] 8 | 9 | # List of module names for which member attributes should not be checked 10 | # (useful for modules/projects where namespaces are manipulated during runtime 11 | # and thus existing member attributes cannot be deduced by static analysis. It 12 | # supports qualified module names, as well as Unix pattern matching. 13 | ignored-modules=numpy,tensorflow,scipy,networkx,strawberryfields,strawberryfields.parameters,collections.abc 14 | 15 | # List of classes names for which member attributes should not be checked 16 | # (useful for classes with attributes dynamically set). This supports can work 17 | # with qualified names. 18 | ignored-classes=numpy,tensorflow,scipy,networkx,strawberryfields 19 | 20 | [MESSAGES CONTROL] 21 | 22 | # Enable the message, report, category or checker with the given id(s). You can 23 | # either give multiple identifier separated by comma (,) or put this option 24 | # multiple time. 25 | #enable= 26 | 27 | # Disable the message, report, category or checker with the given id(s). You 28 | # can either give multiple identifier separated by comma (,) or put this option 29 | # multiple time (only on the command line, not in the configuration file where 30 | # it should appear only once). 31 | disable=line-too-long,invalid-name,too-many-lines,redefined-builtin,too-many-locals,duplicate-code,too-many-arguments,too-few-public-methods 32 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | sphinx: 4 | configuration: doc/conf.py 5 | 6 | python: 7 | install: 8 | - requirements: doc/requirements.txt 9 | - method: pip 10 | path: . 11 | 12 | build: 13 | os: ubuntu-22.04 14 | tools: 15 | python: "3.8" 16 | -------------------------------------------------------------------------------- /DOCS.rst: -------------------------------------------------------------------------------- 1 | Documentation 2 | ============= 3 | 4 | The Strawberry Fields documentation is built automatically and hosted at `Read the Docs `_. 5 | 6 | To build the documentation locally, the following additional packages are required: 7 | 8 | * `Sphinx `_ >=1.5 9 | * `graphviz `_ >=2.38 10 | * `sphinxcontrib-bibtex `_ >=0.3.6 11 | 12 | If using Ubuntu, they can be installed via a combination of ``apt`` and ``pip``: 13 | :: 14 | 15 | $ sudo apt install graphviz 16 | $ pip3 install sphinx --user 17 | $ pip3 install sphinxcontrib-bibtex --user 18 | 19 | To build the HTML documentation, go to the top-level directory and run the command 20 | :: 21 | 22 | $ make docs 23 | 24 | The documentation can then be found in the ``doc/_build/html/`` directory. 25 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include doc/* 3 | include LICENSE 4 | include examples/* 5 | include tests/* 6 | include strawberryfields/backends/data/* 7 | include strawberryfields/apps/data/feature_data/* 8 | include strawberryfields/apps/data/sample_data/* 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PYTHON := $(shell which python3 2>/dev/null) 2 | TESTRUNNER := -m pytest tests -p no:warnings --randomly-seed=42 3 | COVERAGE := --cov=strawberryfields --cov-report=html:coverage_html_report --cov-append 4 | 5 | .PHONY: help 6 | help: 7 | @echo "Please use \`make ' where is one of" 8 | @echo " install to install Strawberry Fields" 9 | @echo " wheel to build the Strawberry Fields wheel" 10 | @echo " dist to package the source distribution" 11 | @echo " docs to generate the Sphinx documentation" 12 | @echo " clean to delete all temporary, cache, and build files" 13 | @echo " clean-docs to delete all built documentation" 14 | @echo " format to run black formatting" 15 | @echo " test to run the test suite for entire codebase" 16 | @echo " test-[component] to run the test suite for frontend, fock, tf, gaussian or apps" 17 | @echo " coverage to generate a coverage report for entire codebase" 18 | @echo " coverage-[backend] to generate a coverage report for frontend, fock, tf, gaussian or apps" 19 | 20 | .PHONY: install 21 | install: 22 | ifndef PYTHON3 23 | @echo "To install Strawberry Fields you need to have Python 3 installed" 24 | endif 25 | $(PYTHON) setup.py install 26 | 27 | .PHONY: wheel 28 | wheel: 29 | $(PYTHON) setup.py bdist_wheel 30 | 31 | .PHONY: dist 32 | dist: 33 | $(PYTHON) setup.py sdist 34 | 35 | .PHONY : clean 36 | clean: 37 | rm -rf strawberryfields/__pycache__ 38 | rm -rf strawberryfields/api/__pycache__ 39 | rm -rf strawberryfields/backends/__pycache__ 40 | rm -rf strawberryfields/backends/fockbackend/__pycache__ 41 | rm -rf strawberryfields/backends/tfbackend/__pycache__ 42 | rm -rf strawberryfields/backends/gaussianbackend/__pycache__ 43 | rm -rf tests/__pycache__ 44 | rm -rf tests/api/__pycache__ 45 | rm -rf tests/backend/__pycache__ 46 | rm -rf tests/frontend/__pycache__ 47 | rm -rf tests/integration/__pycache__ 48 | rm -rf dist 49 | rm -rf build 50 | 51 | .PHONY : docs 52 | docs: 53 | make -C doc html 54 | 55 | .PHONY : clean-docs 56 | clean-docs: 57 | make -C doc clean 58 | rm -rf doc/code/api 59 | 60 | .PHONY : format 61 | format: 62 | black -l 100 strawberryfields tests 63 | 64 | test: test-frontend test-gaussian test-fock test-tf batch-test-tf test-apps test-api 65 | 66 | test-%: 67 | @echo "Testing $(subst test-,,$@) backend..." 68 | $(PYTHON) $(TESTRUNNER) -m $(subst test-,,"$@") 69 | 70 | batch-test-%: 71 | @echo "Testing $(subst batch-test-,,$@) backend in batch mode..." 72 | export BATCHED=1 && $(PYTHON) $(TESTRUNNER) -m $(subst batch-test-,,"$@") 73 | 74 | coverage: coverage-frontend coverage-gaussian coverage-fock coverage-tf batch-coverage-tf coverage-apps coverage-api 75 | 76 | coverage-%: 77 | @echo "Generating coverage report for $(subst coverage-,,$@)..." 78 | $(PYTHON) $(TESTRUNNER) $(COVERAGE) -m $(subst coverage-,,"$@") 79 | 80 | batch-coverage-%: 81 | @echo "Generating coverage report for $(subst batch-coverage-,,"$@") in batch mode..." 82 | export BATCHED=1 && $(PYTHON) $(TESTRUNNER) $(COVERAGE) -m $(subst batch-coverage-,,"$@") 83 | -------------------------------------------------------------------------------- /TESTS.rst: -------------------------------------------------------------------------------- 1 | Software tests 2 | ============== 3 | 4 | The Strawberry Fields test suite requires `pytest `_, `pytest-cov `_, `pytest-randomly `_, and `pytest-mocks `_ for coverage reports. These can be installed via ``pip``: 5 | :: 6 | 7 | $ pip install pytest pytest-cov pytest-randomly pytest-mock 8 | 9 | 10 | To ensure that Strawberry Fields is working correctly after installation, the test suite can be run by navigating to the source code folder and running 11 | :: 12 | 13 | $ make test 14 | 15 | Note that this runs *all* of the tests, using *all* available backends, in both pure *and* mixed modes, so can be quite slow (it should take around 1 hour to complete). Alternatively, you can run the full test suite for a particular component by running 16 | :: 17 | 18 | $ make test-[component] 19 | 20 | where ``[component]`` should be replaced with either ``frontend`` for the Strawberry Fields frontend UI, or one of the :ref:`backend ` you would like to test (``fock``, ``tf``, or ``gaussian``). 21 | 22 | Pytest can accept a boolean logic string specifying exactly which tests to run, if finer control is needed. For example, to run all tests for the frontend and the Gaussian backend, as well as the Fock backend (but only for pure states), you can run: 23 | :: 24 | 25 | $ make test-"gaussian or frontend or (fock and pure)" 26 | 27 | The above syntax also works for the ``make coverage`` command, as well as ``make batch-test`` command for running the tests in batched mode. 28 | 29 | 30 | Individual test modules are run by invoking pytest directly from the command line: 31 | :: 32 | 33 | $ pytest tests/test_gate.py 34 | 35 | 36 | .. note:: **Adding tests to Strawberry Fields** 37 | 38 | The ``tests`` folder is organised into three subfolders: ``backend`` for tests that 39 | only import a Strawberry Fields backend, ``frontend`` for tests that import the Strawberry 40 | Fields UI but do not make use of a backend, and ``integration`` for tests that test 41 | integration of the frontend and backends. 42 | 43 | When writing new tests, make sure to mark what components it tests. For a backend test, 44 | you can use the ``backends`` mark, which accepts the names of the backends: 45 | 46 | .. code-block:: python 47 | 48 | pytest.mark.backends("fock", "gaussian") 49 | 50 | For a frontend-only test, you can use the frontend mark: 51 | 52 | .. code-block:: python 53 | 54 | pytest.mark.frontend 55 | -------------------------------------------------------------------------------- /doc/_ext/edit_on_github.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the 3 | sidebar. 4 | Loosely based on https://github.com/astropy/astropy/pull/347 5 | """ 6 | 7 | import os 8 | import warnings 9 | 10 | 11 | __licence__ = 'BSD (3 clause)' 12 | 13 | 14 | def get_github_url(app, view, path): 15 | return 'https://github.com/{project}/{view}/{branch}/{path}'.format( 16 | project=app.config.edit_on_github_project, 17 | view=view, 18 | branch=app.config.edit_on_github_branch, 19 | path=path) 20 | 21 | 22 | def html_page_context(app, pagename, templatename, context, doctree): 23 | if templatename != 'page.html': 24 | return 25 | 26 | if not app.config.edit_on_github_project: 27 | warnings.warn("edit_on_github_project not specified") 28 | return 29 | 30 | if not doctree: 31 | return 32 | 33 | path = os.path.relpath(doctree.get('source'), app.builder.srcdir) 34 | show_url = get_github_url(app, 'blob', path) 35 | edit_url = get_github_url(app, 'edit', path) 36 | 37 | context['show_on_github_url'] = show_url 38 | context['edit_on_github_url'] = edit_url 39 | 40 | 41 | def setup(app): 42 | app.add_config_value('edit_on_github_project', '', True) 43 | app.add_config_value('edit_on_github_branch', 'master', True) 44 | app.connect('html-page-context', html_page_context) -------------------------------------------------------------------------------- /doc/_images/shirt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_images/shirt.jpg -------------------------------------------------------------------------------- /doc/_images/sticker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_images/sticker.jpg -------------------------------------------------------------------------------- /doc/_images/sticker2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_images/sticker2.jpg -------------------------------------------------------------------------------- /doc/_images/sticker_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_images/sticker_crop.jpg -------------------------------------------------------------------------------- /doc/_static/Dgate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/_static/GBS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/GBS.png -------------------------------------------------------------------------------- /doc/_static/GateSynthesis.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/GateSynthesis.gif -------------------------------------------------------------------------------- /doc/_static/NOON.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/NOON.png -------------------------------------------------------------------------------- /doc/_static/Sgate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/_static/StateLearning.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/StateLearning.gif -------------------------------------------------------------------------------- /doc/_static/Strawberry-fields_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/Strawberry-fields_white.png -------------------------------------------------------------------------------- /doc/_static/TF.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/TF.png -------------------------------------------------------------------------------- /doc/_static/Vgate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/_static/X8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/X8.png -------------------------------------------------------------------------------- /doc/_static/borealis_3d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/borealis_3d.png -------------------------------------------------------------------------------- /doc/_static/borealis_schematic_advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/borealis_schematic_advanced.png -------------------------------------------------------------------------------- /doc/_static/borealis_schematic_simple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/borealis_schematic_simple.png -------------------------------------------------------------------------------- /doc/_static/boson_sampling_ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/boson_sampling_ex.png -------------------------------------------------------------------------------- /doc/_static/bs_measure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/bs_measure.png -------------------------------------------------------------------------------- /doc/_static/cats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/cats.png -------------------------------------------------------------------------------- /doc/_static/chip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/chip.png -------------------------------------------------------------------------------- /doc/_static/circulant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/circulant.png -------------------------------------------------------------------------------- /doc/_static/clements.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/clements.png -------------------------------------------------------------------------------- /doc/_static/cloning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/cloning.png -------------------------------------------------------------------------------- /doc/_static/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/code.png -------------------------------------------------------------------------------- /doc/_static/complete_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/complete_graph.png -------------------------------------------------------------------------------- /doc/_static/complete_subgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/complete_subgraph.png -------------------------------------------------------------------------------- /doc/_static/dense.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/dense.png -------------------------------------------------------------------------------- /doc/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/favicon.ico -------------------------------------------------------------------------------- /doc/_static/fock_teleport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/fock_teleport.png -------------------------------------------------------------------------------- /doc/_static/formic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/formic.png -------------------------------------------------------------------------------- /doc/_static/formic_spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/formic_spec.png -------------------------------------------------------------------------------- /doc/_static/formic_spectrum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/formic_spectrum.png -------------------------------------------------------------------------------- /doc/_static/gaussian_boson_sampling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/gaussian_boson_sampling.png -------------------------------------------------------------------------------- /doc/_static/graphs/MUTAG_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/MUTAG_0.png -------------------------------------------------------------------------------- /doc/_static/graphs/MUTAG_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/MUTAG_1.png -------------------------------------------------------------------------------- /doc/_static/graphs/MUTAG_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/MUTAG_2.png -------------------------------------------------------------------------------- /doc/_static/graphs/MUTAG_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/MUTAG_3.png -------------------------------------------------------------------------------- /doc/_static/graphs/TACE-AS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/TACE-AS.png -------------------------------------------------------------------------------- /doc/_static/graphs/planted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/graphs/planted.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_gate_synthesis_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_gate_synthesis_001.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_gate_synthesis_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_gate_synthesis_002.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_minimizing_correlations_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_minimizing_correlations_001.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_minimizing_correlations_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_minimizing_correlations_002.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_state_learner_001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_state_learner_001.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_state_learner_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_state_learner_002.png -------------------------------------------------------------------------------- /doc/_static/images/sphx_glr_run_state_learner_003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/images/sphx_glr_run_state_learner_003.png -------------------------------------------------------------------------------- /doc/_static/interactive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/interactive.png -------------------------------------------------------------------------------- /doc/_static/laptop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/laptop.png -------------------------------------------------------------------------------- /doc/_static/max_clique.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/max_clique.png -------------------------------------------------------------------------------- /doc/_static/minimizing_correlations.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/minimizing_correlations.gif -------------------------------------------------------------------------------- /doc/_static/normal_pp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/normal_pp.png -------------------------------------------------------------------------------- /doc/_static/points.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/points.png -------------------------------------------------------------------------------- /doc/_static/pyrrole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/pyrrole.png -------------------------------------------------------------------------------- /doc/_static/qcircuit/BSgate.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{article} 2 | \input{Qcircuit} 3 | \renewcommand{\Qcircuit}[1][0em]{\xymatrix @*=<#1>} 4 | \newcommand{\Rgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{R} & \qw}} 5 | \newcommand{\Dgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{D} & \qw}} 6 | \newcommand{\Sgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{S} & \qw}} 7 | \newcommand{\BSgate}{\Qcircuit @C=0.5em @R=.7em { 8 | & \multigate{1}{BS} & \qw \\ 9 | & \ghost{BS}& \qw 10 | }} 11 | \newcommand{\Vgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{V} & \qw}} 12 | 13 | \begin{document} 14 | \BSgate 15 | \thispagestyle{empty} % make sure no other junk shows up 16 | \end{document} 17 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/Dgate.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{article} 2 | \input{Qcircuit} 3 | \renewcommand{\Qcircuit}[1][0em]{\xymatrix @*=<#1>} 4 | \newcommand{\Rgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{R} & \qw}} 5 | \newcommand{\Dgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{D} & \qw}} 6 | \newcommand{\Sgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{S} & \qw}} 7 | \newcommand{\BSgate}{\Qcircuit @C=0.5em @R=.7em { 8 | & \multigate{1}{BS} & \qw \\ 9 | & \ghost{BS}& \qw 10 | }} 11 | \newcommand{\Vgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{V} & \qw}} 12 | 13 | \begin{document} 14 | \Dgate 15 | \thispagestyle{empty} % make sure no other junk shows up 16 | \end{document} 17 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/Rgate.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{article} 2 | \input{Qcircuit} 3 | \renewcommand{\Qcircuit}[1][0em]{\xymatrix @*=<#1>} 4 | \newcommand{\Rgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{R} & \qw}} 5 | \newcommand{\Dgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{D} & \qw}} 6 | \newcommand{\Sgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{S} & \qw}} 7 | \newcommand{\BSgate}{\Qcircuit @C=0.5em @R=.7em { 8 | & \multigate{1}{BS} & \qw \\ 9 | & \ghost{BS}& \qw 10 | }} 11 | \newcommand{\Vgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{V} & \qw}} 12 | 13 | \begin{document} 14 | \Rgate 15 | \thispagestyle{empty} % make sure no other junk shows up 16 | \end{document} 17 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/Sgate.tex: -------------------------------------------------------------------------------- 1 | \documentclass[11pt]{article} 2 | \input{Qcircuit} 3 | \renewcommand{\Qcircuit}[1][0em]{\xymatrix @*=<#1>} 4 | \newcommand{\Rgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{R} & \qw}} 5 | \newcommand{\Dgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{D} & \qw}} 6 | \newcommand{\Sgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{S} & \qw}} 7 | \newcommand{\BSgate}{\Qcircuit @C=0.5em @R=.7em { 8 | & \multigate{1}{BS} & \qw \\ 9 | & \ghost{BS}& \qw 10 | }} 11 | \newcommand{\Vgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{V} & \qw}} 12 | 13 | \begin{document} 14 | \Sgate 15 | \thispagestyle{empty} % make sure no other junk shows up 16 | \end{document} 17 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/boson_sampling_ex.tex: -------------------------------------------------------------------------------- 1 | \begin{picture}(100,100) 2 | \put(0,0){ 3 | \Qcircuit @C=1.5em @R=1em { 4 | \lstick{q_0:~\ket{1}} & \gate{R(0.5719)} & \multigate{1}{BS} & \qw & \multigate{1}{BS} & \qw& \multigate{1}{BS} &\qw\\ 5 | \lstick{q_1:~\ket{1}} & \gate{R(-1.9782)} & \ghost{BS} & \multigate{1}{BS}& \ghost{BS} & \multigate{1}{BS} & \ghost{BS}&\qw\\ 6 | \lstick{q_2:~\ket{0}} & \gate{R(2.0603)} & \multigate{1}{BS} & \ghost{BS} & \multigate{1}{BS} & \ghost{BS}& \multigate{1}{BS}&\qw\\ 7 | \lstick{q_3:~\ket{1}} & \gate{R(0.0644)} & \ghost{BS} & \qw & \ghost{BS} & \qw & \ghost{BS}&\qw 8 | } 9 | } 10 | %\put(81,-20){\footnotesize$\hat{x}$} 11 | %\put(81,-41){\footnotesize$\hat{p}$} 12 | \end{picture} -------------------------------------------------------------------------------- /doc/_static/qcircuit/bosonsampling.tex: -------------------------------------------------------------------------------- 1 | \begin{picture}(100,100) 2 | \put(0,0){ 3 | \Qcircuit @C=1.5em @R=1em { 4 | \lstick{q_0:~\ket{n_1}} & \gate{R(\phi_1)} & \multigate{1}{BS} & \qw & \multigate{1}{BS} & \qw& \multigate{1}{BS} &\measureD{\hat{n}}\\ 5 | \lstick{q_1:~\ket{n_2}} & \gate{R(\phi_2)} & \ghost{BS} & \multigate{1}{BS}& \ghost{BS} & \multigate{1}{BS} & \ghost{BS}&\measureD{\hat{n}}\\ 6 | \lstick{q_2:~\ket{n_3}} & \gate{R(\phi_3)} & \multigate{1}{BS} & \ghost{BS} & \multigate{1}{BS} & \ghost{BS}& \multigate{1}{BS}&\measureD{\hat{n}}\\ 7 | \lstick{q_3:~\ket{n_4}} & \gate{R(\phi_4)} & \ghost{BS} & \qw & \ghost{BS} & \qw & \ghost{BS}&\measureD{\hat{n}} 8 | } 9 | } 10 | %\put(81,-20){\footnotesize$\hat{x}$} 11 | %\put(81,-41){\footnotesize$\hat{p}$} 12 | \end{picture} -------------------------------------------------------------------------------- /doc/_static/qcircuit/cloning.tex: -------------------------------------------------------------------------------- 1 | \begin{picture}(100,100) 2 | \put(0,0){ 3 | \Qcircuit @C=1.5em @R=1em { 4 | \lstick{q_0:~\ket{\alpha_0}} & \multigate{1}{BS} &\qw & \gate{X} & \gate{Z} &\multigate{3}{BS}& \qw&\rstick{\hspace{-0.5cm}\ket{\alpha'}_1}\\ 5 | \lstick{q_1:~\ket{0}} &\ghost{BS} & \multigate{1}{BS} & \meter \cwx[-1] & \\ 6 | \lstick{q_2:~\ket{0}} & \qw & \ghost{BS} &\meter & \control\cw\cwx[-2] &\\ 7 | \lstick{q_3:~\ket{0}} & \qw & \qw & \qw & \qw & \ghost{BS} & \qw &\rstick{\hspace{-0.5cm}\ket{\alpha'}_3} 8 | } 9 | } 10 | \put(81,-20){\footnotesize$\hat{x}$} 11 | \put(81,-41){\footnotesize$\hat{p}$} 12 | \end{picture} -------------------------------------------------------------------------------- /doc/_static/qcircuit/gate_teleport1.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=2em { 2 | \lstick{q_0:~\ket{\psi}~} & \ctrl{1} & \gate{F^\dagger} & \meter & \rstick{\hspace{-0.5cm}\ket{x}\bra{x}=m}\\ 3 | \lstick{q_1:~\ket{0}_P} & \ctrl{0} & \qw & \qw & \qw &\rstick{\hspace{-0.5cm}X(m)F\ket{\psi}} 4 | } 5 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/gate_teleport2.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=2em { 2 | \lstick{q_0:~U\ket{\psi}} & \ctrl{1} & \gate{F^\dagger} & \meter & \rstick{\hspace{-0.5cm}\ket{x}\bra{x}=m}\\ 3 | \lstick{q_1:~\ket{0}_P~} & \ctrl{0} & \qw & \qw & \qw &\rstick{\hspace{-0.5cm}X(m)FU\ket{\psi}} 4 | } 5 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/gate_teleport3.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=2em { 2 | \lstick{q_0:~\ket{\psi}~} & \ctrl{1} & \meter & \rstick{\hspace{-0.5cm}U^\dagger\ket{p}\bra{p}U=m}\\ 3 | \lstick{q_1:~\ket{0}_P} & \ctrl{0} & \qw & \qw &\rstick{\hspace{-0.5cm}X(m)FU\ket{\psi}} 4 | } 5 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/gate_teleport_ex.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=2em { 2 | \lstick{q_0:~\ket{\psi}~~} & \ctrl{1} & \qw & \gate{F^\dagger} & \meter & \rstick{\hspace{-0.5cm}\ket{x}\bra{x}=m_1}\\ 3 | \lstick{q_1:P\ket{0}_P} & \ctrl{0} & \ctrl{1}& \gate{F^\dagger} & \meter & \rstick{\hspace{-0.5cm}\ket{x}\bra{x}=m_2}\\ 4 | \lstick{q_2:~\ket{0}_P~} & \qw & \ctrl{0} &\qw & \qw &\qw &\rstick{\hspace{-0.5cm}X(m_2)FPX(m_1)F\ket{\psi}} 5 | } 6 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/gaussian_boson_sampling.tex: -------------------------------------------------------------------------------- 1 | \begin{picture}(100,100) 2 | \put(0,0){ 3 | \Qcircuit @C=1.5em @R=1em { 4 | \lstick{q_0:~\ket{0}} & \gate{S} & \gate{R(\phi_1)} & \multigate{1}{BS} & \qw & \multigate{1}{BS} &\qw& \multigate{1}{BS} &\measureD{\hat{n}}\\ 5 | \lstick{q_1:~\ket{0}} &\gate{S} & \gate{R(\phi_2)} & \ghost{BS} & \multigate{1}{BS}& \ghost{BS} & \multigate{1}{BS} & \ghost{BS}&\measureD{\hat{n}}\\ 6 | \lstick{q_2:~\ket{0}} & \gate{S} & \gate{R(\phi_3)} & \multigate{1}{BS} & \ghost{BS} & \multigate{1}{BS} & \ghost{BS}& \multigate{1}{BS}&\measureD{\hat{n}}\\ 7 | \lstick{q_3:~\ket{0}} & \gate{S} & \gate{R(\phi_4)} & \ghost{BS} & \qw & \ghost{BS} & \qw & \ghost{BS}&\measureD{\hat{n}} 8 | } 9 | } 10 | %\put(81,-20){\footnotesize$\hat{x}$} 11 | %\put(81,-41){\footnotesize$\hat{p}$} 12 | \end{picture} -------------------------------------------------------------------------------- /doc/_static/qcircuit/hamiltonian.tex: -------------------------------------------------------------------------------- 1 | \begin{picture}(100,100) 2 | \Qcircuit @C=1em @R=1em { 3 | \lstick{q_0:~\ket{2}} & \multigate{1}{BS} & \gate{K} & \gate{R} & \multigate{1}{BS} & \gate{K} & \gate{R} & \qw \\ 4 | \lstick{q_1:~\ket{0}} & \ghost{BS} & \gate{K} & \gate{R} & \ghost{BS} & \gate{K} & \gate{R} & \qw 5 | } 6 | \end{picture} -------------------------------------------------------------------------------- /doc/_static/qcircuit/iqp_circuit.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1em @R=.7em { 2 | \lstick{\ket{0}} & \gate{S} & \ctrl{1} & \gate{Z} & \qw & \ctrl{2} & \gate{V} & \meter&\rstick{\hat{p}}\push{\rule{5em}{0em}} \\ 3 | \lstick{\ket{0}} & \gate{S} & \ctrl{0} & \qw & \ctrl{1} & \qw & \gate{V} & \meter &\rstick{\hat{p}}\push{\rule{5em}{0em}}\\ 4 | \lstick{\ket{0}} & \gate{S} & \gate{V} & \gate{Z} & \ctrl{0} & \ctrl{0} &\gate{Z} & \meter&\rstick{\hat{p}}\push{\rule{5em}{0em}} \\ 5 | \lstick{\ket{0}} & \gate{S} & \gate{Z} & \qw & \gate{Z} & \gate{Z} & \qw & \meter &\rstick{\hat{p}}\push{\rule{5em}{0em}} 6 | } 7 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/main.tex: -------------------------------------------------------------------------------- 1 | \documentclass[amsmath,amssymb,aps,pra,10pt,twocolumn,groupedaddress]{revtex4-1} 2 | 3 | \usepackage{graphicx, epsf} 4 | \usepackage[T1]{fontenc} % fix quotation marks in code blocks 5 | \usepackage{caption} % allows some extra formatting for captions 6 | \usepackage[bitstream-charter]{mathdesign} 7 | \graphicspath{{figures/}} 8 | \usepackage{tikz} 9 | \input{Qcircuit} 10 | 11 | \usepackage{calrsfs} 12 | \DeclareMathAlphabet{\pazocal}{OMS}{zplm}{m}{n} 13 | \let\mathcal\undefined 14 | \newcommand{\mathcal}[1]{\pazocal{#1}} 15 | \usepackage{import} 16 | 17 | \let\bm\undefined 18 | \newcommand{\bm}[1]{\mathbf{#1}} 19 | 20 | \newcommand{\Rgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{R} & \qw}} 21 | \newcommand{\Dgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{D} & \qw}} 22 | \newcommand{\Sgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{S} & \qw}} 23 | \newcommand{\BSgate}{\Qcircuit @C=0.5em @R=.7em { 24 | & \multigate{1}{BS} & \qw \\ 25 | & \ghost{BS}& \qw 26 | }} 27 | \newcommand{\Vgate}{\Qcircuit @C=0.5em @R=.7em {& \gate{V} & \qw}} 28 | \renewcommand{\Qcircuit}[1][0em]{\xymatrix @*=<#1>} 29 | 30 | \begin{document} 31 | \pagestyle{empty} 32 | 33 | \begin{figure} 34 | \mbox{\import{.}{cloning}} 35 | \end{figure} 36 | 37 | \end{document} 38 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/measurements.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=2em { 2 | \lstick{q_0:\ket{0}} & \multigate{1}{S} & \meter\\ 3 | \lstick{q_1:\ket{0}} & \ghost{S} & \qw 4 | } 5 | -------------------------------------------------------------------------------- /doc/_static/qcircuit/teleportation.tex: -------------------------------------------------------------------------------- 1 | \Qcircuit @C=1.5em @R=1em { 2 | \lstick{q_0:~\ket{\psi}~} & \qw & \multigate{1}{BS} & \meter & \control\cw\cwx[2] & \rstick{\hspace{-0.8cm}\ket{x}\bra{x}=m_1}\\ 3 | \lstick{q_1:~\ket{0}_p} & \multigate{1}{BS} & \ghost{BS} & \meter & \cw& \control\cw\cwx[1] & \rstick{\hspace{-0.6cm}\ket{p}\bra{p}=m_2}\\ 4 | \lstick{q_2:~\ket{0}_x} & \ghost{BS} & \qw & \qw & \gate{X} & \gate{Z} & \qw &\rstick{\hspace{-0.5cm}\ket{\psi}} 5 | } 6 | -------------------------------------------------------------------------------- /doc/_static/readme_panel1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/readme_panel1.png -------------------------------------------------------------------------------- /doc/_static/reck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/reck.png -------------------------------------------------------------------------------- /doc/_static/sf_wordmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/sf_wordmark.png -------------------------------------------------------------------------------- /doc/_static/similarity_svm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/similarity_svm.png -------------------------------------------------------------------------------- /doc/_static/strawberry-fields-text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/strawberry-fields-text.png -------------------------------------------------------------------------------- /doc/_static/strawberry_fields.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/strawberry_fields.png -------------------------------------------------------------------------------- /doc/_static/teleport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/teleport.png -------------------------------------------------------------------------------- /doc/_static/thumbs/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/thumbs/code.png -------------------------------------------------------------------------------- /doc/_static/thumbs/photon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/thumbs/photon.png -------------------------------------------------------------------------------- /doc/_static/thumbs/spectrum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/thumbs/spectrum.png -------------------------------------------------------------------------------- /doc/_static/water.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/water.png -------------------------------------------------------------------------------- /doc/_static/x_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/doc/_static/x_p.png -------------------------------------------------------------------------------- /doc/_templates/autosummary/base.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | replace("strawberryfields", "sf") | escape | underline}} 2 | 3 | .. currentmodule:: {{ module }} 4 | 5 | .. auto{{ objtype }}:: {{ objname }} 6 | -------------------------------------------------------------------------------- /doc/_templates/autosummary/class.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | replace("strawberryfields", "sf") }} 2 | {{ underline }} 3 | 4 | .. autoclass:: {{ fullname }} 5 | :show-inheritance: 6 | 7 | {% if '__init__' in methods %} 8 | {% set caught_result = methods.remove('__init__') %} 9 | {% endif %} 10 | 11 | {% block attributes_documentation %} 12 | {% if attributes %} 13 | 14 | .. raw:: html 15 | 16 | 21 |
22 | 23 | {% block attributes_summary %} 24 | {% if attributes %} 25 | 26 | .. autosummary:: 27 | :nosignatures: 28 | {% for item in attributes %} 29 | ~{{ name }}.{{ item }} 30 | {%- endfor %} 31 | 32 | {% endif %} 33 | {% endblock %} 34 | 35 | {% for item in attributes %} 36 | .. autoattribute:: {{ item }} 37 | {%- endfor %} 38 | 39 | .. raw:: html 40 | 41 |
42 | 43 | {% endif %} 44 | {% endblock %} 45 | 46 | {% block methods_documentation %} 47 | {% if methods %} 48 | 49 | .. raw:: html 50 | 51 | 56 |
57 | 58 | {% block methods_summary %} 59 | {% if methods %} 60 | 61 | .. autosummary:: 62 | {% for item in methods %} 63 | ~{{ name }}.{{ item }} 64 | {%- endfor %} 65 | 66 | {% endif %} 67 | {% endblock %} 68 | 69 | {% for item in methods %} 70 | .. automethod:: {{ item }} 71 | {%- endfor %} 72 | 73 | .. raw:: html 74 | 75 |
76 | 77 | {% endif %} 78 | {% endblock %} 79 | 80 | .. raw:: html 81 | 82 | 87 | -------------------------------------------------------------------------------- /doc/_templates/autosummary/module.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | replace("strawberryfields", "sf") | escape | underline}} 2 | 3 | .. automodule:: {{ fullname }} 4 | 5 | {% block classes %} 6 | {% if classes %} 7 | .. rubric:: Classes 8 | 9 | .. autosummary:: 10 | :toctree: 11 | 12 | {% for item in classes %} 13 | {{ item }} 14 | {%- endfor %} 15 | {% endif %} 16 | {% endblock %} 17 | 18 | {% block functions %} 19 | {% if functions %} 20 | .. rubric:: Functions 21 | 22 | .. autosummary:: 23 | :toctree: 24 | 25 | {% for item in functions %} 26 | {{ item }} 27 | {%- endfor %} 28 | {% endif %} 29 | {% endblock %} 30 | 31 | {% block exceptions %} 32 | {% if exceptions %} 33 | .. rubric:: Exceptions 34 | 35 | .. autosummary:: 36 | {% for item in exceptions %} 37 | {{ item }} 38 | {%- endfor %} 39 | {% endif %} 40 | {% endblock %} 41 | -------------------------------------------------------------------------------- /doc/_templates/autosummary_core/base.rst: -------------------------------------------------------------------------------- 1 | {% if referencefile %} 2 | .. include:: {{ referencefile }} 3 | {% endif %} 4 | 5 | {% if module.split(".")[1:] | length >= 1 %} 6 | {% set mod = module.split(".")[1:] | join(".") %} 7 | {% set mod = "sf." + mod %} 8 | {% else %} 9 | {% set mod = "sf" %} 10 | {% endif %} 11 | 12 | {{ mod }}.{{ objname }} 13 | ={% for i in range(mod|length) %}={% endfor %}{{ underline }} 14 | 15 | .. currentmodule:: {{ module }} 16 | 17 | .. auto{{ objtype }}:: {{ objname }} 18 | -------------------------------------------------------------------------------- /doc/_templates/autosummary_core/class.rst: -------------------------------------------------------------------------------- 1 | {% if referencefile %} 2 | .. include:: {{ referencefile }} 3 | {% endif %} 4 | 5 | {% if module.split(".")[1:] | length >= 1 %} 6 | {% set mod = module.split(".")[1:] | join(".") %} 7 | {% set mod = "sf." + mod %} 8 | {% else %} 9 | {% set mod = "sf" %} 10 | {% endif %} 11 | 12 | {{ mod }}.{{ objname }} 13 | ={% for i in range(mod|length) %}={% endfor %}{{ underline }} 14 | 15 | .. currentmodule:: {{ module }} 16 | 17 | .. autoclass:: {{ objname }} 18 | :show-inheritance: 19 | 20 | {% if '__init__' in methods %} 21 | {% set caught_result = methods.remove('__init__') %} 22 | {% endif %} 23 | 24 | {% block attributes_documentation %} 25 | {% if attributes %} 26 | 27 | .. raw:: html 28 | 29 | 34 |
35 | 36 | {% block attributes_summary %} 37 | {% if attributes %} 38 | 39 | .. autosummary:: 40 | :nosignatures: 41 | {% for item in attributes %} 42 | ~{{ name }}.{{ item }} 43 | {%- endfor %} 44 | 45 | {% endif %} 46 | {% endblock %} 47 | 48 | {% for item in attributes %} 49 | .. autoattribute:: {{ item }} 50 | {%- endfor %} 51 | 52 | .. raw:: html 53 | 54 |
55 | 56 | {% endif %} 57 | {% endblock %} 58 | 59 | {% block methods_documentation %} 60 | {% if methods %} 61 | 62 | .. raw:: html 63 | 64 | 69 |
70 | 71 | {% block methods_summary %} 72 | {% if methods %} 73 | 74 | .. autosummary:: 75 | {% for item in methods %} 76 | ~{{ name }}.{{ item }} 77 | {%- endfor %} 78 | 79 | {% endif %} 80 | {% endblock %} 81 | 82 | {% for item in methods %} 83 | .. automethod:: {{ item }} 84 | {%- endfor %} 85 | 86 | .. raw:: html 87 | 88 |
89 | 90 | {% endif %} 91 | {% endblock %} 92 | 93 | .. raw:: html 94 | 95 | 100 | -------------------------------------------------------------------------------- /doc/_templates/autosummary_core/module.rst: -------------------------------------------------------------------------------- 1 | {% if referencefile %} 2 | .. include:: {{ referencefile }} 3 | {% endif %} 4 | 5 | {% if module.split(".")[1:] | length >= 1 %} 6 | {% set mod = module.split(".")[1:] | join(".") %} 7 | {% set mod = "sf." + mod %} 8 | {% else %} 9 | {% set mod = "sf" %} 10 | {% endif %} 11 | 12 | {{ mod }}.{{ objname }} 13 | ={% for i in range(mod|length) %}={% endfor %}{{ underline }} 14 | 15 | .. automodule:: {{ fullname }} 16 | 17 | {% block functions %} 18 | {% if functions %} 19 | .. rubric:: Functions 20 | 21 | .. autosummary:: 22 | {% for item in functions %} 23 | {{ item }} 24 | {%- endfor %} 25 | {% endif %} 26 | {% endblock %} 27 | 28 | {% block classes %} 29 | {% if classes %} 30 | .. rubric:: Classes 31 | 32 | .. autosummary:: 33 | {% for item in classes %} 34 | {{ item }} 35 | {%- endfor %} 36 | {% endif %} 37 | {% endblock %} 38 | 39 | {% block exceptions %} 40 | {% if exceptions %} 41 | .. rubric:: Exceptions 42 | 43 | .. autosummary:: 44 | {% for item in exceptions %} 45 | {{ item }} 46 | {%- endfor %} 47 | {% endif %} 48 | {% endblock %} 49 | -------------------------------------------------------------------------------- /doc/code/sf.rst: -------------------------------------------------------------------------------- 1 | sf 2 | == 3 | 4 | .. currentmodule:: strawberryfields 5 | 6 | .. automodapi:: strawberryfields 7 | :no-heading: 8 | :include-all-objects: 9 | :no-inheritance-diagram: 10 | -------------------------------------------------------------------------------- /doc/code/sf_apps.rst: -------------------------------------------------------------------------------- 1 | sf.apps 2 | ======= 3 | 4 | .. currentmodule:: strawberryfields.apps 5 | 6 | .. automodule:: strawberryfields.apps 7 | -------------------------------------------------------------------------------- /doc/code/sf_backends.rst: -------------------------------------------------------------------------------- 1 | sf.backends 2 | =========== 3 | 4 | .. currentmodule:: strawberryfields.backends 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | See the :class:`.Engine` class for 12 | details on loading a particular backend for quantum program 13 | execution. 14 | 15 | .. automodule:: strawberryfields.backends 16 | -------------------------------------------------------------------------------- /doc/code/sf_circuitdrawer.rst: -------------------------------------------------------------------------------- 1 | sf.circuitdrawer 2 | ================ 3 | 4 | .. currentmodule:: strawberryfields.circuitdrawer 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | See the :class:`.Program.draw_circuit` method for 12 | details on converting a Strawberry Fields program to :math:`\LaTeX{}`. 13 | 14 | .. automodapi:: strawberryfields.circuitdrawer 15 | :no-heading: 16 | :no-inheritance-diagram: 17 | -------------------------------------------------------------------------------- /doc/code/sf_compilers.rst: -------------------------------------------------------------------------------- 1 | sf.compilers 2 | ============ 3 | 4 | .. currentmodule:: strawberryfields.compilers 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | .. automodapi:: strawberryfields.compilers 12 | :no-heading: 13 | :include-all-objects: 14 | -------------------------------------------------------------------------------- /doc/code/sf_decompositions.rst: -------------------------------------------------------------------------------- 1 | sf.decompositions 2 | ================= 3 | 4 | .. currentmodule:: strawberryfields.decompositions 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these functions directly. 10 | 11 | See the :ref:`decomposition ` operations for 12 | details on embedding states, graphs, and unitaries within a photonic 13 | quantum circuit. 14 | 15 | .. automodapi:: strawberryfields.decompositions 16 | :no-heading: 17 | :include-all-objects: 18 | :skip: block_diag, sqrtm, polar, schur, sympmat, xpxp_to_xxpp, adj_scaling 19 | -------------------------------------------------------------------------------- /doc/code/sf_engine.rst: -------------------------------------------------------------------------------- 1 | sf.engine 2 | ========= 3 | 4 | .. currentmodule:: strawberryfields.engine 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | See the :class:`.Engine` class for 12 | details on creating a Strawberry Fields engine. 13 | 14 | .. automodapi:: strawberryfields.engine 15 | :no-heading: 16 | :include-all-objects: 17 | -------------------------------------------------------------------------------- /doc/code/sf_io.rst: -------------------------------------------------------------------------------- 1 | sf.io 2 | ===== 3 | 4 | .. currentmodule:: strawberryfields.io 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these functions directly. 10 | 11 | See the :func:`.save` and :func:`.load` functions for saving/loading Strawberry Fields 12 | quantum programs. 13 | 14 | .. automodapi:: strawberryfields.io 15 | :no-heading: 16 | :include-all-objects: 17 | -------------------------------------------------------------------------------- /doc/code/sf_ops.rst: -------------------------------------------------------------------------------- 1 | .. _gates: 2 | 3 | sf.ops 4 | ====== 5 | 6 | .. currentmodule:: strawberryfields.ops 7 | 8 | .. automodapi:: strawberryfields.ops 9 | :no-heading: 10 | :include-all-objects: 11 | -------------------------------------------------------------------------------- /doc/code/sf_parameters.rst: -------------------------------------------------------------------------------- 1 | sf.parameters 2 | ============= 3 | 4 | .. currentmodule:: strawberryfields.parameters 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | .. automodapi:: strawberryfields.parameters 12 | :no-heading: 13 | :include-all-objects: 14 | :no-inherited-members: 15 | -------------------------------------------------------------------------------- /doc/code/sf_plot.rst: -------------------------------------------------------------------------------- 1 | sf.plot 2 | ======= 3 | 4 | .. currentmodule:: strawberryfields.plot 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | .. automodapi:: strawberryfields.plot 12 | :no-heading: 13 | :skip: copy, deepcopy 14 | -------------------------------------------------------------------------------- /doc/code/sf_program.rst: -------------------------------------------------------------------------------- 1 | sf.program 2 | ========== 3 | 4 | .. currentmodule:: strawberryfields.program 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | See the :class:`.Program` class for 12 | details on Strawberry Fields programs. 13 | 14 | 15 | .. automodapi:: strawberryfields.program 16 | :no-heading: 17 | :include-all-objects: 18 | -------------------------------------------------------------------------------- /doc/code/sf_program_utils.rst: -------------------------------------------------------------------------------- 1 | sf.program_utils 2 | ================ 3 | 4 | .. currentmodule:: strawberryfields.program_utils 5 | 6 | .. warning:: 7 | 8 | Unless you are a Strawberry Fields developer, you likely do not need 9 | to use these classes directly. 10 | 11 | See the general :class:`~.Program` class for 12 | details on creating a Strawberry Fields program. 13 | 14 | .. automodapi:: strawberryfields.program_utils 15 | :no-heading: 16 | :include-all-objects: 17 | :no-inheritance-diagram: 18 | -------------------------------------------------------------------------------- /doc/code/sf_tdm.rst: -------------------------------------------------------------------------------- 1 | sf.tdm 2 | ====== 3 | 4 | .. currentmodule:: strawberryfields.tdm 5 | 6 | .. automodapi:: strawberryfields.tdm 7 | :no-heading: 8 | :include-all-objects: 9 | :skip: TDMProgram 10 | -------------------------------------------------------------------------------- /doc/code/sf_utils.rst: -------------------------------------------------------------------------------- 1 | sf.utils 2 | ======== 3 | 4 | .. currentmodule:: strawberryfields.utils 5 | 6 | .. automodapi:: strawberryfields.utils 7 | :no-heading: 8 | :include-all-objects: 9 | :no-inheritance-diagram: 10 | -------------------------------------------------------------------------------- /doc/development/example_module_autosummary.txt: -------------------------------------------------------------------------------- 1 | .. currentmodule:: strawberryfields.package_name 2 | .. autosummary:: 3 | :toctree: api 4 | 5 | module1 6 | module2 7 | -------------------------------------------------------------------------------- /doc/development/example_module_rst.txt: -------------------------------------------------------------------------------- 1 | sf.module_name 2 | ============== 3 | 4 | .. currentmodule:: strawberryfields.module_name 5 | 6 | .. automodapi:: strawberryfields.module_name 7 | :no-heading: 8 | :include-all-objects: 9 | :skip: 10 | -------------------------------------------------------------------------------- /doc/development/example_package_rst.txt: -------------------------------------------------------------------------------- 1 | sf.package_name 2 | =============== 3 | 4 | .. rubric:: Modules 5 | 6 | .. automodule:: strawberryfields.package_name 7 | -------------------------------------------------------------------------------- /doc/development/release_notes.md: -------------------------------------------------------------------------------- 1 | Release notes 2 | ------------- 3 | 4 | This page contains the release notes for Strawberry Fields. 5 | 6 | .. mdinclude:: ../../.github/CHANGELOG.md 7 | -------------------------------------------------------------------------------- /doc/introduction/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | .. image:: /_static/NOON.png 5 | :align: right 6 | :width: 250px 7 | :target: javascript:void(0); 8 | 9 | 10 | Strawberry Fields is an open-source framework for photonic quantum computing. 11 | In particular, Strawberry Fields allows for the following workflows: 12 | 13 | * Construct and simulate continuous-variable quantum photonic circuits. 14 | Provided simulators include highly optimized Gaussian, Fock, and Bosonic 15 | numeric backends, as well as a TensorFlow backend for backpropagation. 16 | 17 | * Compile and submit photonic circuits for remote execution on Xanadu's quantum hardware, 18 | retrieve your results, and manage multiple jobs. 19 | 20 | * Use our high-level functions for graph and network optimization, machine learning, and 21 | chemistry applications --- all executable on near-term hardware. 22 | 23 | Get started 24 | ----------- 25 | 26 | Follow the `installation <../_static/install.html>`_ page to get Strawberry Fields up and 27 | running, then have a look at our quickstart guides, or jump over to the 28 | :doc:`tutorials ` to see what you can do with Strawberry Fields. 29 | 30 | Users interested in applications of photonic quantum computers should check 31 | out the :doc:`applications` pages. Those wanting to dig deeper into the design 32 | of circuits can head to the :doc:`/introduction/circuits` page. 33 | 34 | Developers can head to the :doc:`/development/development_guide` to see how 35 | they can contribute to Strawberry Fields. 36 | 37 | Quickstart guides 38 | ----------------- 39 | 40 | In the following sections you can learn more about the key features of Strawberry Fields: 41 | 42 | .. image:: ../_static/code.png 43 | :align: right 44 | :width: 300px 45 | :target: javascript:void(0); 46 | 47 | 1. :doc:`circuits` shows how to construct and simulate photonic circuits in Strawberry Fields, 48 | including applying quantum gates, performing measurements, and how to use our various 49 | simulator backends. 50 | 51 | .. 52 | 53 | 2. :doc:`ops` outlines the various quantum photonic circuit building blocks 54 | provided in Strawberry Fields --- including gates, state preparations and measurements. 55 | 56 | .. 57 | 58 | 4. :doc:`states` outlines the various statevector methods and attributes accessible 59 | when using the built-in simulators. These provide useful information and processing 60 | of the quantum state of the system. 61 | 62 | .. 63 | 64 | 5. :doc:`photonic_hardware` gives an overview of building, submitting, and managing 65 | remote jobs on both hardware and cloud simulators through Strawberry Fields. 66 | 67 | .. 68 | 69 | 6. :doc:`data` details the built-in datasets of pre-generated photonic samples provided 70 | by Strawberry Fields, for various graphs used in optimization, machine learning, and chemistry 71 | applications. 72 | -------------------------------------------------------------------------------- /doc/introduction/ops.rst: -------------------------------------------------------------------------------- 1 | .. role:: html(raw) 2 | :format: html 3 | 4 | Operations 5 | ========== 6 | 7 | Strawberry Fields supports a wide variety of photonic quantum operations --- including gates, 8 | state preparations and measurements. These operations are used to construct quantum programs, 9 | as in the following example: 10 | 11 | .. code-block:: python3 12 | 13 | with prog.context as q: 14 | Fock(2) | q[0] 15 | Fock(3) | q[1] 16 | BSgate() | (q[0], q[1]) 17 | MeasureFock() | q[0] 18 | 19 | This program uses Fock state preparation (:class:`~.ops.Fock`), beamsplitters (:class:`~.BSgate`), 20 | and a photon number resolving detector (:class:`~.MeasureFock`). 21 | 22 | Below is a list of all quantum operations supported by Strawberry Fields. 23 | 24 | .. note:: 25 | 26 | In the Strawberry Fields we use the convention :math:`\hbar=2` by default, however 27 | this can be changed using the global variable :py:data:`sf.hbar`. 28 | 29 | See :ref:`conventions` for more details. 30 | 31 | .. currentmodule:: strawberryfields.ops 32 | 33 | Single-mode gates 34 | ----------------- 35 | 36 | :html:`
` 37 | 38 | .. autosummary:: 39 | Dgate 40 | Xgate 41 | Zgate 42 | Sgate 43 | Rgate 44 | Pgate 45 | Vgate 46 | Fouriergate 47 | 48 | :html:`
` 49 | 50 | Two-mode gates 51 | -------------- 52 | 53 | :html:`
` 54 | 55 | .. autosummary:: 56 | BSgate 57 | MZgate 58 | S2gate 59 | CXgate 60 | CZgate 61 | CKgate 62 | 63 | :html:`
` 64 | 65 | State preparation 66 | ----------------- 67 | 68 | :html:`
` 69 | 70 | .. autosummary:: 71 | Vacuum 72 | Coherent 73 | Squeezed 74 | DisplacedSqueezed 75 | Thermal 76 | Fock 77 | Catstate 78 | GKP 79 | Ket 80 | DensityMatrix 81 | Gaussian 82 | 83 | :html:`
` 84 | 85 | Measurements 86 | ------------ 87 | 88 | :html:`
` 89 | 90 | .. autosummary:: 91 | MeasureFock 92 | MeasureThreshold 93 | MeasureHomodyne 94 | MeasureHeterodyne 95 | MeasureX 96 | MeasureP 97 | MeasureHD 98 | 99 | :html:`
` 100 | 101 | .. seealso:: 102 | 103 | See the :doc:`measurements and post-selection tutorial ` 104 | for more details on applying measurements, post-selection, and classical processing. 105 | 106 | 107 | Channels 108 | -------- 109 | 110 | :html:`
` 111 | 112 | .. autosummary:: 113 | LossChannel 114 | ThermalLossChannel 115 | MSgate 116 | PassiveChannel 117 | 118 | :html:`
` 119 | 120 | .. _decompositions: 121 | 122 | Decompositions 123 | -------------- 124 | 125 | :html:`
` 126 | 127 | .. autosummary:: 128 | Interferometer 129 | GraphEmbed 130 | BipartiteGraphEmbed 131 | GaussianTransform 132 | Gaussian 133 | 134 | :html:`
` 135 | 136 | 137 | -------------------------------------------------------------------------------- /doc/introduction/states.rst: -------------------------------------------------------------------------------- 1 | .. role:: html(raw) 2 | :format: html 3 | 4 | States 5 | ====== 6 | 7 | In Strawberry Fields, the statevector simulator backends return ``state`` objects, 8 | which provide useful information and processing of the quantum state of 9 | the system. For example, consider the following program: 10 | 11 | .. code-block:: python3 12 | 13 | prog = sf.Program(3) 14 | 15 | with prog.context as q: 16 | ops.Sgate(0.54) | q[0] 17 | ops.Sgate(0.54) | q[1] 18 | ops.Sgate(0.54) | q[2] 19 | ops.BSgate(0.43, 0.1) | (q[0], q[2]) 20 | ops.BSgate(0.43, 0.1) | (q[1], q[2]) 21 | 22 | eng = sf.Engine("fock", backend_options={"cutoff_dim": 10}) 23 | result = eng.run(prog) 24 | state = result.state 25 | 26 | By executing this program on a local simulator backend, we can use the state 27 | object to determine the trace, return the density matrix, and calculate particular 28 | Fock basis state probabilities: 29 | 30 | >>> state.trace() 31 | 0.9989783190545866 32 | >>> rho = state.dm() 33 | >>> state.fock_prob([0, 0, 2]) 34 | 0.07933909728557098 35 | 36 | These methods may differ depending on the backend, but there 37 | are a few that are implemented for all backends. 38 | 39 | Common methods and attributes 40 | ----------------------------- 41 | 42 | .. currentmodule:: strawberryfields.backends.BaseState 43 | 44 | :html:`
` 45 | 46 | .. autosummary:: 47 | data 48 | hbar 49 | is_pure 50 | num_modes 51 | mode_names 52 | mode_indices 53 | ket 54 | dm 55 | reduced_dm 56 | fock_prob 57 | all_fock_probs 58 | mean_photon 59 | fidelity 60 | fidelity_vacuum 61 | fidelity_coherent 62 | wigner 63 | quad_expectation 64 | poly_quad_expectation 65 | number_expectation 66 | parity_expectation 67 | p_quad_values 68 | x_quad_values 69 | 70 | :html:`
` 71 | 72 | 73 | Gaussian states 74 | --------------- 75 | 76 | Backend that represent the quantum state using the Gaussian formalism 77 | (such as the ``gaussian`` backend) will return a ``GaussianState`` object, 78 | with the following methods and attributes. 79 | 80 | .. currentmodule:: strawberryfields.backends.BaseGaussianState 81 | 82 | :html:`
` 83 | 84 | .. autosummary:: 85 | means 86 | cov 87 | reduced_gaussian 88 | is_coherent 89 | is_squeezed 90 | displacement 91 | squeezing 92 | 93 | :html:`
` 94 | 95 | 96 | Fock states 97 | ----------- 98 | 99 | Backend that represent the quantum state in the Fock basis 100 | (such as the ``fock`` or ``tf`` backends) will return a ``FockState`` 101 | object. 102 | 103 | .. currentmodule:: strawberryfields.backends.BaseFockState 104 | 105 | :html:`
` 106 | 107 | .. autosummary:: 108 | cutoff_dim 109 | trace 110 | 111 | :html:`
` 112 | -------------------------------------------------------------------------------- /doc/macros.tex: -------------------------------------------------------------------------------- 1 | % % LaTeX macros for the Sphinx docs. 2 | % Deprecated (see xanadu_theme/layout.html instead), 3 | % but sphinx complains if the file is not found 4 | % 5 | % 6 | % \usepackage{bbm} 7 | % 8 | % \newcommand{\pr}[1]{| #1 \rangle \langle #1|} 9 | % \newcommand{\ket}[1]{| #1 \rangle} % generic ket, also Fock state 10 | % \newcommand{\bra}[1]{\langle #1 |} % generic bra, also Fock costate 11 | % \newcommand{\xket}[1]{| #1 \rangle_x} % position eigenket 12 | % \newcommand{\xbra}[1]{\langle #1 |_x} % position eigenbra 13 | % \newcommand{\braket}[1]{\langle #1 \rangle} 14 | % \newcommand{\ketbra}[2]{| #1 \rangle\langle #2 |} 15 | % \newcommand{\hc}{\text{h.c.}} % hermitian conjugate 16 | % \newcommand{\cc}{\text{c.c.}} % complex conjugate 17 | % \newcommand{\h}{\hat} 18 | % \newcommand{\nn}{\nonumber} 19 | % \newcommand{\di}[1]{\frac{d}{d #1}} 20 | % \newcommand{\uu}{\mathcal{U}} 21 | % \newcommand{\inn}{\text{in}} 22 | % \newcommand{\out}{\text{out}} 23 | % \newcommand{\vac}{\text{vac}} 24 | % \newcommand{\nbar}{\overline{n}} 25 | % \newcommand{\x}{\hat{x}} 26 | % \newcommand{\p}{\hat{p}} 27 | % \newcommand{\a}{\hat{a}} 28 | % \newcommand{\ad}{\a^\dagger} 29 | % \newcommand{\b}{\hat{b}} 30 | % \newcommand{\I}{\mathbbm{1}} % vector/Hilbert space identity operator 31 | % \newcommand{\sech}{\mathrm{sech~}} 32 | % 33 | % \DeclareMathOperator{\re}{Re} % real part 34 | % \DeclareMathOperator{\im}{Im} % imaginary part 35 | % \DeclareMathOperator{\sign}{sign} % sign function 36 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | docutils==0.16 2 | black==19.10b0 3 | ipykernel==6.7.0 4 | jinja2==3.0.3 5 | sphinx==2.2.2 6 | m2r2==0.3.1 7 | mistune==0.8.4 8 | numba==0.56.4 9 | networkx==2.6.3 10 | numpy==1.19.2 11 | plotly==4.4.1 12 | protobuf<4.21.0 # remove when fix is released 13 | quantum-blackbird==0.4.0 14 | quantum-xir>=0.1.1 15 | scipy==1.7.1 16 | scikit-learn==1.0.2 17 | sphinx-autodoc-typehints==1.10.3 18 | sphinx-copybutton==0.4.0 19 | sphinx-automodapi==0.13 20 | sphinxcontrib-bibtex==0.4.2 21 | tensorflow==2.6.3 22 | thewalrus==0.19.0 23 | toml==0.10.2 24 | xanadu-sphinx-theme==0.1.0 25 | xanadu-cloud-client>=0.2.1 26 | -------------------------------------------------------------------------------- /doc/zreferences.rst: -------------------------------------------------------------------------------- 1 | .. _references: 2 | 3 | References 4 | ========== 5 | 6 | For more details and further information on continuous-variable quantum computation and Gaussian quantum information, please see :cite:`FR-weedbrook2012,FR-adesso2014,FR-serafini2017,FR-ferraro2005`. 7 | 8 | 9 | .. bibliography:: references.bib 10 | :cited: 11 | :style: unsrt 12 | -------------------------------------------------------------------------------- /examples/IQP.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import * 4 | 5 | # initialize engine and program objects 6 | eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 5}) 7 | iqp_circuit = sf.Program(4) 8 | 9 | with iqp_circuit.context as q: 10 | # prepare the input squeezed states 11 | S = Sgate(-1) 12 | S | q[0] 13 | S | q[1] 14 | S | q[2] 15 | S | q[3] 16 | 17 | # gates diagonal in the x quadrature 18 | CZgate(0.5719) | (q[0], q[1]) 19 | Vgate(-1.9782) | q[2] 20 | Zgate(2.0603) | q[3] 21 | Zgate(-0.7804) | q[0] 22 | Zgate(0.8578) | q[2] 23 | CZgate(1.321) | (q[1], q[2]) 24 | Zgate(0.473) | q[3] 25 | CZgate(0.9946) | (q[0], q[3]) 26 | Zgate(0.1223) | q[3] 27 | Vgate(0.6157) | q[0] 28 | Vgate(0.3110) | q[1] 29 | Zgate(-1.243) | q[2] 30 | # end circuit 31 | 32 | # run the engine 33 | results = eng.run(iqp_circuit) 34 | -------------------------------------------------------------------------------- /examples/boson_sampling.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import * 4 | 5 | # initialize engine and program objects 6 | eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 7}) 7 | boson_sampling = sf.Program(4) 8 | 9 | with boson_sampling.context as q: 10 | # prepare the input fock states 11 | Fock(1) | q[0] 12 | Fock(1) | q[1] 13 | Vac | q[2] 14 | Fock(1) | q[3] 15 | 16 | # rotation gates 17 | Rgate(0.5719) | q[0] 18 | Rgate(-1.9782) | q[1] 19 | Rgate(2.0603) | q[2] 20 | Rgate(0.0644) | q[3] 21 | 22 | # beamsplitter array 23 | BSgate(0.7804, 0.8578) | (q[0], q[1]) 24 | BSgate(0.06406, 0.5165) | (q[2], q[3]) 25 | BSgate(0.473, 0.1176) | (q[1], q[2]) 26 | BSgate(0.563, 0.1517) | (q[0], q[1]) 27 | BSgate(0.1323, 0.9946) | (q[2], q[3]) 28 | BSgate(0.311, 0.3231) | (q[1], q[2]) 29 | BSgate(0.4348, 0.0798) | (q[0], q[1]) 30 | BSgate(0.4368, 0.6157) | (q[2], q[3]) 31 | # end circuit 32 | 33 | # run the engine 34 | results = eng.run(boson_sampling) 35 | 36 | # extract the joint Fock probabilities 37 | probs = results.state.all_fock_probs() 38 | 39 | # print the joint Fock state probabilities 40 | print(probs[1, 1, 0, 1]) 41 | print(probs[2, 0, 0, 1]) 42 | -------------------------------------------------------------------------------- /examples/custom_operation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. 13 | import strawberryfields as sf 14 | from strawberryfields.ops import * 15 | from strawberryfields.utils import operation 16 | 17 | 18 | @operation(4) 19 | def prepare_squeezing(q): 20 | """This operation prepares modes 0 and 1 21 | as squeezed states with r = -1. 22 | 23 | Args: 24 | q (register): the qumode register. 25 | """ 26 | S = Sgate(-1) 27 | S | q[0] 28 | S | q[1] 29 | 30 | 31 | @operation(3) 32 | def circuit_op(v1, v2, q): 33 | """Some gates that are groups into a custom operation. 34 | 35 | Args: 36 | v1 (float): parameter for CZgate 37 | v2 (float): parameter for the cubic phase gate 38 | q (register): the qumode register 39 | """ 40 | CZgate(v1) | (q[0], q[1]) 41 | Vgate(v2) | q[1] 42 | 43 | 44 | # initialize engine and program objects 45 | eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 5}) 46 | circuit = sf.Program(4) 47 | 48 | with circuit.context as q: 49 | # The following operation takes no arguments 50 | prepare_squeezing() | q 51 | 52 | # another operation with 2 parameters that operates on three registers: 0, 1 53 | circuit_op(0.5719, 2.0603) | (q[0], q[1], q[3]) 54 | 55 | # run the engine 56 | results = eng.run(circuit) 57 | -------------------------------------------------------------------------------- /examples/example_job_X8.xbb: -------------------------------------------------------------------------------- 1 | name example_job_X8 2 | version 1.0 3 | target X8_01 (shots = 20) 4 | 5 | complex array U[4, 4] = 6 | -0.13879438-0.47517904j, -0.29303954-0.47264099j, -0.43951987+0.12977568j, -0.03496718-0.48418713j 7 | 0.06065372-0.11292765j, 0.54733962+0.1215551j, -0.50721513+0.56195975j, -0.15923161+0.26606674j 8 | 0.42212573-0.53182417j, -0.2642572+0.50625182j, 0.19448705+0.28321781j, 0.30281396-0.05582391j 9 | 0.43097587-0.30288974j, 0.07419772-0.21155126j, 0.28335618-0.13633175j, -0.75113453+0.09580304j 10 | 11 | # Initial states are two-mode squeezed states 12 | S2gate(1.0, 0.0) | [0, 4] 13 | S2gate(1.0, 0.0) | [1, 5] 14 | S2gate(1.0, 0.0) | [3, 7] 15 | 16 | # Apply the unitary matrix above to 17 | # the first pair of modes, as well 18 | # as a beamsplitter 19 | Interferometer(U) | [0, 1, 2, 3] 20 | BSgate(0.543, 0.123) | [2, 0] 21 | Rgate(0.453) | 1 22 | MZgate(0.65, -0.54) | [2, 3] 23 | 24 | # Duplicate the above unitary for 25 | # the second pair of modes 26 | Interferometer(U) | [4, 5, 6, 7] 27 | BSgate(0.543, 0.123) | [6, 4] 28 | Rgate(0.453) | 5 29 | MZgate(0.65, -0.54) | [6, 7] 30 | 31 | # Perform a PNR measurement in the Fock basis 32 | MeasureFock() | [0, 1, 2, 3, 4, 5, 6, 7] 33 | -------------------------------------------------------------------------------- /examples/gate_teleportation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import * 4 | 5 | # initialize engine and program objects 6 | eng = sf.Engine(backend="gaussian") 7 | gate_teleportation = sf.Program(4) 8 | 9 | with gate_teleportation.context as q: 10 | # create initial states 11 | Squeezed(0.1) | q[0] 12 | Squeezed(-2) | q[1] 13 | Squeezed(-2) | q[2] 14 | 15 | # apply the gate to be teleported 16 | Pgate(0.5) | q[1] 17 | 18 | # conditional phase entanglement 19 | CZgate(1) | (q[0], q[1]) 20 | CZgate(1) | (q[1], q[2]) 21 | 22 | # projective measurement onto 23 | # the position quadrature 24 | Fourier.H | q[0] 25 | MeasureX | q[0] 26 | Fourier.H | q[1] 27 | MeasureX | q[1] 28 | # compare against the expected output 29 | # X(q1/sqrt(2)).F.P(0.5).X(q0/sqrt(0.5)).F.|z> 30 | # not including the corrections 31 | Squeezed(0.1) | q[3] 32 | Fourier | q[3] 33 | Xgate(q[0].par) | q[3] 34 | Pgate(0.5) | q[3] 35 | Fourier | q[3] 36 | Xgate(q[1].par) | q[3] 37 | # end circuit 38 | 39 | results = eng.run(gate_teleportation) 40 | print(results.state.reduced_gaussian([2])) 41 | print(results.state.reduced_gaussian([3])) 42 | -------------------------------------------------------------------------------- /examples/gaussian_boson_sampling.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import numpy as np 3 | import strawberryfields as sf 4 | from strawberryfields.ops import * 5 | 6 | # initialize engine and program objects 7 | eng = sf.Engine(backend="gaussian") 8 | gbs = sf.Program(4) 9 | 10 | # define the linear interferometer 11 | U = np.array([ 12 | [ 0.219546940711-0.256534554457j, 0.611076853957+0.524178937791j, 13 | -0.102700187435+0.474478834685j,-0.027250232925+0.03729094623j], 14 | [ 0.451281863394+0.602582912475j, 0.456952590016+0.01230749109j, 15 | 0.131625867435-0.450417744715j, 0.035283194078-0.053244267184j], 16 | [ 0.038710094355+0.492715562066j,-0.019212744068-0.321842852355j, 17 | -0.240776471286+0.524432833034j,-0.458388143039+0.329633367819j], 18 | [-0.156619083736+0.224568570065j, 0.109992223305-0.163750223027j, 19 | -0.421179844245+0.183644837982j, 0.818769184612+0.068015658737j] 20 | ]) 21 | 22 | 23 | with gbs.context as q: 24 | # prepare the input squeezed states 25 | S = Sgate(1) 26 | S | q[0] 27 | S | q[1] 28 | S | q[2] 29 | S | q[3] 30 | 31 | # linear interferometer 32 | Interferometer(U) | q 33 | # end circuit 34 | 35 | # run the engine 36 | results = eng.run(gbs) 37 | 38 | # Fock states to measure at output 39 | measure_states = [[0,0,0,0], [1,1,0,0], [0,1,0,1], [1,1,1,1], [2,0,0,0]] 40 | 41 | # extract the probabilities of calculating several 42 | # different Fock states at the output, and print them to the terminal 43 | for i in measure_states: 44 | prob = results.state.fock_prob(i) 45 | print("|{}>: {}".format("".join(str(j) for j in i), prob)) 46 | -------------------------------------------------------------------------------- /examples/gaussian_cloning.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from numpy import pi, sqrt 3 | 4 | import strawberryfields as sf 5 | from strawberryfields.ops import * 6 | 7 | # initialize engine and program objects 8 | eng = sf.Engine(backend="gaussian") 9 | gaussian_cloning = sf.Program(4) 10 | 11 | alpha = 0.7+1.2j 12 | r = np.abs(alpha) 13 | phi = np.angle(alpha) 14 | 15 | with gaussian_cloning.context as q: 16 | # state to be cloned 17 | Coherent(r, phi) | q[0] 18 | 19 | # 50-50 beamsplitter 20 | BS = BSgate(pi/4, 0) 21 | 22 | # symmetric Gaussian cloning scheme 23 | BS | (q[0], q[1]) 24 | BS | (q[1], q[2]) 25 | MeasureX | q[1] 26 | MeasureP | q[2] 27 | Xgate(q[1].par * sqrt(2)) | q[0] 28 | Zgate(q[2].par * sqrt(2)) | q[0] 29 | 30 | # after the final beamsplitter, modes q[0] and q[3] 31 | # will contain identical approximate clones of the 32 | # initial state Coherent(0.1+0j) 33 | BS | (q[0], q[3]) 34 | # end circuit 35 | 36 | # run the engine 37 | results = eng.run(gaussian_cloning, modes=[0, 3]) 38 | 39 | # return the cloning fidelity 40 | fidelity = sqrt(results.state.fidelity_coherent([0.7+1.2j, 0.7+1.2j])) 41 | # return the cloned displacement 42 | alpha = results.state.displacement() 43 | 44 | # run the engine over an ensemble 45 | reps = 1000 46 | f = np.empty([reps]) 47 | a = np.empty([reps], dtype=np.complex128) 48 | 49 | for i in range(reps): 50 | eng.reset() 51 | results = eng.run(gaussian_cloning, modes=[0]) 52 | f[i] = results.state.fidelity_coherent([0.7+1.2j]) 53 | a[i] = results.state.displacement() 54 | 55 | print("Fidelity of cloned state:", np.mean(f)) 56 | print("Mean displacement of cloned state:", np.mean(a)) 57 | print("Mean covariance matrix of cloned state:\n", np.cov([a.real, a.imag])) 58 | -------------------------------------------------------------------------------- /examples/gkp_phase_gate.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """A comparison of the Wigner function for a finite energy GKP |+i> state 16 | to the output of a GKP qubit phase gate applied to a finite energy |+> state. 17 | The qubit phase gate is applied using measurement-based squeezing.""" 18 | 19 | import strawberryfields as sf 20 | import numpy as np 21 | import matplotlib.pyplot as plt 22 | from matplotlib import colors, colorbar 23 | 24 | 25 | sf.hbar = 1 26 | x = np.linspace(-4, 4, 400) * np.sqrt(np.pi) 27 | p = np.linspace(-4, 4, 400) * np.sqrt(np.pi) 28 | wigners = [] 29 | 30 | # Finite energy GKP |+i> state 31 | prog_y = sf.Program(1) 32 | with prog_y.context as q: 33 | sf.ops.GKP([np.pi / 2, -np.pi / 2], epsilon=0.1) | q[0] 34 | eng = sf.Engine("bosonic") 35 | result = eng.run(prog_y) 36 | wigners.append(result.state.wigner(0, x, p)) 37 | 38 | # Squeezing values for measurement-based squeezing ancillae 39 | rdB = np.array([14, 10, 6]) 40 | r_anc = np.log(10) * rdB / 20 41 | 42 | # Detection efficiencies 43 | eta_anc = np.array([1, 0.98, 0.95]) 44 | 45 | # Target squeezing and rotation angles to apply a GKP phase gate 46 | r = np.arccosh(np.sqrt(5 / 4)) 47 | theta = np.arctan(0.5) 48 | phi = -np.pi / 2 * np.sign(0.5) - theta 49 | 50 | # Apply a GKP phase gate to |+> for three different qualities of 51 | # measurement-based squeezing. 52 | for i in range(3): 53 | prog = sf.Program(1) 54 | with prog.context as q: 55 | sf.ops.GKP([np.pi / 2, 0], epsilon=0.1) | q[0] 56 | sf.ops.MSgate(r, phi, r_anc[i], eta_anc[i], avg=True) | q[0] 57 | sf.ops.Rgate(theta) | q[0] 58 | eng = sf.Engine("bosonic") 59 | result = eng.run(prog) 60 | wigners.append(result.state.wigner(0, x, p)) 61 | 62 | 63 | # Plotting 64 | cmax = np.real_if_close(np.amax(np.array(wigners))) 65 | cmin = np.real_if_close(np.amin(np.array(wigners))) 66 | if abs(cmin) < cmax: 67 | cmin = -cmax 68 | else: 69 | cmax = -cmin 70 | 71 | fig, axs = plt.subplots(1, 5, figsize=(16, 4), gridspec_kw={"width_ratios": [1, 1, 1, 1, 0.05]}) 72 | cmap = plt.cm.RdBu 73 | norm = colors.Normalize(vmin=cmin, vmax=cmax) 74 | cb1 = colorbar.ColorbarBase(axs[4], cmap=cmap, norm=norm, orientation="vertical") 75 | ims = np.empty(4, dtype=object) 76 | axs[0].set_ylabel(r"p (units of $\sqrt{\hbar\pi}$)", fontsize=15) 77 | axs[0].set_title(r"$|+i^\epsilon\rangle_{gkp}$, $\epsilon$=0.1 (10 dB)", fontsize=15) 78 | for i in range(4): 79 | ims[i] = axs[i].contourf( 80 | x / np.sqrt(np.pi), 81 | p / np.sqrt(np.pi), 82 | wigners[i], 83 | levels=60, 84 | cmap=plt.cm.RdBu, 85 | vmin=cmin, 86 | vmax=cmax, 87 | ) 88 | axs[i].set_xlabel(r"q (units of $\sqrt{\hbar\pi}$)", fontsize=15) 89 | if i > 0: 90 | axs[i].set_title( 91 | r"$r_{anc}=$" + str(rdB[i - 1]) + r"dB, $\sqrt{\eta}=$" + str(eta_anc[i - 1]), 92 | fontsize=15, 93 | ) 94 | for c in ims[i].collections: 95 | c.set_edgecolor("face") 96 | axs[i].tick_params(labelsize=14) 97 | cb1.set_label("Wigner function", fontsize=15) 98 | fig.tight_layout() 99 | plt.show() 100 | -------------------------------------------------------------------------------- /examples/hamiltonian_simulation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import * 4 | from numpy import pi 5 | 6 | # initialize engine and program objects 7 | eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 5}) 8 | ham_simulation = sf.Program(2) 9 | 10 | # set the Hamiltonian parameters 11 | J = 1 # hopping transition 12 | U = 1.5 # on-site interaction 13 | k = 20 # Lie product decomposition terms 14 | t = 1.086 # timestep 15 | theta = -J*t/k 16 | r = -U*t/(2*k) 17 | 18 | with ham_simulation.context as q: 19 | # prepare the initial state 20 | Fock(2) | q[0] 21 | 22 | # Two node tight-binding 23 | # Hamiltonian simulation 24 | 25 | for i in range(k): 26 | BSgate(theta, pi/2) | (q[0], q[1]) 27 | Kgate(r) | q[0] 28 | Rgate(-r) | q[0] 29 | Kgate(r) | q[1] 30 | Rgate(-r) | q[1] 31 | # end circuit 32 | 33 | # run the engine 34 | results = eng.run(ham_simulation) 35 | # the output state probabilities 36 | print(results.state.fock_prob([0,2])) 37 | print(results.state.fock_prob([1,1])) 38 | print(results.state.fock_prob([2,0])) 39 | -------------------------------------------------------------------------------- /examples/measurement_based_squeezing.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """A comparison of ideal squeezing, and measurement-based squeezing applied using 16 | the average and single shot maps.""" 17 | 18 | import strawberryfields as sf 19 | import numpy as np 20 | import matplotlib.pyplot as plt 21 | from matplotlib.patches import Ellipse 22 | 23 | # Values of target squeezing 24 | r = [0.3, 1, 2] 25 | 26 | # Style choices for plots 27 | color = ["tab:red", "seagreen", "cornflowerblue"] 28 | style = [":", "--", "-"] 29 | label = ["Ideal", "Average map", "Single shot"] 30 | e = [0, 1, 2] 31 | 32 | # Create plot 33 | fig, ax = plt.subplots(1, 3, figsize=(12, 4)) 34 | 35 | # Loop over target r values 36 | for j in range(3): 37 | 38 | prog = sf.Program(3) 39 | with prog.context as q: 40 | # Ideal squeezing 41 | sf.ops.Sgate(r[j], 0) | q[0] 42 | # Average map of measurement-based squeezing 43 | sf.ops.MSgate(r[j], 0, r_anc=1.2, eta_anc=0.99, avg=True) | q[1] 44 | # Single-shot map of measurement-based squeezing 45 | sf.ops.MSgate(r[j], 0, r_anc=1.2, eta_anc=0.99, avg=False) | q[2] 46 | eng = sf.Engine("bosonic") 47 | state = eng.run(prog).state 48 | 49 | # Quadrature values 50 | x = np.linspace(-4, 4, 1000) * np.sqrt(sf.hbar) * r[j] 51 | p = np.linspace(-4, 4, 1000) * np.sqrt(sf.hbar) * r[j] 52 | 53 | # Plot ellipses for each squeezed state 54 | for i in range(3): 55 | _, mean, cov = state.reduced_bosonic(i) 56 | width = 2 * np.sqrt(cov[0, 0, 0]) 57 | height = 2 * np.sqrt(cov[0, 1, 1]) 58 | e[i] = Ellipse( 59 | xy=mean[0], 60 | width=width, 61 | height=height, 62 | facecolor="none", 63 | edgecolor=color[i], 64 | linestyle=style[i], 65 | ) 66 | ax[j].add_artist(e[i]) 67 | 68 | ax[j].set_title(r"$r_{target}=$" + str(r[j])) 69 | ax[j].set_xlabel(r"q (units of $\sqrt{\hbar}$)", fontsize=12) 70 | ax[j].set_xlim(x[0], x[-1]) 71 | ax[j].set_ylim(p[0], p[-1]) 72 | 73 | ax[0].set_ylabel(r"p (units of $\sqrt{\hbar}$)", fontsize=12) 74 | ax[1].legend(e, label, ncol=3, bbox_to_anchor=(0.5, -0.3), loc="lower center") 75 | plt.show() 76 | -------------------------------------------------------------------------------- /examples/optimization.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import * 4 | import tensorflow as tf 5 | 6 | # initialize engine and program objects 7 | eng = sf.Engine(backend="tf", backend_options={"cutoff_dim": 7}) 8 | circuit = sf.Program(1) 9 | 10 | tf_alpha = tf.Variable(0.1) 11 | tf_phi = tf.Variable(0.1) 12 | 13 | alpha, phi = circuit.params('alpha', 'phi') 14 | 15 | with circuit.context as q: 16 | Dgate(alpha, phi) | q[0] 17 | 18 | opt = tf.keras.optimizers.Adam(learning_rate=0.1) 19 | steps = 50 20 | 21 | for step in range(steps): 22 | 23 | # reset the engine if it has already been executed 24 | if eng.run_progs: 25 | eng.reset() 26 | 27 | with tf.GradientTape() as tape: 28 | # execute the engine 29 | results = eng.run(circuit, args={'alpha': tf_alpha, 'phi': tf_phi}) 30 | # get the probability of fock state |1> 31 | prob = results.state.fock_prob([1]) 32 | # negative sign to maximize prob 33 | loss = -prob 34 | 35 | gradients = tape.gradient(loss, [tf_alpha, tf_phi]) 36 | opt.apply_gradients(zip(gradients, [tf_alpha, tf_phi])) 37 | print("Value at step {}: {}".format(step, prob)) 38 | -------------------------------------------------------------------------------- /examples/teleportation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import strawberryfields as sf 3 | from strawberryfields.ops import ( 4 | Coherent, 5 | Squeezed, 6 | BSgate, 7 | Xgate, 8 | Zgate, 9 | MeasureX, 10 | MeasureP, 11 | ) 12 | 13 | import numpy as np 14 | from numpy import pi, sqrt 15 | 16 | # set the random seed 17 | np.random.seed(42) 18 | 19 | prog = sf.Program(3) 20 | 21 | alpha = 1 + 0.5j 22 | r = np.abs(alpha) 23 | phi = np.angle(alpha) 24 | 25 | with prog.context as q: 26 | # prepare initial states 27 | Coherent(r, phi) | q[0] 28 | Squeezed(-2) | q[1] 29 | Squeezed(2) | q[2] 30 | 31 | # apply gates 32 | BS = BSgate(pi / 4, 0) 33 | BS | (q[1], q[2]) 34 | BS | (q[0], q[1]) 35 | 36 | # Perform homodyne measurements 37 | MeasureX | q[0] 38 | MeasureP | q[1] 39 | 40 | # Displacement gates conditioned on 41 | # the measurements 42 | Xgate(sqrt(2) * q[0].par) | q[2] 43 | Zgate(sqrt(2) * q[1].par) | q[2] 44 | 45 | eng = sf.Engine("fock", backend_options={"cutoff_dim": 15}) 46 | result = eng.run(prog) 47 | 48 | # view output state and fidelity 49 | print(result.samples) 50 | print(result.state) 51 | print(result.state.fidelity_coherent([0, 0, alpha])) 52 | -------------------------------------------------------------------------------- /requirements-ci.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scipy 3 | sympy 4 | tensorflow 5 | tensorboard 6 | networkx 7 | quantum-blackbird 8 | python-dateutil 9 | thewalrus>=0.22.0 10 | toml 11 | numba 12 | requests 13 | setuptools 14 | urllib3 15 | plotly 16 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | black==22.1.0 2 | pytest==7.1.0 3 | pytest-cov==3.0.0 4 | pytest-mock==3.7.0 5 | pytest-randomly==3.11.0 6 | typing-extensions==4.1.1 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | networkx==2.7.1 2 | numba==0.55.1 3 | numpy==1.26.4 4 | plotly==5.6.0 5 | python-dateutil==2.8.2 6 | quantum-blackbird==0.4.0 7 | requests==2.27.1 8 | scipy==1.14.0 9 | sympy==1.10 10 | tensorflow==2.8.0 11 | tensorboard==2.8.0 12 | thewalrus==0.22.0 13 | toml==0.10.2 14 | typing-extensions==4.1.1 15 | urllib3==1.26.8 16 | quantum-xir==0.2.1 17 | xanadu-cloud-client==0.2.1 18 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | from setuptools import setup, find_packages 15 | 16 | 17 | with open("strawberryfields/_version.py") as f: 18 | version = f.readlines()[-1].split()[-1].strip("\"'") 19 | 20 | 21 | requirements = [ 22 | "networkx>=2.0", 23 | "numba", 24 | "numpy>=1.17.4", 25 | "python-dateutil>=2.8.0", 26 | "quantum-blackbird>=0.4.0", 27 | "requests>=2.22.0", 28 | "scipy>=1.8.0", 29 | "sympy>=1.5", 30 | "thewalrus>=0.18.0", 31 | "toml", 32 | "urllib3>=1.25.3", 33 | "quantum-xir>=0.1.1", 34 | "xanadu-cloud-client>=0.2.1", 35 | ] 36 | 37 | info = { 38 | "name": "StrawberryFields", 39 | "version": version, 40 | "maintainer": "Xanadu Inc.", 41 | "maintainer_email": "software@xanadu.ai", 42 | "url": "https://github.com/XanaduAI/StrawberryFields", 43 | "license": "Apache License 2.0", 44 | "packages": find_packages(where="."), 45 | "package_data": {"strawberryfields": ["backends/data/*", "apps/data/feature_data/*", 46 | "apps/data/sample_data/*"]}, 47 | "include_package_data": True, 48 | "description": "Open source library for continuous-variable quantum computation", 49 | "long_description": open("README.md", encoding="utf-8").read(), 50 | "long_description_content_type": "text/markdown", 51 | "provides": ["strawberryfields"], 52 | "install_requires": requirements, 53 | "command_options": { 54 | "build_sphinx": {"version": ("setup.py", version), "release": ("setup.py", version)} 55 | }, 56 | } 57 | 58 | classifiers = [ 59 | "Development Status :: 4 - Beta", 60 | "Environment :: Console", 61 | "Intended Audience :: Science/Research", 62 | "License :: OSI Approved :: Apache Software License", 63 | "Natural Language :: English", 64 | "Operating System :: POSIX", 65 | "Operating System :: MacOS :: MacOS X", 66 | "Operating System :: POSIX :: Linux", 67 | "Operating System :: Microsoft :: Windows", 68 | "Programming Language :: Python", 69 | "Programming Language :: Python :: 3", 70 | "Programming Language :: Python :: 3.7", 71 | "Programming Language :: Python :: 3.8", 72 | "Programming Language :: Python :: 3.9", 73 | "Programming Language :: Python :: 3.10", 74 | "Programming Language :: Python :: 3 :: Only", 75 | "Topic :: Scientific/Engineering :: Physics", 76 | ] 77 | 78 | setup(classifiers=classifiers, **(info)) 79 | -------------------------------------------------------------------------------- /strawberryfields/_version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2022 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """Version information. 16 | Version number (major.minor.patch[-label]) 17 | """ 18 | 19 | __version__ = "0.24.0-dev" 20 | -------------------------------------------------------------------------------- /strawberryfields/apps/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """This package contains the modules that make up the 15 | Strawberry Fields application layer. 16 | 17 | .. currentmodule:: strawberryfields.apps 18 | .. autosummary:: 19 | :toctree: api 20 | 21 | clique 22 | data 23 | plot 24 | points 25 | qchem 26 | sample 27 | similarity 28 | subgraph 29 | train 30 | """ 31 | 32 | import strawberryfields.apps.clique 33 | import strawberryfields.apps.data 34 | import strawberryfields.apps.plot 35 | import strawberryfields.apps.points 36 | import strawberryfields.apps.qchem 37 | import strawberryfields.apps.sample 38 | import strawberryfields.apps.similarity 39 | import strawberryfields.apps.subgraph 40 | import strawberryfields.apps.train 41 | from strawberryfields.apps.qchem import vibronic 42 | -------------------------------------------------------------------------------- /strawberryfields/apps/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Data module providing pre-calculated datasets from GBS simulations. 15 | 16 | GBS samples 17 | ^^^^^^^^^^^ 18 | The following datasets of GBS samples are available: 19 | 20 | .. currentmodule:: strawberryfields.apps.data 21 | 22 | .. autosummary:: 23 | :toctree: api 24 | 25 | Planted 26 | TaceAs 27 | PHat 28 | Mutag0 29 | Mutag1 30 | Mutag2 31 | Mutag3 32 | Formic 33 | Water 34 | Pyrrole 35 | 36 | .. seealso:: 37 | 38 | :doc:`/introduction/data` 39 | 40 | The :mod:`~.sample` submodule contains the base :class:`~.GraphDataset`, 41 | :class:`~.MoleculeDataset`, and :class:`~.SampleDataset` classes from which these datasets inherit. 42 | 43 | .. autosummary:: 44 | :toctree: api 45 | 46 | sample 47 | 48 | GBS feature vectors 49 | ^^^^^^^^^^^^^^^^^^^ 50 | 51 | For use with the :mod:`~.similarity` module, the following pre-calculated feature vectors of graph 52 | datasets are provided: 53 | 54 | .. autosummary:: 55 | :toctree: api 56 | 57 | MUTAG 58 | QM9Exact 59 | QM9MC 60 | 61 | The :mod:`~.feature` submodule contains the base :class:`~.FeatureDataset` class from which 62 | these datasets inherit. 63 | 64 | .. autosummary:: 65 | :toctree: api 66 | 67 | feature 68 | """ 69 | 70 | import strawberryfields.apps.data.sample 71 | import strawberryfields.apps.data.feature 72 | from strawberryfields.apps.data.sample import ( 73 | Planted, 74 | TaceAs, 75 | PHat, 76 | Mutag0, 77 | Mutag1, 78 | Mutag2, 79 | Mutag3, 80 | Formic, 81 | Water, 82 | Pyrrole, 83 | ) 84 | from strawberryfields.apps.data.feature import ( 85 | MUTAG, 86 | QM9Exact, 87 | QM9MC, 88 | ) 89 | -------------------------------------------------------------------------------- /strawberryfields/apps/data/feature_data/MUTAG_exact_fv.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/feature_data/MUTAG_exact_fv.npy -------------------------------------------------------------------------------- /strawberryfields/apps/data/feature_data/MUTAG_mat.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/feature_data/MUTAG_mat.npy -------------------------------------------------------------------------------- /strawberryfields/apps/data/feature_data/QM9_exact_fv.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/feature_data/QM9_exact_fv.npy -------------------------------------------------------------------------------- /strawberryfields/apps/data/feature_data/QM9_mat.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/feature_data/QM9_mat.npy -------------------------------------------------------------------------------- /strawberryfields/apps/data/feature_data/QM9_mc_fv.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/feature_data/QM9_mc_fv.npy -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_0.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_0.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_0_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_0_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_1.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_1_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_1_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_2.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_2_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_2_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_3.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_3.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/MUTAG_3_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/MUTAG_3_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/TACE-AS.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/TACE-AS.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/TACE-AS_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/TACE-AS_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/formic.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/formic.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/formic_Ud.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/formic_Ud.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/formic_delta.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/formic_delta.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/formic_w.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/formic_w.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/formic_wp.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/formic_wp.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/p_hat300-1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/p_hat300-1.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/p_hat300-1_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/p_hat300-1_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/planted.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/planted.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/planted_A.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/planted_A.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_Lf.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_Lf.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_Li.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_Li.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_U.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_U.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_m.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_m.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_rf.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_rf.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_ri.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_ri.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_wf.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_wf.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/pyrrole_wi.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/pyrrole_wi.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/water.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/water.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/water_U.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/water_U.npz -------------------------------------------------------------------------------- /strawberryfields/apps/data/sample_data/water_w.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/apps/data/sample_data/water_w.npz -------------------------------------------------------------------------------- /strawberryfields/apps/qchem/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """This module contains functionality for quantum chemistry calculations. 15 | 16 | .. currentmodule:: strawberryfields.apps.qchem 17 | 18 | The following submodules are available: 19 | 20 | .. autosummary:: 21 | :toctree: api 22 | 23 | dynamics 24 | vibronic 25 | 26 | Additional utility functions are also available: 27 | 28 | .. autosummary:: 29 | :toctree: api 30 | 31 | duschinsky 32 | read_gamess 33 | """ 34 | import strawberryfields.apps.qchem.dynamics 35 | import strawberryfields.apps.qchem.vibronic 36 | from strawberryfields.apps.qchem.utils import duschinsky, read_gamess 37 | -------------------------------------------------------------------------------- /strawberryfields/backends/bosonicbackend/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Bosonic qubit simulator backend""" 15 | 16 | from .backend import BosonicBackend 17 | -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_10.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_10.npz -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_15.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_15.npz -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_20.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_20.npz -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_25.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_25.npz -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_30.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_30.npz -------------------------------------------------------------------------------- /strawberryfields/backends/data/fock_beamsplitter_factors_5.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/strawberryfields/backends/data/fock_beamsplitter_factors_5.npz -------------------------------------------------------------------------------- /strawberryfields/backends/fockbackend/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Fock simulator backend""" 15 | 16 | from .backend import FockBackend 17 | -------------------------------------------------------------------------------- /strawberryfields/backends/gaussianbackend/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Gaussian simulator backend""" 15 | 16 | from .backend import GaussianBackend 17 | -------------------------------------------------------------------------------- /strawberryfields/backends/gaussianbackend/ops.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Gaussian operations""" 15 | 16 | import numpy as np 17 | 18 | 19 | def chop_in_blocks(m, idtodelete): 20 | """ 21 | Splits a (symmetric) matrix into 3 blocks, A, B, C 22 | Blocks A and B are diagonal blocks and C is the offdiagonal block 23 | idtodelete specifies which indices go into B. 24 | """ 25 | A = np.copy(m) 26 | A = np.delete(A, idtodelete, axis=0) 27 | A = np.delete(A, idtodelete, axis=1) 28 | B = np.delete(m[:, idtodelete], idtodelete, axis=0) 29 | C = np.empty((len(idtodelete), (len(idtodelete)))) 30 | for localindex, globalindex in enumerate(idtodelete): 31 | for localindex1, globalindex1 in enumerate(idtodelete): 32 | C[localindex, localindex1] = m[globalindex, globalindex1] 33 | return (A, B, C) 34 | 35 | 36 | def chop_in_blocks_vector(v, idtodelete): 37 | """ 38 | Splits a vector into two vectors, where idtodelete specifies 39 | which elements go into vb 40 | """ 41 | idtokeep = list(set(np.arange(len(v))) - set(idtodelete)) 42 | idtokeep.sort() 43 | va = v[idtokeep] 44 | vb = v[idtodelete] 45 | return (va, vb) 46 | 47 | 48 | def reassemble(A, idtodelete): 49 | """ 50 | Puts the matrix A inside a larger matrix of dimensions 51 | dim(A)+len(idtodelete) 52 | The empty space are filled with zeros (offdiagonal) and ones (diagonals) 53 | """ 54 | ntot = len(A) + len(idtodelete) 55 | ind = list(set(np.arange(ntot)) - set(idtodelete)) 56 | ind.sort() 57 | newmat = np.zeros((ntot, ntot)) 58 | for i, i1 in enumerate(ind): 59 | for j, j1 in enumerate(ind): 60 | newmat[i1, j1] = A[i, j] 61 | 62 | for i in idtodelete: 63 | newmat[i, i] = 1.0 64 | return newmat 65 | 66 | 67 | def reassemble_vector(va, idtodelete): 68 | r"""Creates a vector with zeros indices idtodelete 69 | and everywhere else it puts the entries of va 70 | """ 71 | ntot = len(va) + len(idtodelete) 72 | ind = list(set(np.arange(ntot)) - set(idtodelete)) 73 | ind.sort() 74 | newv = np.zeros(ntot) 75 | for j, j1 in enumerate(ind): 76 | newv[j1] = va[j] 77 | return newv 78 | -------------------------------------------------------------------------------- /strawberryfields/compilers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2022 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | This subpackage implements the :class:`Compiler` class, an abstract base class used to define and 16 | compile families of quantum circuits, e.g., circuits that can be executed on particular hardware or 17 | simulator backends. 18 | 19 | The information in the :class:`Compiler` instances is used by :meth:`.Program.compile` to validate and 20 | compile quantum programs. By querying the :class:`Compiler` class representing the requested compilation 21 | target, :meth:`.Program.compile` can 22 | 23 | 1. **Validate** that the Program consists of valid quantum operations in the correct topology for 24 | the targeted circuit class. 25 | 26 | 2. **Compile** the Program into an :term:`equivalent circuit` that has the topology required by the 27 | targeted circuit class, decomposing circuit operations as required. 28 | 29 | Note that the compilation process is not perfect and can provide false negatives: it can admit 30 | failure by raising a :class:`.CircuitError` even if the Program theoretically is equivalent to a 31 | circuit that belongs in the target circuit class. 32 | 33 | The circuit class database :attr:`circuit_db` is a dictionary mapping the circuit family 34 | short name to the corresponding Compiler instance. 35 | In particular, for each backend supported by Strawberry Fields the database contains a 36 | corresponding Compiler instance with the same short name, used to validate Programs to be 37 | executed on that backend. 38 | """ 39 | from .compiler import Compiler, Ranges 40 | from .xcov import Xcov 41 | from .xstrict import Xstrict 42 | from .xunitary import Xunitary 43 | from .fock import Fock 44 | from .gaussian import Gaussian 45 | from .bosonic import Bosonic 46 | from .gbs import GBS 47 | from .gaussian_unitary import GaussianUnitary 48 | from .gaussian_merge import GaussianMerge 49 | from .passive import Passive 50 | from .tdm import TDM, TD2, Borealis 51 | 52 | compilers = ( 53 | Fock, 54 | Gaussian, 55 | Bosonic, 56 | GBS, 57 | GaussianUnitary, 58 | Xcov, 59 | Xstrict, 60 | Xunitary, 61 | GaussianMerge, 62 | Passive, 63 | TDM, 64 | TD2, 65 | Borealis, 66 | ) 67 | 68 | compiler_db = {c.short_name: c for c in compilers} 69 | """dict[str, ~strawberryfields.compilers.Compiler]: Map from compiler name to the corresponding 70 | class.""" 71 | 72 | __all__ = ["compiler_db", "Compiler", "Ranges"] + [i.__name__ for i in compilers] 73 | -------------------------------------------------------------------------------- /strawberryfields/compilers/bosonic.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Circuit specifications for general Gaussian simulator backends.""" 15 | from .compiler import Compiler 16 | 17 | 18 | class Bosonic(Compiler): 19 | """Compiler for general Bosonic backends.""" 20 | 21 | short_name = "bosonic" 22 | interactive = True 23 | 24 | primitives = { 25 | # meta operations 26 | "All", 27 | "_New_modes", 28 | "_Delete", 29 | # state preparations 30 | "Vacuum", 31 | "Coherent", 32 | "Squeezed", 33 | "DisplacedSqueezed", 34 | "Thermal", 35 | "Gaussian", 36 | "Fock", 37 | "Ket", 38 | "DensityMatrix", 39 | "Bosonic", 40 | "GKP", 41 | "Catstate", 42 | "Comb", 43 | # measurements 44 | "MeasureHomodyne", 45 | "MeasureHeterodyne", 46 | # TODO: "MeasureFock", 47 | "MeasureThreshold", 48 | # channels 49 | "LossChannel", 50 | "ThermalLossChannel", 51 | # single mode gates 52 | "Dgate", 53 | "Sgate", 54 | "Rgate", 55 | "BSgate", 56 | "MSgate", 57 | } 58 | 59 | decompositions = { 60 | "Pgate": {}, 61 | "S2gate": {}, 62 | "CXgate": {}, 63 | "CZgate": {}, 64 | "MZgate": {}, 65 | "Xgate": {}, 66 | "Zgate": {}, 67 | "Fouriergate": {}, 68 | } 69 | -------------------------------------------------------------------------------- /strawberryfields/compilers/fock.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Circuit specifications for general Fock simulator backends.""" 15 | from .compiler import Compiler 16 | 17 | 18 | class Fock(Compiler): 19 | """Compiler for general Fock backends.""" 20 | 21 | short_name = "fock" 22 | interactive = True 23 | 24 | primitives = { 25 | # meta operations 26 | "All", 27 | "_New_modes", 28 | "_Delete", 29 | # state preparations 30 | "Vacuum", 31 | "Coherent", 32 | "Squeezed", 33 | "DisplacedSqueezed", 34 | "Thermal", 35 | "Fock", 36 | "Catstate", 37 | "GKP", 38 | "Ket", 39 | "DensityMatrix", 40 | # measurements 41 | "MeasureFock", 42 | "MeasureHomodyne", 43 | # channels 44 | "LossChannel", 45 | # single mode gates 46 | "Dgate", 47 | "Sgate", 48 | "Rgate", 49 | "Vgate", 50 | "Kgate", 51 | # two mode gates 52 | "BSgate", 53 | "MZgate", 54 | "CKgate", 55 | "S2gate", 56 | # Multimode gate 57 | "Ggate", 58 | } 59 | 60 | decompositions = { 61 | "Interferometer": {}, 62 | "GraphEmbed": {}, 63 | "BipartiteGraphEmbed": {}, 64 | "GaussianTransform": {}, 65 | "Gaussian": {}, 66 | "Pgate": {}, 67 | "CXgate": {}, 68 | "CZgate": {}, 69 | "sMZgate": {}, 70 | "Xgate": {}, 71 | "Zgate": {}, 72 | "Fouriergate": {}, 73 | } 74 | -------------------------------------------------------------------------------- /strawberryfields/compilers/gaussian.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Circuit specifications for general Gaussian simulator backends.""" 15 | from .compiler import Compiler 16 | 17 | 18 | class Gaussian(Compiler): 19 | """Compiler for general Gaussian backends.""" 20 | 21 | short_name = "gaussian" 22 | interactive = True 23 | 24 | primitives = { 25 | # meta operations 26 | "All", 27 | "_New_modes", 28 | "_Delete", 29 | # state preparations 30 | "Vacuum", 31 | "Coherent", 32 | "Squeezed", 33 | "DisplacedSqueezed", 34 | "Thermal", 35 | "Gaussian", 36 | # measurements 37 | "MeasureHomodyne", 38 | "MeasureHeterodyne", 39 | "MeasureFock", 40 | "MeasureThreshold", 41 | # channels 42 | "LossChannel", 43 | "ThermalLossChannel", 44 | "PassiveChannel", 45 | # single mode gates 46 | "Dgate", 47 | "Sgate", 48 | "Rgate", 49 | "BSgate", 50 | } 51 | 52 | decompositions = { 53 | "Interferometer": {}, 54 | "GraphEmbed": {}, 55 | "BipartiteGraphEmbed": {}, 56 | "GaussianTransform": {}, 57 | "Gaussian": {}, 58 | "Pgate": {}, 59 | "S2gate": {}, 60 | "CXgate": {}, 61 | "CZgate": {}, 62 | "MZgate": {}, 63 | "sMZgate": {}, 64 | "Xgate": {}, 65 | "Zgate": {}, 66 | "Fouriergate": {}, 67 | } 68 | -------------------------------------------------------------------------------- /strawberryfields/compilers/xstrict.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """Strict compiler for the X class of circuits.""" 15 | from .compiler import Compiler 16 | from .gbs import GBS 17 | 18 | 19 | class Xstrict(Compiler): 20 | """Strict compiler for the X class of circuits. 21 | 22 | Ensures that the program exactly matches the devices topology. 23 | As a result, this compiler only accepts :class:`~.ops.S2gate`, :class:`~.ops.MZgate`, 24 | :class:`~.ops.Rgate`, and :class:`~.ops.MeasureFock` operations. 25 | 26 | This compiler must be used with an X series device specification. 27 | 28 | **Example** 29 | 30 | >>> eng = sf.RemoteEngine("X8") 31 | >>> spec = eng.device_spec 32 | >>> prog.compile(device=spec, compiler="Xstrict") 33 | """ 34 | 35 | short_name = "Xstrict" 36 | interactive = False 37 | 38 | primitives = {"S2gate", "MeasureFock", "MZgate", "Rgate"} 39 | 40 | decompositions = {} 41 | 42 | def compile(self, seq, registers): 43 | # Call the GBS compiler to do basic measurement validation. 44 | # The GBS compiler also merges multiple measurement commands 45 | # into a single MeasureFock command at the end of the circuit. 46 | return GBS().compile(seq, registers) 47 | -------------------------------------------------------------------------------- /strawberryfields/tdm/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2022 Xanadu Quantum Technologies Inc. 2 | 3 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | """This package contains classes and functions for creating time-domain 16 | algorithms in Strawberry Fields.""" 17 | 18 | from .program import TDMProgram, reshape_samples, is_ptype, shift_by 19 | from .utils import ( 20 | borealis_gbs, 21 | full_compile, 22 | get_mode_indices, 23 | loop_phase_from_device, 24 | make_phases_compatible, 25 | make_squeezing_compatible, 26 | move_vac_modes, 27 | vacuum_padding, 28 | random_r, 29 | random_bs, 30 | to_args_list, 31 | to_args_dict, 32 | ) 33 | -------------------------------------------------------------------------------- /strawberryfields/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | This package defines and implements several utility functions and language 16 | extensions that complement StrawberryFields. 17 | """ 18 | from .decorators import * 19 | from .gbs_analysis import * 20 | from .post_processing import * 21 | from .program_functions import * 22 | from .random_numbers_matrices import * 23 | from .states import * 24 | -------------------------------------------------------------------------------- /strawberryfields/utils/gbs_analysis.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | # supercomputer benchmark parameters: 4 | # ``c`` is a scale factor in units of seconds, obtained by the LINPACK 5 | # benchmarks, satisfying 6 | 7 | # t = c * n**3 * 2 ** (n / 2) 8 | 9 | # where ``t`` is the time it takes to compute a Hafnian of size ``n x n`` on a 10 | # particular computer. 11 | 12 | # c.f. references 13 | # - L.S. Madsen et al., "Quantum computational advantage with a programmable 14 | # photonic processor", Nature (2022). 15 | # - A. Deshpande et al., "Quantum computational advantage via high-dimensional 16 | # Gaussian boson sampling", Science Adv. 8, eabi7894 (2022). 17 | c_niagara = 5.42e-15 18 | c_fugaku = c_niagara / 122.8 19 | 20 | 21 | def gbs_runtime(N_c, G, modes, c=c_fugaku): 22 | """Simulation time of a GBS sample (cf. L.S. Madsen et al., 23 | "Quantum computational advantage with a programmable photonic 24 | processor", Nature (2022).) 25 | 26 | Args: 27 | N_c (int): number of nonzero detector outcomes 28 | G (float): collision parameter 29 | modes (int): number of modes 30 | c (float): a supercomputer benchmark parameter (see reference 31 | above) 32 | 33 | Returns: 34 | float: runtime in seconds 35 | """ 36 | 37 | return 0.5 * c_fugaku * modes * N_c**3 * G ** (N_c / 2) 38 | 39 | 40 | def ncg(sample): 41 | """Calculates and returns the number of nonzero events ``N_c`` and the collision parameter ``G`` of 42 | a sample. 43 | 44 | Args: 45 | sample (array[int]): a photon-number array of shape 46 | ``(temporal_modes,)`` 47 | 48 | Returns: 49 | tuple[float]: the number of nonzero events ``N_c`` and the collision parameter ``G`` of a sample 50 | """ 51 | N_c = int(np.heaviside(sample, 0).sum()) 52 | 53 | # avoid division by 0 when `samples` has no photons 54 | if N_c != 0: 55 | G = np.prod(np.float64(sample) + 1) ** (1 / N_c) 56 | else: 57 | G = 1 58 | 59 | return N_c, G 60 | 61 | 62 | def gbs_sample_runtime(sample, c=c_fugaku, return_ncg=False): 63 | """Simulation time of a GBS sample (cf. L.S. Madsen et al., 64 | "Quantum computational advantage with a programmable photonic 65 | processor", Nature (2022)") 66 | 67 | Args: 68 | sample (array[int]): a photon-number array of shape 69 | ``(temporal_modes,)`` 70 | c (float): a supercomputer benchmark parameter (see reference 71 | above) 72 | return_ncg (bool): if ``True`` return not only runtime but also 73 | the number of non-zero detector events ``N_c`` and the 74 | collision parameter ``G`` 75 | 76 | Returns: 77 | float: the simulation time of a sample in seconds; 78 | if ``return_ncg`` also returns ``N_c`` and ``G`` 79 | """ 80 | N_c, G = ncg(sample) 81 | modes = len(sample) 82 | r = gbs_runtime(N_c, G, modes, c) 83 | 84 | if not return_ncg: 85 | return r 86 | return r, N_c, G 87 | -------------------------------------------------------------------------------- /tests/api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XanaduAI/strawberryfields/cc0a0e4b695f7584a629def02801285c9e7a9da2/tests/api/__init__.py -------------------------------------------------------------------------------- /tests/api/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | Test fixtures and shared functions for Strawberry Fields API tests 16 | """ 17 | import pytest 18 | 19 | import xcc 20 | 21 | from strawberryfields import Program, ops 22 | 23 | # pylint: disable=expression-not-assigned 24 | 25 | 26 | @pytest.fixture 27 | def prog(): 28 | """Program fixture.""" 29 | program = Program(8) 30 | with program.context as q: 31 | ops.Rgate(0.5) | q[0] 32 | ops.Rgate(0.5) | q[4] 33 | ops.MeasureFock() | q 34 | return program 35 | 36 | 37 | @pytest.fixture 38 | def connection() -> xcc.Connection: 39 | """A mock connection.""" 40 | return xcc.Connection(refresh_token="j.w.t", host="cloud.xanadu.ai", port=443, tls=True) 41 | 42 | 43 | def mock_return(return_value): 44 | """A helper function for defining a mock function that returns the given value for 45 | any arguments. 46 | """ 47 | return lambda *args, **kwargs: return_value 48 | -------------------------------------------------------------------------------- /tests/apps/conftest.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r""" 15 | conftest.py file for use in pytest 16 | """ 17 | import numpy as np 18 | import networkx as nx 19 | import pytest 20 | 21 | pytestmark = pytest.mark.apps 22 | 23 | 24 | @pytest.fixture 25 | def adj(dim: int): 26 | """Creates a fixed adjacency matrix of size ``dim`` with alternating zeros and nonzeros in a 27 | checkerboard pattern. 28 | 29 | The nonzero value is fixed to 0.5. This can, e.g., prevent issues with square roots, 30 | and also explore any problems with weighted graph edges. 31 | 32 | Args: 33 | dim (int): dimension of adjacency matrix 34 | 35 | Returns: 36 | array: NumPy adjacency matrix of dimension ``dim`` with each element a ``float``. 37 | """ 38 | a = np.zeros((dim, dim), dtype=float) 39 | 40 | a[1::2, ::2] = 0.5 41 | a[::2, 1::2] = 0.5 42 | 43 | return a 44 | 45 | 46 | @pytest.fixture 47 | def graph(dim: int): 48 | """Creates the NetworkX graph of ``dim`` nodes corresponding to the checkerboard adjacency 49 | matrix in :func:`adj` 50 | 51 | Args: 52 | dim (int): number of nodes in graph 53 | 54 | Returns: graph: NetworkX graph of dimension ``dim`` corresponding to the adjacency matrix in 55 | :func:`adj` 56 | """ 57 | 58 | a = np.zeros((dim, dim), dtype=float) 59 | 60 | a[1::2, ::2] = 0.5 61 | a[::2, 1::2] = 0.5 62 | 63 | return nx.Graph(a) 64 | -------------------------------------------------------------------------------- /tests/apps/qchem/gamess_dummy_m.out: -------------------------------------------------------------------------------- 1 | INPUT CARD> $contrl scftyp=rhf dfttyp=pbe0 runtyp=hessian ispher=1 nosym=1 $end 2 | INPUT CARD> $system mwords=100 $end 3 | INPUT CARD> $scf dirscf=.true. $end 4 | INPUT CARD> $cphf cphf=ao $end 5 | INPUT CARD> $basis gbasis=accd $end 6 | INPUT CARD> $guess guess=huckel $end 7 | INPUT CARD> $data 8 | INPUT CARD>title 9 | INPUT CARD>C1 10 | INPUT CARD> B 5.0 0.0000000000 0.0000000000 0.0000000000 11 | INPUT CARD> H 1.0 1.2536039000 0.0000000000 0.0000000000 12 | INPUT CARD> $end 13 | 14 | FREQUENCY: 22.29 22.29 1.11 1.11 1.11 15 | SYMMETRY: A A A A A 16 | REDUCED MASS: 1.13132 1.13132 4.01190 3.98654 3.98655 17 | 18 | 1 LI X -0.09313476 -0.09744023 0.00487611 0.32071597 0.14656112 19 | Y -0.09744043 0.09313474 0.00718194 -0.14663509 0.32063875 20 | Z -0.00000011 0.00000008 0.35292119 -0.00145020 -0.00856830 21 | 2 H X 0.64290518 0.67262689 0.00491752 0.32343679 0.14780464 22 | Y 0.67262669 -0.64290520 0.00724329 -0.14787897 0.32335945 23 | Z -0.00000011 0.00000008 0.35292067 -0.00145020 -0.00856829 24 | 25 | TRANS. SAYVETZ X -0.00549756 -0.00575045 0.03916677 2.57611096 1.17723404 26 | Y -0.00575206 0.00549737 0.05768848 -1.17782793 2.57549124 27 | Z -0.00000086 0.00000065 2.83177735 -0.01163619 -0.06875052 28 | TOTAL 0.00795671 0.00795543 2.83263569 2.83262453 2.83262453 29 | 30 | ROT. SAYVETZ X -1.97712918 1.88976521 -0.00015750 0.00319363 -0.00698533 31 | Y 1.88976521 1.97712919 0.00010634 0.00698563 0.00319269 32 | Z 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 33 | TOTAL 2.73500500 2.73500500 0.00019004 0.00768104 0.00768038 34 | 35 | 6 36 | FREQUENCY: 1689.90 37 | SYMMETRY: A 38 | REDUCED MASS: 1.12929 39 | 40 | 1 LI X -0.00000000 41 | Y -0.00000000 42 | Z -0.13380012 43 | 2 H X 0.00000000 44 | Y 0.00000000 45 | Z 0.93145437 46 | 47 | TRANS. SAYVETZ X -0.00000000 48 | Y -0.00000000 49 | Z 0.00000139 50 | TOTAL 0.00000139 51 | 52 | ROT. SAYVETZ X -0.00000000 53 | Y 0.00000000 54 | Z 0.00000000 55 | TOTAL 0.00000000 56 | -------------------------------------------------------------------------------- /tests/apps/qchem/gamess_dummy_r.out: -------------------------------------------------------------------------------- 1 | ATOMIC WEIGHTS (AMU) 2 | 3 | 1 B 11.00931 4 | 2 H 1.00782 5 | 6 | FREQUENCY: 22.29 22.29 1.11 1.11 1.11 7 | SYMMETRY: A A A A A 8 | REDUCED MASS: 1.13132 1.13132 4.01190 3.98654 3.98655 9 | 10 | 1 LI X -0.09313476 -0.09744023 0.00487611 0.32071597 0.14656112 11 | Y -0.09744043 0.09313474 0.00718194 -0.14663509 0.32063875 12 | Z -0.00000011 0.00000008 0.35292119 -0.00145020 -0.00856830 13 | 2 H X 0.64290518 0.67262689 0.00491752 0.32343679 0.14780464 14 | Y 0.67262669 -0.64290520 0.00724329 -0.14787897 0.32335945 15 | Z -0.00000011 0.00000008 0.35292067 -0.00145020 -0.00856829 16 | 17 | TRANS. SAYVETZ X -0.00549756 -0.00575045 0.03916677 2.57611096 1.17723404 18 | Y -0.00575206 0.00549737 0.05768848 -1.17782793 2.57549124 19 | Z -0.00000086 0.00000065 2.83177735 -0.01163619 -0.06875052 20 | TOTAL 0.00795671 0.00795543 2.83263569 2.83262453 2.83262453 21 | 22 | ROT. SAYVETZ X -1.97712918 1.88976521 -0.00015750 0.00319363 -0.00698533 23 | Y 1.88976521 1.97712919 0.00010634 0.00698563 0.00319269 24 | Z 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 25 | TOTAL 2.73500500 2.73500500 0.00019004 0.00768104 0.00768038 26 | 27 | 6 28 | FREQUENCY: 1689.90 29 | SYMMETRY: A 30 | REDUCED MASS: 1.12929 31 | 32 | 1 LI X -0.00000000 33 | Y -0.00000000 34 | Z -0.13380012 35 | 2 H X 0.00000000 36 | Y 0.00000000 37 | Z 0.93145437 38 | 39 | TRANS. SAYVETZ X -0.00000000 40 | Y -0.00000000 41 | Z 0.00000139 42 | TOTAL 0.00000139 43 | 44 | ROT. SAYVETZ X -0.00000000 45 | Y 0.00000000 46 | Z 0.00000000 47 | TOTAL 0.00000000 48 | -------------------------------------------------------------------------------- /tests/apps/qchem/gamess_dummy_w.out: -------------------------------------------------------------------------------- 1 | INPUT CARD> $contrl scftyp=rhf dfttyp=pbe0 runtyp=hessian ispher=1 nosym=1 $end 2 | INPUT CARD> $system mwords=100 $end 3 | INPUT CARD> $scf dirscf=.true. $end 4 | INPUT CARD> $cphf cphf=ao $end 5 | INPUT CARD> $basis gbasis=accd $end 6 | INPUT CARD> $guess guess=huckel $end 7 | INPUT CARD> $data 8 | INPUT CARD>title 9 | INPUT CARD>C1 10 | INPUT CARD> B 5.0 0.0000000000 0.0000000000 0.0000000000 11 | INPUT CARD> H 1.0 1.2536039000 0.0000000000 0.0000000000 12 | INPUT CARD> $end 13 | 14 | ATOMIC WEIGHTS (AMU) 15 | 16 | 1 B 11.00931 17 | 2 H 1.00782 -------------------------------------------------------------------------------- /tests/apps/test_plot.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r""" 15 | Unit tests for strawberryfields.apps.plot 16 | """ 17 | # pylint: disable=no-self-use,unused-argument,too-many-arguments,protected-access 18 | import networkx as nx 19 | import numpy as np 20 | import pytest 21 | 22 | from strawberryfields.apps import plot 23 | 24 | pytestmark = pytest.mark.apps 25 | 26 | 27 | class TestNodeCoords: 28 | """Test for the internal function strawberryfields.apps.plot._node_coords""" 29 | 30 | @pytest.mark.parametrize("dim", [4, 5, 6]) 31 | def test_complete_graph(self, dim): 32 | """Tests that nodes in a complete graph are located in the unit circle when using the 33 | Kamada-Kawai layout""" 34 | graph = nx.complete_graph(dim) 35 | layout = nx.kamada_kawai_layout(graph) 36 | coords = plot._node_coords(graph, layout) 37 | x = coords["x"] 38 | y = coords["y"] 39 | radii = [np.sqrt(x[i] ** 2 + y[i] ** 2) for i in range(dim)] 40 | 41 | assert np.allclose(radii, np.ones(dim), atol=1e-5) 42 | 43 | def test_custom_layout(self): 44 | """Tests that nodes in a complete graph are correctly located based on a custom layout""" 45 | graph = nx.complete_graph(4) 46 | layout = {0: [1, 1], 1: [1, -1], 2: [-1, 1], 3: [-1, -1]} 47 | coords = plot._node_coords(graph, layout) 48 | x = coords["x"] 49 | y = coords["y"] 50 | 51 | assert x == [1, 1, -1, -1] 52 | assert y == [1, -1, 1, -1] 53 | 54 | 55 | class TestEdgeCoords: 56 | """Test for the internal function strawberryfields.apps.plot._edge_coords""" 57 | 58 | @pytest.mark.parametrize("dim", [4, 5, 6]) 59 | def test_cycle_graph(self, dim): 60 | """Tests that the length of edges in a circular cycle graph are all of equal length.""" 61 | graph = nx.cycle_graph(dim) 62 | layout = nx.kamada_kawai_layout(graph) 63 | coords = plot._edge_coords(graph, layout) 64 | x = coords["x"] 65 | y = coords["y"] 66 | dists = [ 67 | np.sqrt((x[3 * k] - x[3 * k + 1]) ** 2 + (y[3 * k] - y[3 * k + 1]) ** 2) 68 | for k in range(dim) 69 | ] 70 | first_dist = np.sqrt((x[0] - x[1]) ** 2 + (y[0] - y[1]) ** 2) 71 | 72 | assert np.allclose(dists, first_dist) 73 | 74 | def test_custom_layout(self): 75 | """Tests that edges in a complete graph are correctly located based on a custom layout""" 76 | graph = nx.complete_graph(2) 77 | layout = {0: [1, 1], 1: [-1, -1]} 78 | coords = plot._edge_coords(graph, layout) 79 | x = coords["x"] 80 | y = coords["y"] 81 | print(x) 82 | print(y) 83 | 84 | assert x[:2] == [1, -1] 85 | assert y[:2] == [1, -1] 86 | 87 | 88 | def test_spectrum_invalid_energies(): 89 | """Test if function `plot.spectrum` raises a ``ValueError`` when the number of sampled energies 90 | is less than two""" 91 | with pytest.raises(ValueError, match="Number of sampled energies must be at least two"): 92 | plot.spectrum([1000.0]) 93 | -------------------------------------------------------------------------------- /tests/apps/test_points.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Tests for the the point process functions""" 15 | 16 | import pytest 17 | import numpy as np 18 | from strawberryfields.apps.points import rbf_kernel, sample 19 | 20 | 21 | pytestmark = pytest.mark.apps 22 | 23 | 24 | def test_rbf_kernel(): 25 | r"""Tests the correctness of the RBF kernel matrix generated for a given set of point 26 | coordinates""" 27 | 28 | R = np.array([[0, 1], [1, 0], [0, 0], [1, 1]]) 29 | K = rbf_kernel(R, 1.0) 30 | Kref = np.array( 31 | [ 32 | [1.0, 0.36787944, 0.60653066, 0.60653066], 33 | [0.36787944, 1.0, 0.60653066, 0.60653066], 34 | [0.60653066, 0.60653066, 1.0, 0.36787944], 35 | [0.60653066, 0.60653066, 0.36787944, 1.0], 36 | ] 37 | ) 38 | 39 | assert np.allclose(K, Kref) 40 | 41 | 42 | def test_sample(): 43 | r"""Tests that the generated samples have the correct dimension""" 44 | 45 | Kref = np.array( 46 | [ 47 | [1.0, 0.36787944, 0.60653066, 0.60653066], 48 | [0.36787944, 1.0, 0.60653066, 0.60653066], 49 | [0.60653066, 0.60653066, 1.0, 0.36787944], 50 | [0.60653066, 0.60653066, 0.36787944, 1.0], 51 | ] 52 | ) 53 | samples = sample(Kref, 1, 10) 54 | shape = np.array(samples).shape 55 | shape_ref = (10, 4) 56 | 57 | assert shape == shape_ref 58 | -------------------------------------------------------------------------------- /tests/backend/test_displacement_operation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | r""" 16 | Unit tests for displacement operations 17 | Convention: The displacement unitary is fixed to be 18 | U(\alpha) = \exp(alpha \hat{a}^\dagger - \alpha^* \hat{a}) 19 | where \hat{a}^\dagger is the photon creation operator. 20 | """ 21 | # pylint: disable=too-many-arguments 22 | import pytest 23 | 24 | import numpy as np 25 | from scipy.special import factorial as fac 26 | 27 | 28 | MAG_ALPHAS = np.linspace(0, 0.8, 4) 29 | PHASE_ALPHAS = np.linspace(0, 2 * np.pi, 7, endpoint=False) 30 | 31 | 32 | class TestRepresentationIndependent: 33 | """Basic implementation-independent tests.""" 34 | 35 | def test_no_displacement(self, setup_backend, tol): 36 | """Tests displacement operation where the result should be a vacuum state.""" 37 | backend = setup_backend(1) 38 | backend.displacement(0, 0, 0) 39 | assert np.all(backend.is_vacuum(tol)) 40 | 41 | @pytest.mark.parametrize("r", MAG_ALPHAS) 42 | @pytest.mark.parametrize("p", PHASE_ALPHAS) 43 | def test_fidelity_coherent(self, setup_backend, r, p, tol): 44 | """Tests if a range of alpha-displaced states have the correct fidelity 45 | with the corresponding coherent state. 46 | """ 47 | alpha = r * np.exp(1j * p) 48 | 49 | backend = setup_backend(1) 50 | backend.displacement(r, p, 0) 51 | state = backend.state() 52 | 53 | fid = state.fidelity_coherent([alpha]) 54 | assert np.allclose(fid, 1, atol=tol, rtol=0) 55 | 56 | 57 | @pytest.mark.backends("fock", "tf") 58 | class TestFockRepresentation: 59 | """Tests that make use of the Fock basis representation.""" 60 | 61 | @pytest.mark.parametrize("r", MAG_ALPHAS) 62 | @pytest.mark.parametrize("p", PHASE_ALPHAS) 63 | def test_normalized_displaced_state(self, setup_backend, r, p, tol): 64 | """Tests if a range of displaced states are normalized.""" 65 | 66 | backend = setup_backend(1) 67 | backend.displacement(r, p, 0) 68 | state = backend.state() 69 | 70 | assert np.allclose(state.trace(), 1, atol=tol, rtol=0) 71 | 72 | @pytest.mark.parametrize("r", MAG_ALPHAS) 73 | @pytest.mark.parametrize("p", PHASE_ALPHAS) 74 | def test_coherent_state_fock_elements(self, setup_backend, r, p, cutoff, pure, tol): 75 | r"""Tests if a range of alpha-displaced states have the correct Fock basis elements: 76 | |\alpha> = exp(-0.5 |\alpha|^2) \sum_n \alpha^n / \sqrt{n!} |n> 77 | """ 78 | 79 | backend = setup_backend(1) 80 | backend.displacement(r, p, 0) 81 | state = backend.state() 82 | 83 | if state.is_pure: 84 | numer_state = state.ket() 85 | else: 86 | numer_state = state.dm() 87 | 88 | n = np.arange(cutoff) 89 | ref_state = np.exp(-0.5 * r**2) * (r * np.exp(1j * p)) ** n / np.sqrt(fac(n)) 90 | 91 | if not pure: 92 | ref_state = np.outer(ref_state, np.conj(ref_state)) 93 | 94 | assert np.allclose(numer_state, ref_state, atol=tol, rtol=0) 95 | -------------------------------------------------------------------------------- /tests/backend/test_gaussian_cptp.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | r"""Unit test for Gaussian CPTP map 16 | """ 17 | 18 | 19 | import pytest 20 | 21 | import numpy as np 22 | 23 | LOSS_TS = np.linspace(0.0, 1, 3, endpoint=True) 24 | DISPS = np.linspace(0.0, 5, 3, endpoint=True) 25 | PHIS = np.linspace(0.0, np.pi / 2, 3, endpoint=True) 26 | 27 | 28 | @pytest.mark.backends("bosonic") 29 | @pytest.mark.parametrize("r", DISPS) 30 | @pytest.mark.parametrize("phi", PHIS) 31 | class TestGaussianCPTP: 32 | """Tests that Gaussian CPTP channels applied to bosonic states work.""" 33 | 34 | @pytest.mark.parametrize("T", LOSS_TS) 35 | def test_cptp_vs_loss(self, T, r, phi, setup_backend, tol): 36 | """Tests loss channel and associated Gaussian CPTP produce same output.""" 37 | backend = setup_backend(1) 38 | backend.prepare_coherent_state(r, phi, 0) 39 | backend.loss(T, 0) 40 | state1 = backend.state(0) 41 | backend.reset() 42 | backend.prepare_coherent_state(r, phi, 0) 43 | X = np.sqrt(T) * np.identity(2) 44 | Y = (1 - T) * np.identity(2) 45 | backend.gaussian_cptp(0, X, Y) 46 | state2 = backend.state(0) 47 | 48 | assert np.allclose(state1.means(), state2.means(), atol=tol, rtol=0) 49 | assert np.allclose(state1.covs(), state2.covs(), atol=tol, rtol=0) 50 | 51 | def test_cptp_vs_phaseshift(self, r, phi, setup_backend, tol): 52 | """Tests phase shift and associated Gaussian CPTP produce same output.""" 53 | backend = setup_backend(1) 54 | backend.prepare_coherent_state(r, 0, 0) 55 | backend.rotation(phi, 0) 56 | state1 = backend.state(0) 57 | backend.reset() 58 | backend.prepare_coherent_state(r, 0, 0) 59 | X = np.array([[np.cos(phi), -np.sin(phi)], [np.sin(phi), np.cos(phi)]]) 60 | backend.gaussian_cptp(0, X) 61 | state2 = backend.state(0) 62 | 63 | assert np.allclose(state1.means(), state2.means(), atol=tol, rtol=0) 64 | assert np.allclose(state1.covs(), state2.covs(), atol=tol, rtol=0) 65 | -------------------------------------------------------------------------------- /tests/backend/test_heterodyne.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Unit tests for heterodyne measurements.""" 15 | import pytest 16 | 17 | import numpy as np 18 | 19 | mag_alphas = np.linspace(0, 0.8, 4) 20 | phase_alphas = np.linspace(0, 2 * np.pi, 7, endpoint=False) 21 | squeeze_val = np.arcsinh(1.0) 22 | 23 | n_meas = 500 24 | disp_val = 1.0 + 1j * 1.0 25 | num_stds = 10.0 26 | std_10 = num_stds / np.sqrt(n_meas) 27 | R_VALS = [-1.2, 0, 1, 1.4] 28 | 29 | 30 | @pytest.mark.backends("gaussian", "bosonic") 31 | class TestHeterodyne: 32 | """Basic implementation-independent tests.""" 33 | 34 | def test_mode_reset_vacuum(self, setup_backend, tol): 35 | """Test heterodyne measurement resets mode to vacuum""" 36 | backend = setup_backend(1) 37 | backend.squeeze(squeeze_val, 0, 0) 38 | backend.displacement(mag_alphas[-1], 0, 0) 39 | backend.measure_homodyne(0, 0) 40 | assert np.all(backend.is_vacuum(tol)) 41 | 42 | def test_mean_vacuum(self, setup_backend, pure, tol): 43 | """Test heterodyne provides the correct vacuum mean""" 44 | backend = setup_backend(1) 45 | x = np.empty(0) 46 | 47 | for i in range(n_meas): 48 | backend.reset(pure=pure) 49 | meas_result = backend.measure_heterodyne(0) 50 | x = np.append(x, meas_result) 51 | 52 | mean_diff = np.abs(x.mean() - 0) 53 | 54 | assert np.allclose(x.mean(), 0.0, atol=std_10 + tol, rtol=0) 55 | 56 | def test_mean_coherent(self, setup_backend, pure, tol): 57 | """Test heterodyne provides the correct coherent mean alpha""" 58 | backend = setup_backend(1) 59 | x = np.empty(0) 60 | 61 | for i in range(n_meas): 62 | backend.reset(pure=pure) 63 | backend.prepare_coherent_state(np.abs(disp_val), np.angle(disp_val), 0) 64 | meas_result = backend.measure_heterodyne(0) 65 | x = np.append(x, meas_result) 66 | 67 | assert np.allclose(x.mean(), disp_val, atol=std_10 + tol, rtol=0) 68 | 69 | @pytest.mark.parametrize("r", R_VALS) 70 | def test_std(self, r, setup_backend, pure, tol): 71 | """Test heterodyne provides the correct standard deviation for heterodyne outcomes on 72 | squeezed states""" 73 | backend = setup_backend(1) 74 | x = np.empty(0) 75 | 76 | for i in range(n_meas): 77 | backend.reset(pure=pure) 78 | backend.prepare_squeezed_state(r, 0, 0) 79 | meas_result = backend.measure_heterodyne(0) 80 | x = np.append(x, meas_result) 81 | 82 | xr = x.real 83 | xi = x.imag 84 | 85 | assert np.allclose(xr.std(), np.sqrt(1 + np.exp(-2 * r)) / 2, atol=std_10 + tol, rtol=0) 86 | assert np.allclose(xi.std(), np.sqrt(1 + np.exp(2 * r)) / 2, atol=std_10 + tol, rtol=0) 87 | -------------------------------------------------------------------------------- /tests/backend/test_homodyne.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | r"""Unit tests for homodyne measurements.""" 16 | import numpy as np 17 | 18 | 19 | N_MEAS = 300 # number of homodyne measurements to perform 20 | NUM_STDS = 10.0 21 | std_10 = NUM_STDS / np.sqrt(N_MEAS) 22 | 23 | 24 | class TestRepresentationIndependent: 25 | """Basic implementation-independent tests.""" 26 | 27 | def test_mode_reset_vacuum(self, setup_backend, tol): 28 | """Tests that modes get reset to the vacuum after measurement.""" 29 | backend = setup_backend(1) 30 | 31 | r = np.arcsinh(1.0) # pylint: disable=assignment-from-no-return 32 | alpha = 0.8 33 | 34 | backend.squeeze(r, 0.0, 0) 35 | backend.displacement(np.abs(alpha), np.angle(alpha), 0) 36 | backend.measure_homodyne(0, 0) 37 | 38 | assert np.all(backend.is_vacuum(tol)) 39 | 40 | def test_mean_and_std_vacuum(self, setup_backend, pure, tol): 41 | """Tests that the mean and standard deviation estimates of many homodyne 42 | measurements are in agreement with the expected values for the 43 | vacuum state""" 44 | x = np.empty(0) 45 | 46 | backend = setup_backend(1) 47 | 48 | for _ in range(N_MEAS): 49 | backend.reset(pure=pure) 50 | meas_result = backend.measure_homodyne(0, 0) 51 | x = np.append(x, meas_result) 52 | 53 | assert np.allclose(x.mean(), 0.0, atol=std_10 + tol, rtol=0) 54 | assert np.allclose(x.std(), 1.0, atol=std_10 + tol, rtol=0) 55 | 56 | def test_mean_coherent(self, setup_backend, pure, tol): 57 | """Tests that the mean and standard deviation estimates of many homodyne 58 | measurements are in agreement with the expected values for a 59 | coherent state""" 60 | alpha = 1.0 + 1.0j 61 | x = np.empty(0) 62 | 63 | backend = setup_backend(1) 64 | 65 | for _ in range(N_MEAS): 66 | backend.reset(pure=pure) 67 | backend.prepare_coherent_state(np.abs(alpha), np.angle(alpha), 0) 68 | 69 | meas_result = backend.measure_homodyne(0, 0) 70 | x = np.append(x, meas_result) 71 | 72 | assert np.allclose(x.mean(), 2 * alpha.real, atol=std_10 + tol) 73 | -------------------------------------------------------------------------------- /tests/backend/test_is_vacuum.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | """ 16 | Unit tests for the is_vacuum() check. 17 | """ 18 | 19 | import pytest 20 | 21 | import numpy as np 22 | 23 | 24 | MAG_ALPHAS = np.linspace(0, 0.8, 3) 25 | 26 | 27 | class TestIsVacuum: 28 | """Common tests for all the backends.""" 29 | 30 | @pytest.mark.parametrize("r", MAG_ALPHAS) 31 | def test_coherent_state(self, setup_backend, r, tol): 32 | """Tests if a range of displaced states are within the expected tolerance from vacuum.""" 33 | # fidelity of the displaced state with |0> 34 | fid = np.exp(-np.abs(r) ** 2) 35 | # expected tolerance limit for the test 36 | lim = np.abs(fid - 1) 37 | 38 | backend = setup_backend(1) 39 | backend.displacement(r, 0, 0) 40 | assert not np.any(backend.is_vacuum(lim - tol)) 41 | assert np.all(backend.is_vacuum(lim + tol)) 42 | -------------------------------------------------------------------------------- /tests/backend/test_mbsqueeze_operation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r""" 15 | Unit tests for mbsqueezing operation in the bosonic backend. 16 | """ 17 | # pylint: disable=too-many-arguments 18 | import pytest 19 | 20 | import numpy as np 21 | 22 | 23 | PHASE = np.linspace(0, 2 * np.pi, 3, endpoint=False) 24 | MAG = np.linspace(0.0, 1, 5, endpoint=False) 25 | ETA = np.linspace(0.5, 1, 3) 26 | ANCMAG = np.linspace(0.0, 1, 5, endpoint=False) 27 | 28 | 29 | @pytest.mark.backends("bosonic") 30 | class TestBosonicRepresentation: 31 | """Basic tests for the mbsqueezing operation in the bosonic backend.""" 32 | 33 | @pytest.mark.parametrize("r_anc", ANCMAG) 34 | @pytest.mark.parametrize("eta", ETA) 35 | def test_avg_zero_mbsqueezing(self, setup_backend, r_anc, eta, tol): 36 | """Tests average map of mbsqueezing operation for no squeezing, 37 | where the result should be a vacuum state.""" 38 | backend = setup_backend(2) 39 | backend.mb_squeeze_avg(0, 0, 0, r_anc, eta) 40 | backend.squeeze(0, 0, 1) 41 | assert np.allclose( 42 | backend.circuit.covs[0, :2, :2], backend.circuit.covs[0, 2:, 2:], atol=tol 43 | ) 44 | 45 | @pytest.mark.parametrize("r", MAG) 46 | @pytest.mark.parametrize("phi", PHASE) 47 | def test_avg_mbsqueezing(self, setup_backend, r, phi, tol): 48 | """Tests average map of mbsqueezing operation with a high squeezed ancilla, 49 | where the result should be an ideal state.""" 50 | backend = setup_backend(2) 51 | backend.mb_squeeze_avg(0, r, phi, 9, 1.0) 52 | backend.squeeze(r, phi, 1) 53 | assert np.allclose( 54 | backend.circuit.covs[0, :2, :2], backend.circuit.covs[0, 2:, 2:], atol=tol 55 | ) 56 | 57 | @pytest.mark.parametrize("r_anc", ANCMAG) 58 | @pytest.mark.parametrize("eta", ETA) 59 | def test_singleshot_zero_mbsqueezing(self, setup_backend, r_anc, eta, tol): 60 | """Tests single shot map of mbsqueezing operation for no squeezing, 61 | where the result should be a vacuum state.""" 62 | backend = setup_backend(2) 63 | backend.mb_squeeze_single_shot(0, 0, 0, r_anc, eta) 64 | backend.squeeze(0, 0, 1) 65 | assert np.allclose( 66 | backend.circuit.covs[0, :2, :2], backend.circuit.covs[0, 2:, 2:], atol=tol 67 | ) 68 | 69 | @pytest.mark.parametrize("r", MAG) 70 | @pytest.mark.parametrize("phi", PHASE) 71 | def test_singleshot_mbsqueezing(self, setup_backend, r, phi, tol): 72 | """Tests single shot map of mbsqueezing operation with a high squeezed ancilla, 73 | where the result should be an ideal state.""" 74 | backend = setup_backend(2) 75 | backend.mb_squeeze_single_shot(0, r, phi, 9, 1.0) 76 | backend.squeeze(r, phi, 1) 77 | assert np.allclose( 78 | backend.circuit.covs[0, :2, :2], backend.circuit.covs[0, 2:, 2:], atol=tol 79 | ) 80 | -------------------------------------------------------------------------------- /tests/backend/test_postselection.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""tests for backend postselection""" 15 | import pytest 16 | 17 | import numpy as np 18 | 19 | 20 | def test_homodyne(setup_backend, tol): 21 | """Test that homodyne detection on a TMS state 22 | returns post-selected value.""" 23 | x = 0.2 24 | r = 5 25 | 26 | backend = setup_backend(2) 27 | backend.squeeze(r, 0, 0) 28 | backend.squeeze(-r, 0, 1) 29 | backend.beamsplitter(np.pi / 4, 0, 0, 1) 30 | 31 | res = backend.measure_homodyne(0, mode=0, select=0.2) 32 | assert np.allclose(res, x, atol=tol, rtol=0) 33 | 34 | 35 | @pytest.mark.backends("gaussian", "bosonic") 36 | def test_heterodyne(setup_backend, tol): 37 | """Test that heterodyne detection on a TMS state 38 | returns post-selected value.""" 39 | alpha = 0.43 - 0.12j 40 | r = 5 41 | 42 | backend = setup_backend(2) 43 | backend.squeeze(r, 0, 0) 44 | backend.squeeze(-r, 0, 1) 45 | backend.beamsplitter(np.pi / 4, 0, 0, 1) 46 | 47 | res = backend.measure_heterodyne(mode=0, select=alpha) 48 | assert np.allclose(res, alpha, atol=tol, rtol=0) 49 | 50 | 51 | @pytest.mark.backends("fock", "tf") 52 | def test_measure_fock(setup_backend, cutoff, batch_size): 53 | """Test that Fock post-selection on Fock states 54 | exiting one arm of a beamsplitter results in conservation 55 | of photon number in the other.""" 56 | backend = setup_backend(2) 57 | 58 | for n in range(cutoff - 1): 59 | total_photons = cutoff - 1 60 | 61 | backend.prepare_fock_state(n, 0) 62 | backend.prepare_fock_state(total_photons - n, 1) 63 | backend.beamsplitter(np.pi / 4, 0, 0, 1) 64 | res1 = backend.measure_fock([0], select=[cutoff // 2]) 65 | res2 = backend.measure_fock([1]) 66 | 67 | photons_out = res1 + res2 68 | 69 | if batch_size is not None: 70 | total_photons = np.tile(total_photons, batch_size) 71 | 72 | assert np.all(photons_out == total_photons) 73 | -------------------------------------------------------------------------------- /tests/backend/test_rotation_operation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | r"""Unit tests for phase-shifter operations 16 | Convention: The phase-shift unitary is fixed to be 17 | U(\theta) = \exp(i * \theta \hat{n}) 18 | where \hat{n} is the number operator. For positive \theta, this corresponds 19 | to a clockwise rotation of the state in phase space.""" 20 | 21 | import pytest 22 | 23 | import numpy as np 24 | 25 | SHIFT_THETAS = np.linspace(0, 2 * np.pi, 7, endpoint=False) 26 | 27 | 28 | class TestRepresentationIndependent: 29 | """Basic implementation-independent tests.""" 30 | 31 | @pytest.mark.parametrize("theta", SHIFT_THETAS) 32 | def test_rotated_vacuum(self, setup_backend, theta, tol): 33 | """Tests phase shift operation in some limiting cases where the result should be a vacuum state.""" 34 | backend = setup_backend(1) 35 | backend.rotation(theta, 0) 36 | assert np.all(backend.is_vacuum(tol)) 37 | 38 | 39 | @pytest.mark.backends("fock", "tf") 40 | class TestFockRepresentation: 41 | """Tests that make use of the Fock basis representation.""" 42 | 43 | @pytest.mark.parametrize("theta", SHIFT_THETAS) 44 | def test_normalized_rotated_coherent_states(self, setup_backend, theta, tol): 45 | """Tests if a range of phase-shifted coherent states are normalized.""" 46 | r = 1.0 47 | backend = setup_backend(1) 48 | 49 | backend.prepare_coherent_state(r, 0, 0) 50 | backend.rotation(theta, 0) 51 | 52 | state = backend.state() 53 | tr = state.trace() 54 | assert np.allclose(tr, 1.0, atol=tol, rtol=0.0) 55 | 56 | @pytest.mark.parametrize("theta", SHIFT_THETAS) 57 | def test_rotated_fock_states(self, setup_backend, theta, pure, cutoff, tol): 58 | """Tests if a range of phase-shifted fock states |n> are equal to the form of 59 | exp(i * theta * n)|n>""" 60 | backend = setup_backend(1) 61 | 62 | for n in range(cutoff): 63 | backend.reset(pure=pure) 64 | 65 | backend.prepare_fock_state(n, 0) 66 | backend.rotation(theta, 0) 67 | s = backend.state() 68 | 69 | if s.is_pure: 70 | numer_state = s.ket() 71 | else: 72 | numer_state = s.dm() 73 | 74 | k = np.arange(cutoff) 75 | ref_state = np.where(k == n, np.exp(1j * theta * k), 0) 76 | 77 | if not pure: 78 | ref_state = np.outer(ref_state, np.conj(ref_state)) 79 | 80 | assert np.allclose(numer_state, ref_state, atol=tol, rtol=0.0) 81 | -------------------------------------------------------------------------------- /tests/backend/test_tf_import.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Unit tests for TensorFlow 2.x version checking""" 15 | import sys 16 | from unittest.mock import MagicMock 17 | 18 | import pytest 19 | 20 | import strawberryfields as sf 21 | 22 | try: 23 | import tensorflow 24 | 25 | except ImportError: 26 | tf_available = False 27 | 28 | else: 29 | tf_available = True 30 | 31 | 32 | @pytest.mark.frontend 33 | class TestFrontendImport: 34 | """Test importing via the frontend""" 35 | 36 | def test_incorrect_tf_version(self, monkeypatch): 37 | """Test that an exception is raised if the version 38 | of TensorFlow installed is not version 2.x""" 39 | with monkeypatch.context() as m: 40 | # Force the Python check to pass. 41 | m.setattr(sys, "version_info", (3, 6, 3)) 42 | 43 | # Unload the TF backend to ensure sf.LocalEngine() will run __init__.py. 44 | m.delitem(sys.modules, "strawberryfields.backends.tfbackend", raising=False) 45 | # Set the TF version in case the existing version is valid. 46 | m.setitem(sys.modules, "tensorflow", MagicMock(__version__="1.2.3")) 47 | 48 | with pytest.raises(ImportError, match="version 2.x of TensorFlow is required"): 49 | sf.LocalEngine("tf") 50 | 51 | @pytest.mark.skipif(tf_available, reason="Test only works if TF not installed") 52 | def test_tensorflow_not_installed(self, monkeypatch): 53 | """Test that an exception is raised if TensorFlow is not installed""" 54 | with monkeypatch.context() as m: 55 | # Force the Python check to pass. 56 | m.setattr(sys, "version_info", (3, 6, 3)) 57 | 58 | with pytest.raises(ImportError, match="version 2.x of TensorFlow is required"): 59 | sf.LocalEngine("tf") 60 | -------------------------------------------------------------------------------- /tests/backend/test_tf_ops.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r""" Tests for the file tfbackend/ops.py""" 15 | 16 | import pytest 17 | 18 | import numpy as np 19 | 20 | tf = pytest.importorskip("tensorflow", minversion="2.0") 21 | 22 | from strawberryfields.backends.tfbackend.ops import reduced_density_matrix 23 | 24 | 25 | @pytest.mark.backends("tf") 26 | class TestTFOps: 27 | """Testing for tfbackend/ops.py""" 28 | 29 | @pytest.mark.parametrize("num_modes", [2, 3, 4]) 30 | def test_reduced_density_matrix_fock_states(self, num_modes, setup_backend, cutoff, tol): 31 | """Test the reduced_density_matrix returns the correct reduced density matrices 32 | when prepared with initial fock states""" 33 | 34 | zero_photon_state = np.zeros([cutoff]) 35 | zero_photon_state[0] = 1.0 36 | one_photon_state = np.zeros([cutoff]) 37 | one_photon_state[1] = 1.0 38 | 39 | # create a single-photon state in the second mode 40 | state = np.outer(zero_photon_state, one_photon_state) 41 | for _ in range(2, num_modes): 42 | state = np.multiply.outer(state, zero_photon_state) 43 | state = tf.constant(state) 44 | 45 | # get reduced density matrix of last subsystem 46 | mode = num_modes - 1 47 | reduced_dm = reduced_density_matrix(state, mode, state_is_pure=True) 48 | 49 | if num_modes == 2: 50 | expected = np.multiply.outer(one_photon_state, one_photon_state) 51 | else: 52 | expected = np.multiply.outer(zero_photon_state, zero_photon_state) 53 | expected = tf.constant(expected) 54 | 55 | assert np.allclose(reduced_dm, expected, atol=tol, rtol=0) 56 | 57 | @pytest.mark.parametrize( 58 | "modes,einstr", 59 | [ 60 | ([0], "abccee->ab"), 61 | ([1], "aacdee->cd"), 62 | ([2], "aaccef->ef"), 63 | ([0, 1], "abcdee->abcd"), 64 | ([0, 2], "abccef->abef"), 65 | ([1, 2], "aacdef->cdef"), 66 | ([0, 1, 2], "abcdef->abcdef"), 67 | ], 68 | ) 69 | def test_reduced_density_matrix_multiple_modes(self, setup_backend, cutoff, modes, einstr, tol): 70 | """Test that reduced_density_matrix returns the correct reduced density matrices.""" 71 | state = np.zeros([cutoff, cutoff, cutoff]) 72 | state[0, 0, 0] = 1 / np.sqrt(2) 73 | state[1, 1, 1] = 1 / np.sqrt(2) 74 | state = np.multiply.outer(state, state.conj()) 75 | 76 | # transpose the state due to different conventions 77 | state = state.transpose([0, 3, 1, 4, 2, 5]) 78 | state = tf.constant(state) 79 | 80 | reduced_dm = reduced_density_matrix(state, modes, state_is_pure=False) 81 | expected = tf.constant(np.einsum(einstr, state)) 82 | 83 | assert np.allclose(reduced_dm, expected, atol=tol, rtol=0) 84 | -------------------------------------------------------------------------------- /tests/frontend/compilers/test_gaussianmerge.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Unit tests for the GaussianMerge class""" 15 | 16 | import pytest 17 | import numpy as np 18 | 19 | import strawberryfields as sf 20 | import strawberryfields.ops as ops 21 | 22 | pytestmark = pytest.mark.frontend 23 | 24 | 25 | @pytest.mark.parametrize( 26 | "init", [(1, 1, 1, 1), (0, 2, 1, 0), (0, 1, 1, 1), (0, 1, 0, 3), (0, 0, 0, 0)] 27 | ) 28 | def test_complex(init): 29 | modes = 4 30 | cutoff_dim = 6 31 | 32 | initial_state = np.zeros([cutoff_dim] * modes, dtype=complex) 33 | # The ket below corresponds to a single photon going into each of the modes 34 | initial_state[init] = 1 35 | 36 | prog = sf.Program(modes) 37 | s_d_params = 0.01 38 | with prog.context as q: 39 | ops.Ket(initial_state) | q # Initial state preparation 40 | # Gaussian Layer 41 | ops.S2gate(s_d_params, s_d_params) | (q[0], q[1]) 42 | ops.BSgate(1.9, 1.7) | (q[1], q[2]) 43 | ops.BSgate(0.9, 0.2) | (q[0], q[1]) 44 | # Non-Gaussian Layer 45 | ops.Kgate(0.5) | q[3] 46 | ops.CKgate(0.7) | (q[2], q[3]) 47 | # Gaussian Layer 48 | ops.BSgate(1.0, 0.4) | (q[0], q[1]) 49 | ops.BSgate(2.0, 1.5) | (q[1], q[2]) 50 | ops.Dgate(s_d_params) | q[0] 51 | ops.Dgate(s_d_params) | q[0] 52 | ops.Sgate(s_d_params, s_d_params) | q[1] 53 | # Non-Gaussian Layer 54 | ops.Vgate(0.5) | q[2] 55 | 56 | # We run the simulation 57 | eng = sf.Engine("fock", backend_options={"cutoff_dim": cutoff_dim}) 58 | results_norm = eng.run(prog) 59 | prog_merged = prog.compile(compiler="gaussian_merge") 60 | results_merged = eng.run(prog_merged) 61 | ket = results_norm.state.ket() 62 | ket_merged = results_merged.state.ket() 63 | assert np.allclose(np.abs(np.sum(np.conj(ket) * ket_merged)), 1) 64 | -------------------------------------------------------------------------------- /tests/frontend/compilers/test_xstrict.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Unit tests for the Xstrict compiler""" 15 | import pytest 16 | 17 | import strawberryfields as sf 18 | from strawberryfields import ops 19 | from strawberryfields.program_utils import program_equivalence 20 | 21 | from conftest import X8_device, generate_X8_params 22 | 23 | pytestmark = pytest.mark.frontend 24 | 25 | 26 | class TestCompilation: 27 | """Tests for compilation using the X8_01 circuit specification""" 28 | 29 | def test_exact_template(self, tol): 30 | """Test compilation works for the exact circuit""" 31 | params = generate_X8_params(1, 0.3) 32 | prog = X8_device.create_program(**params) 33 | prog2 = prog.compile(device=X8_device, compiler="Xstrict") 34 | assert program_equivalence(prog, prog2, atol=tol, rtol=0) 35 | 36 | def test_invalid_parameter(self, tol): 37 | """Test exception is raised with invalid parameter values""" 38 | params = generate_X8_params(1, 0.3) 39 | prog = X8_device.create_program(**params) 40 | prog.circuit[0].op.p = [0.5, 0] 41 | 42 | with pytest.raises(ValueError, match="has invalid value"): 43 | prog.compile(device=X8_device, compiler="Xstrict") 44 | 45 | def test_invalid_gate(self, tol): 46 | """Test exception is raised with invalid primitive""" 47 | params = generate_X8_params(1, 0.3) 48 | prog = X8_device.create_program(**params) 49 | prog.circuit[0].op.__class__ = sf.ops.CXgate 50 | 51 | with pytest.raises( 52 | sf.program_utils.CircuitError, match="CXgate cannot be used with the compiler" 53 | ): 54 | prog.compile(device=X8_device, compiler="Xstrict") 55 | 56 | def test_invalid_topology(self, tol): 57 | """Test exception is raised with invalid topology""" 58 | params = generate_X8_params(1, 0.3) 59 | prog = X8_device.create_program(**params) 60 | del prog.circuit[0] 61 | 62 | with pytest.raises(sf.program_utils.CircuitError, match="incompatible topology"): 63 | prog.compile(device=X8_device, compiler="Xstrict") 64 | -------------------------------------------------------------------------------- /tests/frontend/test_about.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | Unit tests for top-level Strawberry Fields functions. 16 | """ 17 | import pytest 18 | import re 19 | import strawberryfields as sf 20 | 21 | 22 | pytestmark = pytest.mark.frontend 23 | 24 | 25 | def test_about(capfd): 26 | """sf.about works.""" 27 | sf.about() 28 | out, err = capfd.readouterr() 29 | # substantial output (actual length varies) 30 | assert len(err) == 0 31 | assert len(out) > 300 32 | 33 | assert "Strawberry Fields version" in out 34 | sf_version_match = re.search(r"Strawberry Fields version:\s+([\S]+)\n", out).group(1) 35 | assert sf_version_match == sf.version() 36 | 37 | for pkg in ("Numpy", "Scipy", "The Walrus", "Blackbird", "XCC"): 38 | assert f"{pkg} version" in out 39 | 40 | 41 | def test_cite(capfd): 42 | """sf.cite works.""" 43 | sf.cite() 44 | out, err = capfd.readouterr() 45 | # correct output 46 | assert len(err) == 0 47 | assert len(out) == 431 48 | -------------------------------------------------------------------------------- /tests/frontend/test_ops_preparation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Xanadu Quantum Technologies Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | r"""Unit tests for Preparation classes in ops.py""" 15 | import pytest 16 | 17 | pytestmark = pytest.mark.frontend 18 | 19 | import numpy as np 20 | 21 | from strawberryfields import ops 22 | from strawberryfields.program import Program 23 | from strawberryfields.program_utils import MergeFailure, RegRefError 24 | from strawberryfields import utils 25 | 26 | 27 | @pytest.mark.parametrize( 28 | "state", ops.simple_state_preparations 29 | ) # these have __init__ methods with default arguments 30 | class TestStatePreparationBasics: 31 | """Basic properties of state preparation operations.""" 32 | 33 | def test_merge(self, state): 34 | """Test that merging states simply returns the second state""" 35 | # state to test against 36 | V = ops.Vacuum() 37 | G = state() 38 | 39 | # merging with another state returns the last one 40 | assert np.all(G.merge(V) == V) 41 | assert np.all(V.merge(G) == G) 42 | 43 | def test_exceptions(self, state): 44 | """Test exceptions raised if state prep used on invalid modes""" 45 | G = state() 46 | prog = Program(2) 47 | 48 | with prog.context: 49 | # all states act on a single mode 50 | with pytest.raises(ValueError): 51 | G.__or__([0, 1]) 52 | 53 | # can't repeat the same index 54 | with pytest.raises(RegRefError): 55 | ops.All(G).__or__([0, 0]) 56 | -------------------------------------------------------------------------------- /tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | backends(name1, name2, ...): test applies to named backends only 4 | frontend: test applies to frontend only 5 | apps: test applies to applications layer only 6 | api: test applies to API only 7 | --------------------------------------------------------------------------------