Skip to content

Commit

Permalink
add test init hamevo noise ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles MOUSSA committed Nov 25, 2024
1 parent 728f5bc commit 4f8f3dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/content/time_dependent.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ t = TimeParameter("t")
omega_param = FeatureParameter("omega")

# Arbitrarily compose a time-dependent generator
generator_td = omega_param * (t * X(0) + t**2 * Y(1))
td_generator = omega_param * (t * X(0) + t**2 * Y(1))

# Create parameterized HamEvo block
hamevo = HamEvo(generator_td, t)
hamevo = HamEvo(td_generator, t)
```

Note that when using `HamEvo` with a time-dependent generator, the actual time parameter that was used to construct the generator must be passed for the second argument `parameter`.
Expand Down Expand Up @@ -48,7 +48,7 @@ Note that Qadence makes no assumption on units. The unit of passed duration valu

# Noisy time-dependent Hamiltonian evolution

For performing noisy time-dependent Hamiltonian evolution, one needs to specify the `noise_operators` corresponding to the jump operators used within the time-dependent Schrodinger equation solver method `SolverType.DP5_ME`:
To perform noisy time-dependent Hamiltonian evolution, one needs to pass a list of noise operators to the `noise_operators` argument in `HamEvo`. They correspond to the jump operators used within the time-dependent Schrodinger equation solver method `SolverType.DP5_ME`:

```python exec="on" source="material-block" session="getting_started"
from qadence import X, Y, HamEvo, TimeParameter, FeatureParameter, run
Expand All @@ -64,11 +64,11 @@ t = TimeParameter("t")
omega_param = FeatureParameter("omega")

# Arbitrarily compose a time-dependent generator
generator_td = omega_param * (t * X(0) + t**2 * Y(1))
td_generator = omega_param * (t * X(0) + t**2 * Y(1))

# Create parameterized HamEvo block
noise_operators = [torch.eye(4, dtype=torch.complex128)]
hamevo = HamEvo(generator_td, t, noise_operators = noise_operators)
hamevo = HamEvo(td_generator, t, noise_operators = noise_operators)

values = {"omega": torch.tensor(10.0), "duration": torch.tensor(1.0)}

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ nav:
- Contents:
- Block system: content/block_system.md
- Parametric programs: content/parameters.md
- Time-dependent generators: content/time_dependent.md
- Quantum models: content/quantummodels.md
- Quantum registers: content/register.md
- State initialization: content/state_init.md
- Arbitrary Hamiltonians: content/hamiltonians.md
- Time-dependent generators: content/time_dependent.md
- QML Constructors: content/qml_constructors.md
- Wavefunction overlaps: content/overlap.md
- Backends: content/backends.md
Expand Down
8 changes: 8 additions & 0 deletions qadence/operations/ham_evo.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def __init__(
self.time_param = parameter
self.generator = generator
self.duration = duration
if len(noise_operators) > 0 and not all(
[
len(op.size()) == 2 and op.size(0) == op.size(1) == 2 ** len(self.qubit_support)
for op in noise_operators
]
):
correct_shape = (2 ** len(self.qubit_support),) * 2
raise ValueError(f"Noise operators should be square tensors of size {correct_shape}")
self.noise_operators = noise_operators

@classmethod
Expand Down

0 comments on commit 4f8f3dc

Please sign in to comment.