Skip to content

Add Layer for easy ansatz creation #119

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add Layer for easy ansatz creation #119

wants to merge 5 commits into from

Conversation

Jacomichi
Copy link
Collaborator

@Jacomichi Jacomichi commented Mar 3, 2025

Change

  • Implement Layer and ParameterizedLayer.
  • I have implemented automated parameter generation for the ParameterizedLayer.
  • I introduce ParameterContext to avoid collision of the name of the parameter in each layer.
  • Implement predefined Ansatz (HardwareEfficientSU2Ansatz) by using above system
  • Introduce CustomAnsatz (I guess there exists better name) for easy and flexible ansatz creation.

Example

The code below is the example code for hand writing version of the hardware efficient ansatz.

num_qubits = 4
layers = [
    qm_l.RotationLayer(num_qubits, rotation_type="ry"),
    qm_l.RotationLayer(num_qubits, rotation_type="rz"),
    qm_l.EntanglementLayer(num_qubits,entangle_type="linear"),
]
custom_ansatz = CustomAnsatz(num_qubits, layers, reps=3)
handmade_su2 = custom_ansatz.get_circuit()

# Add final rotation layer by hand
handmade_su2.append(qm_l.RotationLayer(num_qubits, rotation_type="ry", parameter_context=custom_ansatz.parameter_context).get_circuit())
handmade_su2.append(qm_l.RotationLayer(num_qubits, rotation_type="rz", parameter_context=custom_ansatz.parameter_context).get_circuit())

More example is in the notebook (https://github.com/Jij-Inc/Qamomile/blob/feature/layer/docs/tutorial/usage/ansatz_layers.ipynb)

@Jacomichi Jacomichi requested a review from yuyamashiro March 3, 2025 02:40


class Ansatz(ABC):
"""基底Ansatzクラス。全てのAnsatzはこれを継承する"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use English in docstrings.

)


# def create_efficient_su2_circuit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment out lines.

def set_parameter_context(
self, context: ParameterContext, regenerate: bool = False
) -> None:
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use English

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants