Skip to content

Conversation

@eggerdj
Copy link
Collaborator

@eggerdj eggerdj commented Sep 4, 2025

Summary

We can easily add the possibility to use a custom ansatz operator to the state vector evaluator.

Details and comments

This PR adds the option to give a custom operator to the state vector evaluator and adds a corresponding test.

Version updated

Please increment the qaoa_training_pipeline_version variable and extend the main README.md.

  • Done

@eggerdj eggerdj marked this pull request as ready for review September 4, 2025 15:51
Copy link
Collaborator

@AlbertoBaiardi AlbertoBaiardi left a comment

Choose a reason for hiding this comment

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

I only have 1 suggestion for a new test, but the rest looks good to me :)

Comment on lines 52 to 59
def test_custom_ansatz(self):
"""Test that we can construct the ansatz from a different operator."""
ansatz_op = SparsePauliOp.from_list([("ZI", 1)])

energy1 = self.evaluator.evaluate(self.cost_op, params=[1.2, 1.3], ansatz_circuit=ansatz_op)
energy2 = self.evaluator.evaluate(self.cost_op, params=[1.2, 1.3])

self.assertTrue(abs(energy1 - energy2) > 0.1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to have the same test, but where we pass aself.cost_op to the keyword argument ansatz_circuit of the evaluate call, and we check that the energy is the same as if we did not pass anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good idea. Done here: d7cfe91

@eggerdj eggerdj merged commit e41a472 into qiskit-community:main Sep 8, 2025
8 checks passed
@eggerdj eggerdj deleted the sv_custom_ansatz branch September 8, 2025 12:08
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