Skip to content
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

Defining the new Backend API classes #764

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open

Conversation

HGSilveri
Copy link
Collaborator

@HGSilveri HGSilveri commented Nov 19, 2024

  • Introduces the Results class and make Result a subclass of it in backwards compatible way
  • Defines the State and Operator ABCs
  • Updates BackendConfig and defines EmulationConfig
  • Defines the EmulatorBackend ABC
  • Defines the Callback and Observable ABCs
  • Defines the default observables

To do:

  • Define QutipState to have an example
  • Idem for QutipOperator
  • Solve relevant TODOs
  • Write UTs

)

if default_evaluation_times != "Full":
eval_times_arr = np.array(default_evaluation_times, dtype=float)

Choose a reason for hiding this comment

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

why is this a np.array but below you use AbstractArray?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean for interaction_matrix? I use AbstractArray because I expect people might want to differentiate against it

"""
pass

def infer_one_state(self) -> Eigenstate:

Choose a reason for hiding this comment

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

why do we not simply throw an error if the eigenbasis is not predefined? No backend would know how to simulate it anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I get what you mean. Do you mean in the case that the eigenstates don't match one of these sets we would just throw an error right away?

Copy link

Choose a reason for hiding this comment

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

yes

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 sounds like something each subclass may chose to do, I don't want to enforce the supported eigenbasis in the ABC

Copy link

@a-quelle a-quelle Jan 10, 2025

Choose a reason for hiding this comment

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

I'm not sure. For example, in this implementation, you're considering that the bases in lines 153-160 are known. We only support rg and 01 currently, and that is fine. But what is the use-case for supporting uv and having the user supply that u measures as 1? Perhaps in the qutip backend the state object is independent enough from the simulation that this works, even though no dynamics are really defined for it, but actually enforcing all backends to have a state so independent from the simulation is what seems excessive to me.

The main place where this manifests in an uncomfortable way for me is in the presence of the one_state arg in sample. We only support the rg and 01 bases currently, and these have well defined behaviour upon measurement that I don't think the user should override.

Copy link
Collaborator Author

@HGSilveri HGSilveri Jan 10, 2025

Choose a reason for hiding this comment

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

The reason why I'm allowing this flexibility is because, already, we have a case where we can't infer the one state - notably, when we have the qutrit with eigenstates rgh, the one_state actually depends on the measurement basis.
I defined infer_one_state() to avoid having the user defining the one state as much as possible but sometimes it is unavoidable.
I think that if you want to block the definition of unknown eigenstates or custom one states, you can do so in MPS. As for the ABC, I think we should allow this flexibility. If we don't and at some point want to support some other basis in a particular backend, we would have to open a PR on pulser-core to change the base class, which doesn't make sense to me.
Put another way, the State ABC should not include a hardcoded supserset of the basis states supported by all backends.

@HGSilveri HGSilveri marked this pull request as ready for review January 3, 2025 14:51
@HGSilveri HGSilveri assigned a-corni and HGSilveri and unassigned a-corni Jan 3, 2025
@HGSilveri HGSilveri requested a review from a-corni January 3, 2025 14:52
*,
eigenstates: Sequence[Eigenstate],
n_qudits: int,
operations: FullOp,

Choose a reason for hiding this comment

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

in the notion page we had an extra argument here operators: dict[str, QubitOp] where you could define aliases for certain QuditOps such as {"X": {"rg": 1, "gr": 1}}. I found this super useful and started depending on it in several places. Now I realize it's not in the method. Could we add it back in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can't it be specfic to MPO? I'm not a big fan of it and chose not to have it in QutipOperator as I found it overcomplicated the implementation unnecessarily.
I think that what you wanted could be achieved by defining an auxiliary variable instead, eg.

X = {"rg": 1, "gr": 1}
QutipOperator.from_operator_repr(
    eigenstates=("r", "g"),
    n_qudits=3,
    operations=[(1.0, [(X, {0, 2})]],
)

Choose a reason for hiding this comment

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

That is fair.

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.

3 participants