Skip to content

RFC: log dialect #230

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

Open
jon-wurtz opened this issue May 1, 2025 · 1 comment
Open

RFC: log dialect #230

jon-wurtz opened this issue May 1, 2025 · 1 comment
Labels
rfc Request for Comments

Comments

@jon-wurtz
Copy link
Contributor

jon-wurtz commented May 1, 2025

Following #229 .

One option for extracting out the quantum state from a simulator is to have a log dialect. Backing up a bit from what I proposed in #229 , it could be as simple as bloqade.dialects.log_state(label:str="foo"). The results object from the appropriate simulator would be a StochasticWavefunction where each instance is a seed recording bitstring measurements that occurred up to that point, and the wavefunction state of the qpu at that point.

For example, consider doing some sort of Bell state prep:

@bloqade.kernel
def main():
    
    register = bloqade.circuits.line_qubits(2) # This doesn't exactly follow our convention but whatever
    bloqade.circuits.h(register[0])
    bloqade.circuits.cx(register[0], register[1])
    
    bloqade.dialects.log_state(label="A")
    z0 = bloqade.circuits.measure(register[0])
    bloqade.dialects.log_state(label="B")
    z1 = bloqade.circuits.measure(register[1])
    bloqade.dialects.log_state(label="C")
    
    return z0, z1

context = bloqade.executors.statevector()
result = context.log_state(main,repititions=2)
result == StochasticWavefunction:[# First repetition
    {"A":
    BitstringResult: {"data":[],"basis":[]},
    Wavefunction: {"data":[1,0,0,1],"basis":[Qubit(0), Qubit(1)]}},
            {"B":
    BitstringResult: {"data":[0],"basis":[Qubit(0)]},
    Wavefunction: {"data":[1,0],"basis":[Qubit(0)]}},
            {"C":
    BitstringResult: {"data":[0,0],"basis":[Qubit(0),Qubit(1)]},
    Wavefunction: {"data":[],"basis":[]}},
            # Second repetition
    {"A":
    BitstringResult: {"data":[],"basis":[]},
    Wavefunction: {"data":[1,0,0,1],"basis":[Qubit(0), Qubit(1)]}},
            {"B":
    BitstringResult: {"data":[1],"basis":[Qubit(0)]},
    Wavefunction: {"data":[0,1],"basis":[Qubit(0)]}},
            {"C":
    BitstringResult: {"data":[1,1],"basis":[Qubit(0),Qubit(1)]},
    Wavefunction: {"data":[],"basis":[]}},
            # etc.
    ]

Here the dictionaries are a rough representation of the attributes of the appropriate data classes

Other options work too, just being forward-thinking in terms of mid-circuit measurement. debug() could also return the final state, if measurements are not performed. The important thing is to consider the non-physicality of the wavefunction and how this execution differs from what actually happens on hardware-- we cannot directly access or retrieve the wavefunction!!

@jon-wurtz jon-wurtz added the rfc Request for Comments label May 1, 2025
@jon-wurtz
Copy link
Contributor Author

Maybe something like MachineState could also include the positions, labels, and moves of atoms, as a way of getting us to atom move animations...

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

No branches or pull requests

1 participant