-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merging Representation and Ansatz #487
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #487 +/- ##
===========================================
- Coverage 89.85% 89.84% -0.01%
===========================================
Files 104 106 +2
Lines 7698 7644 -54
===========================================
- Hits 6917 6868 -49
+ Misses 781 776 -5
Continue to review full report in Codecov by Sentry.
|
…refactorRepAnsatz
…refactorRepAnsatz
…refactorRepAnsatz
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Code Suggestions ✨Explore these optional code suggestions:
|
…refactorRepAnsatz
…refactorRepAnsatz
Replaced with #498 |
**Context:** One bottleneck currently in Mr Mustard is that `Representation` and `Wires` are treated separately when they are in fact very closely related. Here is presented an alternative implementation based on the [Merging Representation and Ansatz](#487) PR. In this, we now have a single `Representation` class that contains the ansatz, the wires and a dictionary mapping wires to their respective representation. To consider: Remove ArrayAnsatz and only use PolyExp? **Description of the Change:** - Introduced the new `Representation` class. - Introduced `RepEnum` class. - What is currently on develop as Ansatz and Representation is replaced with just Ansatz. - All `CircuitComponents` are initialized with a `Representation` and a name. Exposed classes are still initialized with modes where they make use of the new `from_modes` class method. - Renamed bargmann.py and fock.py to bargmann_utils.py and fock_utils.py - Renamed `fock` to `fock_array` **Benefits:** We now have an object responsible for managing multi representations and keeping track of what wire each representation is. Fewer classes to maintain (6 -> 4). Clearer separation of responsibilities. Much cleaner codebase. --------- Co-authored-by: Filippo Miatto <[email protected]>
User description
Opening for discussion
Context: It is becoming apparent that the separation between Representation and Ansatz may not be necessary. E.g. questions about where certain properties should live, questions about what responsibilities the representation should have vs the ansatz, a lot of exposing ansatz properties and methods in representation, etc.
Description of the Change:
Ansatz
,ArrayAnsatz
,PolyExpBase
andPolyExpAnsatz
are removed. Their underlying logic moved toFock
andBargmann
.bargmann.py
andfock.py
are renamed tobargmann_utils.py
andfock_utils.py
.Benefits: We no longer have to worry about maintaining 7 classes but instead just 3. A lot of duplicate code and exposing properties/ methods is removed. The responsibilities of
Representation
is much more clear.Possible Drawbacks: bargmann.py is massive (we could move many of the methods into utils?). If there is a use case to separate out representations and ansatz then we no longer support that.
PR Type
enhancement, refactoring, tests, documentation, bug fix, configuration changes
Description
Representation
andAnsatz
classes, simplifying the structure by removingAnsatz
,ArrayAnsatz
,PolyExpBase
, andPolyExpAnsatz
.Bargmann
andFock
classes for quantum state representation with enhanced mathematical operations and transformations.bargmann_utils
andfock_utils
.ansatze
.Changes walkthrough 📝
9 files
bargmann.py
Added Bargmann representation class with mathematical operations.
mrmustard/physics/representations/bargmann.py
Bargmann
class for quantum state representation.Bargmann
objects.polynomial shapes.
fock.py
Added Fock representation class with mathematical operations.
mrmustard/physics/representations/fock.py
Fock
class for quantum state representation.Fock
objects.manipulations.
representations.
state.py
Refactored state module to use new utils modules.
mrmustard/lab/abstract/state.py
bargmann_utils
andfock_utils
.fock
tofock_utils
for various operations.circuit_components.py
Refactored circuit components to use new representation classes.
mrmustard/lab_dev/circuit_components.py
fock_utils
.Bargmann
andFock
classes.dgate.py
Refactored Dgate transformation to use new Fock class.
mrmustard/lab_dev/transformations/dgate.py
fock_utils
.Fock
class.base.py
Introduce `Representation` base class with abstract methods.
mrmustard/physics/representations/base.py
Representation
class as a base for representations.representations.
bargmann_utils.py
Add utility function for Bargmann to phase space conversion.
mrmustard/physics/bargmann_utils.py
bargmann_Abc_to_phasespace_cov_means
function.__init__.py
Update widgets to remove `ansatz` references.
mrmustard/widgets/init.py
ansatz
in widget displays.__init__.py
Add new representations module with licensing.
mrmustard/physics/representations/init.py
15 files
test_bargmann.py
Introduced unit tests for Bargmann representation class.
tests/test_physics/test_representations/test_bargmann.py
Bargmann
class.handling.
test_fock_utils.py
Updated tests for fock_utils module functions.
tests/test_physics/test_fock_utils.py
fock_utils
module.fock
tofock_utils
.test_fock.py
Introduced unit tests for Fock representation class.
tests/test_physics/test_representations/test_fock.py
Fock
class.test_gates_fock.py
Update Fock gate tests to use `fock_utils`.
tests/test_lab/test_gates_fock.py
fock_utils
.test_states_base.py
Add and update tests for Bargmann utilities.
tests/test_lab_dev/test_states/test_states_base.py
bargmann_Abc_to_phasespace_cov_means
.bargmann_utils
.test_circuit_components.py
Update circuit component tests for new representations.
tests/test_lab_dev/test_circuit_components.py
ansatz
.test_transformations_base.py
Update transformation tests for new representations.
tests/test_lab_dev/test_transformations/test_transformations_base.py
test_circuit_components_utils.py
Update circuit component utility tests for new representations.
tests/test_lab_dev/test_circuit_components_utils.py
bargmann_utils
.test_bargmann_utils.py
Add license and update imports in Bargmann utils tests.
tests/test_physics/test_bargmann_utils.py
bargmann_utils
.test_coherent.py
Update coherent state tests for new representations.
tests/test_lab_dev/test_states/test_coherent.py
test_cft.py
Update CFT transformation tests for new representations.
tests/test_lab_dev/test_transformations/test_cft.py
test_lattice.py
Update lattice tests to use `bargmann_utils`.
tests/test_math/test_lattice.py
bargmann_utils
.test_compactFock.py
Update compact Fock tests to use `bargmann_utils`.
tests/test_math/test_compactFock.py
bargmann_utils
.test_number.py
Update number state tests to use `fock_utils`.
tests/test_lab_dev/test_states/test_number.py
fock_utils
.test_fidelity.py
Update fidelity tests to use `fock_utils`.
tests/test_physics/test_fidelity.py
fock_utils
.9 files
base.py
Refactor state base to use new representation structure.
mrmustard/lab_dev/states/base.py
fock_utils
andbargmann_utils
.ansatz
and updated logic to userepresentation
.structure.
transformation.py
Refactor transformation logic to use updated representations.
mrmustard/lab/abstract/transformation.py
fock_utils
andbargmann_utils
.gates.py
Refactor gate logic to use `fock_utils`.
mrmustard/lab/gates.py
fock_utils
.__init__.py
Update physics utilities to use `fock_utils`.
mrmustard/physics/init.py
fock_utils
.structure.
base.py
Refactor transformation base to use `bargmann_utils`.
mrmustard/lab_dev/transformations/base.py
bargmann_utils
.structure.
detectors.py
Refactor detector logic to use `fock_utils`.
mrmustard/lab/detectors.py
fock_utils
.states.py
Refactor state logic to use `fock_utils`.
mrmustard/lab/states.py
fock_utils
.trace_out.py
Update trace out utility for new representations.
mrmustard/lab_dev/circuit_components_utils/trace_out.py
number.py
Update number state logic to use `fock_utils`.
mrmustard/lab_dev/states/number.py
fock_utils
.9 files
diagonal_grad.py
Update comments to reference `fock_utils`.
mrmustard/math/lattice/strategies/compactFock/diagonal_grad.py
fock_utils
instead offock
.diagonal_amps.py
Update comments to reference `fock_utils`.
mrmustard/math/lattice/strategies/compactFock/diagonal_amps.py
fock_utils
instead offock
.singleLeftoverMode_grad.py
Update comments to reference `fock_utils`.
mrmustard/math/lattice/strategies/compactFock/singleLeftoverMode_grad.py
fock_utils
instead offock
.singleLeftoverMode_amps.py
Update comments to reference `fock_utils`.
mrmustard/math/lattice/strategies/compactFock/singleLeftoverMode_amps.py
fock_utils
instead offock
.backend_tensorflow.py
Update comments to reference `bargmann_utils`.
mrmustard/math/backend_tensorflow.py
bargmann_utils
instead ofbargmann
.backend_numpy.py
Update comments to reference `bargmann_utils`.
mrmustard/math/backend_numpy.py
bargmann_utils
instead ofbargmann
.diagonal_grad.jl
Update comments to reference `fock_utils`.
mrmustard/math/lattice/strategies/julia/compactFock/diagonal_grad.jl
fock_utils
instead offock
.bargmann_calculations.rst
Update documentation to reference `bargmann_utils`.
doc/code/physics/utils/bargmann_calculations.rst
bargmann_utils
.fock_calculations.rst
Update documentation to reference `fock_utils`.
doc/code/physics/utils/fock_calculations.rst
fock_utils
.1 files
fock_utils.py
Add error handling in `fock_state` function.
mrmustard/physics/fock_utils.py
fock_state
.1 files
circuits.py
Fix typo in circuit equality method.
mrmustard/lab_dev/circuits.py
1 files
tests_docs.yml
Update GitHub workflow to remove outdated tests.
.github/workflows/tests_docs.yml
ansatze
.representations
.