Skip to content

State vector

AnalogGate dataclass

AnalogGate(hamiltonian: RydbergHamiltonian)

run

run(
    shots: int = 1,
    solver_name: str = "dop853",
    atol: float = 1e-14,
    rtol: float = 1e-07,
    nsteps: int = 2147483647,
    interaction_picture: bool = False,
    project_hyperfine: bool = True,
) -> NDArray[np.uint8]

Run the emulation with all atoms in the ground state, sampling the final state vector.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
@beartype
def run(
    self,
    shots: int = 1,
    solver_name: str = "dop853",
    atol: float = 1e-14,
    rtol: float = 1e-7,
    nsteps: int = 2_147_483_647,
    interaction_picture: bool = False,
    project_hyperfine: bool = True,
) -> NDArray[np.uint8]:
    """Run the emulation with all atoms in the ground state,
    sampling the final state vector."""

    options = dict(
        solver_name=solver_name,
        atol=atol,
        rtol=rtol,
        nsteps=nsteps,
        interaction_picture=interaction_picture,
    )

    state = self.hamiltonian.space.zero_state()
    (result,) = self.apply(state, **options)
    result.normalize()

    return result.sample(shots, project_hyperfine=project_hyperfine)

RydbergHamiltonian dataclass

RydbergHamiltonian(
    emulator_ir: EmulatorProgram,
    space: Space,
    rydberg: NDArray,
    detuning_ops: List[DetuningOperator] = list(),
    rabi_ops: List[RabiOperator] = list(),
)

Hamiltonian for a given task. With the RydbergHamiltonian you can convert the Hamiltonian to CSR matrix form as well as obtaining the average energy/variance of a register.

Attributes:

Name Type Description
emulator_ir EmulatorProgram

A copy of the original program used to generate the RydbergHamiltonian

space Space

The Hilbert space of the Hamiltonian, should align with the register the Hamiltonian is being applied on for average energy/variance

rydberg NDArray

Rydberg interaction operator

detuning_ops List[DetuningOperator]

Detuning Operators of the Hamiltonian

rabi_ops List[RabiOperator]

Rabi Operators of the Hamiltonian

average

average(
    register: StateVector, time: Optional[float] = None
) -> float

Get energy average from RydbergHamiltonian object at time time with register register

Parameters:

Name Type Description Default
register StateVector

The state vector to take average with

required
time Optional[float]

Time value to evaluate average at.

None

Returns:

Name Type Description
float float

average energy at time time

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
@beartype
def average(
    self,
    register: StateVector,
    time: Optional[float] = None,
) -> float:
    """Get energy average from RydbergHamiltonian object at time `time` with
    register `register`

    Args:
        register (StateVector): The state vector to take average with
        time (Optional[float], optional): Time value to evaluate average at.
        Defaults to duration of RydbergHamiltonian.

    Returns:
        float: average energy at time `time`
    """
    return np.vdot(register.data, self._apply(register.data, time)).real

average_and_variance

average_and_variance(
    register: StateVector, time: Optional[float] = None
) -> Tuple[float, float]

Get energy average and variance from RydbergHamiltonian object at time time with register register

Parameters:

Name Type Description Default
register StateVector

The state vector to take average and variance with

required
time Optional[float]

Time value to evaluate average at.

None

Returns:

Type Description
float

Tuple[float, float]: average and variance of energy at time time

float

respectively.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
@beartype
def average_and_variance(
    self,
    register: StateVector,
    time: Optional[float] = None,
) -> Tuple[float, float]:
    """Get energy average and variance from RydbergHamiltonian object at time `time`
    with register `register`

    Args:
        register (StateVector): The state vector to take average and variance with
        time (Optional[float], optional): Time value to evaluate average at.
        Defaults to duration of RydbergHamiltonian.

    Returns:
        Tuple[float, float]: average and variance of energy at time `time`
        respectively.
    """
    H_register_data = self._apply(register.data, time)

    average = np.vdot(register.data, H_register_data).real
    square_average = np.vdot(H_register_data, H_register_data).real

    return average, square_average - average**2

tocsr

tocsr(time: float) -> csr_matrix

Return the Hamiltonian as a csr matrix at time time.

Parameters:

Name Type Description Default
time float

time to evaluate the Hamiltonian at.

required

Returns:

Name Type Description
csr_matrix csr_matrix

The Hamiltonian as a csr matrix.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
def tocsr(self, time: float) -> csr_matrix:
    """Return the Hamiltonian as a csr matrix at time `time`.

    Args:
        time (float): time to evaluate the Hamiltonian at.

    Returns:
        csr_matrix: The Hamiltonian as a csr matrix.

    """
    diagonal = sum(
        (detuning.get_diagonal(time) for detuning in self.detuning_ops),
        start=self.rydberg,
    )

    hamiltonian = diags(diagonal).tocsr()
    for rabi_op in self.rabi_ops:
        hamiltonian = hamiltonian + rabi_op.tocsr(time)

    return hamiltonian

variance

variance(
    register: StateVector, time: Optional[float] = None
) -> float

Get the energy variance from RydbergHamiltonian object at time time with register register

Parameters:

Name Type Description Default
register StateVector

The state vector to take variance with

required
time Optional[float]

Time value to evaluate average at.

None

Returns:

Name Type Description
complex float

variance of energy at time time respectively.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
@beartype
def variance(
    self,
    register: StateVector,
    time: Optional[float] = None,
) -> float:
    """Get the energy variance from RydbergHamiltonian object at
    time `time` with register `register`

    Args:
        register (StateVector): The state vector to take variance with
        time (Optional[float], optional): Time value to evaluate average at.
        Defaults to duration of RydbergHamiltonian.

    Returns:
        complex: variance of energy at time `time` respectively.
    """

    _, var = self.average_and_variance(register, time)
    return var

StateVector dataclass

StateVector(data: NDArray, space: Space)

local_trace

local_trace(
    matrix: ndarray, site_index: Union[int, Tuple[int, int]]
) -> complex

return trace of an operator over the StateVector.

Parameters:

Name Type Description Default
matrix ndarray

Square matrix representing operator in the local hilbert space.

required
site_index int | Tuple[int, int]

sites to apply one body operator to.

required

Returns:

Name Type Description
complex complex

the trace of the operator over the state-vector.

Raises:

Type Description
ValueError

Error is raised when the dimension of operator is not

ValueError

Error is raised when the site argument is out of bounds.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@plum.dispatch
def local_trace(  # noqa: F811
    self, matrix: np.ndarray, site_index: Union[int, Tuple[int, int]]
) -> complex:  # noqa: F811
    """return trace of an operator over the StateVector.

    Args:
        matrix (np.ndarray): Square matrix representing operator in the local
            hilbert space.
        site_index (int | Tuple[int, int]): sites to apply one body operator to.

    Returns:
        complex: the trace of the operator over the state-vector.

    Raises:
        ValueError: Error is raised when the dimension of `operator` is not
        consistent with `site` argument. The size of the operator must fit
        the size of the local hilbert space of `site` depending on the number
        of sites and the number of levels inside each atom, e.g. for two site
        expectation value with a three level atom the operator must be a 9 by
        9 array.

        ValueError: Error is raised when the `site` argument is out of bounds.

    """
    ...

norm

norm() -> float

Return the norm of the state vector.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
215
216
217
def norm(self) -> float:
    """Return the norm of the state vector."""
    return np.linalg.norm(self.data)

normalize

normalize() -> None

Normalize the state vector.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
210
211
212
213
def normalize(self) -> None:
    """Normalize the state vector."""
    data = self.data
    data /= np.linalg.norm(data)

sample

sample(
    shots: int, project_hyperfine: bool = True
) -> NDArray

Sample the state vector and return bitstrings.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/emulate/ir/state_vector.py
204
205
206
207
208
def sample(self, shots: int, project_hyperfine: bool = True) -> NDArray:
    """Sample the state vector and return bitstrings."""
    return self.space.sample_state_vector(
        self.data, shots, project_hyperfine=project_hyperfine
    )