-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from calculquebec/release
Release v0.4.0
- Loading branch information
Showing
12 changed files
with
206 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
""" | ||
|
||
|
||
__version__ = "0.3.0" | ||
__version__ = "0.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
from .counts import Counts | ||
from .sample import Sample | ||
from .probabilities import Probabilities | ||
from .state import State | ||
from .expectation_value import ExpectationValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
from collections import Counter | ||
|
||
|
||
class Counts(MeasurementStrategy): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def measure(self, converter, mp, shots): | ||
if self.Snowflurry.currentClient is None: | ||
converter.remove_readouts() | ||
converter.apply_readouts(mp.obs) | ||
shots_results = self.Snowflurry.simulate_shots(self.Snowflurry.sf_circuit, shots) | ||
result = dict(Counter(shots_results)) | ||
return result | ||
else: # if we have a client, we use the real machine | ||
converter.apply_readouts(mp.obs) | ||
qpu = self.Snowflurry.AnyonYamaskaQPU( | ||
self.Snowflurry.currentClient, self.Snowflurry.seval("project_id") | ||
) | ||
shots_results, time = self.Snowflurry.transpile_and_run_job( | ||
qpu, self.Snowflurry.sf_circuit, shots | ||
) | ||
result = dict(Counter(shots_results)) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
import pennylane as qml | ||
from juliacall import convert | ||
import numpy as np | ||
|
||
|
||
class ExpectationValue(MeasurementStrategy): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def measure(self, converter, mp, shots): | ||
# FIXME : this measurement does work when the number of qubits measured is not equal to the number of qubits | ||
# in the circuit | ||
# Requires some processing to work with larger matrices | ||
converter.remove_readouts() | ||
self.Snowflurry.result_state = self.Snowflurry.simulate(self.Snowflurry.sf_circuit) | ||
if mp.obs is not None and mp.obs.has_matrix: | ||
print(mp.obs) | ||
observable_matrix = qml.matrix(mp.obs) | ||
print(observable_matrix) | ||
expected_value = self.Snowflurry.expected_value( | ||
self.Snowflurry.DenseOperator(convert(self.Snowflurry.Matrix, observable_matrix)), | ||
self.Snowflurry.result_state | ||
) | ||
return np.real(expected_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class MeasurementStrategy: | ||
|
||
def __init__(self): | ||
from pennylane_snowflurry.pennylane_converter import Snowflurry | ||
self.Snowflurry = Snowflurry | ||
|
||
def measure(self, converter, mp, shots): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
from juliacall import convert | ||
|
||
|
||
class Probabilities(MeasurementStrategy): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def measure(self, converter, mp, shots): | ||
converter.remove_readouts() | ||
wires_list = mp.wires.tolist() | ||
if len(wires_list) == 0: | ||
return self.Snowflurry.get_measurement_probabilities(self.Snowflurry.sf_circuit) | ||
else: | ||
return self.Snowflurry.get_measurement_probabilities( | ||
self.Snowflurry.sf_circuit, | ||
convert(self.Snowflurry.Vector, [i + 1 for i in wires_list]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
import numpy as np | ||
|
||
|
||
class Sample(MeasurementStrategy): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def measure(self, converter, mp, shots): | ||
if self.Snowflurry.currentClient is None: | ||
converter.remove_readouts() | ||
converter.apply_readouts(mp.obs) | ||
shots_results = self.Snowflurry.simulate_shots(self.Snowflurry.sf_circuit, shots) | ||
return np.asarray(shots_results).astype(int) | ||
else: | ||
converter.apply_readouts(mp.obs) | ||
qpu = self.Snowflurry.AnyonYamaskaQPU( | ||
self.Snowflurry.currentClient, self.Snowflurry.seval("project_id") | ||
) | ||
shots_results, time = self.Snowflurry.transpile_and_run_job( | ||
qpu, self.Snowflurry.sf_circuit, shots, | ||
) | ||
return np.repeat( | ||
[int(key) for key in shots_results.keys()], | ||
[value for value in shots_results.values()], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from .measurement_strategy import MeasurementStrategy | ||
|
||
import numpy as np | ||
|
||
|
||
class State(MeasurementStrategy): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def measure(self, converter, mp, shots): | ||
converter.remove_readouts() | ||
self.Snowflurry.result_state = self.Snowflurry.simulate(self.Snowflurry.sf_circuit) | ||
# Convert the final state from pyjulia to a NumPy array | ||
final_state_np = np.array([element for element in self.Snowflurry.result_state]) | ||
return final_state_np |
Oops, something went wrong.