Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions dwave/gate/operations/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"Y",
"Z",
"Hadamard",
"HY",
"Phase",
"S", # alias
"P", # alias
Expand Down Expand Up @@ -231,6 +232,26 @@ def matrix(cls) -> NDArray[np.complex128]:
matrix = math.sqrt(2) / 2 * np.array([[1.0, 1.0], [1.0, -1.0]], dtype=np.complex128)
return matrix

class HY(Operation):
"""Self-inverse operation for Y-Z basis swap.

Has the property $\sigma_y = H_y \sigma_z H_y.

Args:
qubits: Qubits on which the operation should be applied. Only
required when applying an operation within a circuit context.
"""

_num_qubits: int = 1

# see: https://quantumcomputing.stackexchange.com/questions/11390/problem-with-commutation-of-e-ih-1t-and-e-ih-2t-where-h-1-commutes/11391#11391
# not the only way of doing this, but the most simple

@mixedproperty
def matrix(cls) -> NDArray[np.complex128]:
"""The matrix representation of the $H_y$ operator."""
return math.sqrt(2) / 2 * np.array([[1, -1j], [1j, -1]], dtype=np.complex128)


class S(Operation):
"""S (Phase) operation.
Expand Down
21 changes: 21 additions & 0 deletions dwave/gate/vqe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 D-Wave Systems Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Module for running the Variational Quantum Eigensolver (VQE) algorithm.

TODO: Add description
"""
from dwave.gate.vqe.operators import *
from dwave.gate.vqe.transformations.jordan_wigner import *
from dwave.gate.vqe.vqe import *
68 changes: 68 additions & 0 deletions dwave/gate/vqe/cqm_partition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2023 D-Wave Systems Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = [
"partition_cqm",
]

import warnings


try:
import dimod

from dwave.system import LeapHybridCQMSampler
except ImportError as e:
raise ImportError("Dimod must be installed for CQM partioning.") from e


def partition_cqm(adjacency, num_measurements):
"""TODO"""
cqm = dimod.ConstrainedQuadraticModel()

measurement_rounds = [
dimod.Integer(i, lower_bound=0, upper_bound=num_measurements)
for i in range(num_measurements)
]

cqm.set_objective(sum(measurement_rounds))

for source, target in adjacency:
cqm.add_constraint_from_comparison(
measurement_rounds[source] ** 2
+ measurement_rounds[target] ** 2
- 2 * measurement_rounds[source] * measurement_rounds[target]
>= 1
)

sampler = LeapHybridCQMSampler()

sampleset = sampler.sample_cqm(cqm)
sampleset = sampleset.filter(lambda x: x.is_feasible)

if len(sampleset) == 0:
warnings.warn("No feasible measurement schemes found, defaulting to sequential measurement")
cqm_sample = {i: i for i in range(num_measurements)}
else:
cqm_sample = sampleset.first.sample

partition = {}

for pauli_index, measurement_round in cqm_sample.items():
if measurement_round not in partition:
partition[measurement_round] = [pauli_index]
else:
partition[measurement_round] = partition[measurement_round] + [pauli_index]

return partition
Loading