Skip to content
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

Feat multi-observable for IBM and diagonal observables #126

Draft
wants to merge 67 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e667613
start: setting up todos for the task
hJaffaliColibritd Jan 8, 2025
f260308
chore: Files formated
github-actions[bot] Jan 8, 2025
3640cbf
feat: adding function to detect diagonal matrices
hJaffaliColibritd Jan 10, 2025
dc9ece7
chore: Files formated
github-actions[bot] Jan 10, 2025
92fcc47
feat: starting to update expectation_value.py
hJaffaliColibritd Jan 12, 2025
a42438d
Merge remote-tracking branch 'origin/feat-multi-observable' into feat…
hJaffaliColibritd Jan 12, 2025
2d89063
chore: Files formated
github-actions[bot] Jan 12, 2025
9d5e10b
feat: setting up commutation for diagonal observables
hJaffaliColibritd Jan 14, 2025
8975462
Merge remote-tracking branch 'origin/feat-multi-observable' into feat…
hJaffaliColibritd Jan 14, 2025
fc1c08f
feat: merging DiagonalObservable with Observable, work in progress, s…
hJaffaliColibritd Feb 3, 2025
91dc79f
feat: merging observable and diagonal observable
hJaffaliColibritd Feb 13, 2025
e3875a1
chore: Files formated
github-actions[bot] Feb 13, 2025
08128a6
chore:adding todos
hJaffaliColibritd Feb 14, 2025
7c6816d
chore: adding todos
hJaffaliColibritd Feb 14, 2025
351071a
chore: Files formated
github-actions[bot] Feb 14, 2025
5517dba
chore: adding todos
hJaffaliColibritd Feb 14, 2025
98f5249
chore: update compute_expectation_value
MoHermes Feb 17, 2025
d29517c
Merge branch 'feat-multi-observable' of github.com:ColibrITD-SAS/mpqp…
MoHermes Feb 17, 2025
b13ba72
feat: update 'submit_remote_ibm', multi-obs case
MoHermes Feb 19, 2025
393051d
fix: multi-observables support in ExpectationMeasure
MoHermes Feb 20, 2025
9a9b6f8
chore: adding Literal to grouping methods
hJaffaliColibritd Feb 25, 2025
749e0c9
Merge remote-tracking branch 'origin/dev' into feat-multi-observable
hJaffaliColibritd Feb 25, 2025
f1af7cc
feat: implementing commutativity for PauliStringAtom
hJaffaliColibritd Feb 26, 2025
78df4cd
feat: setting up file for pauli_grouping algorithms
hJaffaliColibritd Feb 26, 2025
7c84013
chore: update expectation value
MoHermes Feb 27, 2025
304bc73
Merge branch 'feat-multi-observable' of github.com:ColibrITD-SAS/mpqp…
MoHermes Feb 27, 2025
e28e1a1
test: simple test sequential vs multi observable
hJaffaliColibritd Feb 28, 2025
9db4d9c
chore: Files formated
github-actions[bot] Feb 28, 2025
918c875
chore: extract_result update
MoHermes Feb 28, 2025
7b432f5
chore: observable size 0 debug
MoHermes Feb 28, 2025
da9c31e
chore: expectation measure update
MoHermes Feb 28, 2025
cd696fd
test: first test ready
hJaffaliColibritd Mar 1, 2025
6ae14cd
feat: setting up file for different pauli grouping
hJaffaliColibritd Mar 1, 2025
ea86c00
chore: few modification in expectation_value.py
hJaffaliColibritd Mar 1, 2025
b671a73
Merge branch 'feat-multi-observable' of github.com:ColibrITD-SAS/mpqp…
hJaffaliColibritd Mar 1, 2025
2427623
fix: fix type of is_diagonal
hJaffaliColibritd Mar 1, 2025
1c95da1
chore: updating the expectation_value.py for commutativity
hJaffaliColibritd Mar 1, 2025
a7b1aba
chore: Files formated
github-actions[bot] Mar 1, 2025
964ec12
fix: fixing the multi-observable local run
hJaffaliColibritd Mar 1, 2025
b7fe962
Merge remote-tracking branch 'origin/feat-multi-observable' into feat…
hJaffaliColibritd Mar 1, 2025
c30dfb7
chore: small chnages + adding is_diagonal to pauli string
hJaffaliColibritd Mar 1, 2025
5cc3f56
feat: implement commutativity between PauliStringMonomials
hJaffaliColibritd Mar 3, 2025
91fbac5
chore: adding todos for cirq multi observable
hJaffaliColibritd Mar 3, 2025
76abde3
feat: adding greedy algorithm for pauli grouping
hJaffaliColibritd Mar 3, 2025
4d85519
chore: cleaning the code and removing prints
hJaffaliColibritd Mar 3, 2025
06c5abf
fix: fixing types and special cases for diagonal observables
hJaffaliColibritd Mar 4, 2025
dfa4db2
fix: refactoring and making tests pass
hJaffaliColibritd Mar 4, 2025
67f2011
chore: Files formated
github-actions[bot] Mar 4, 2025
3d5fc06
chore: EstimatorResult supports multi observables
MoHermes Mar 4, 2025
cd81829
chore: multi-observables job execution for IBMSimulatedDevice
MoHermes Mar 4, 2025
4436b7f
chore: change shots data
hJaffaliColibritd Mar 5, 2025
7d79ae3
feat: introducing S_dagger gate
hJaffaliColibritd Mar 5, 2025
8323371
feat: adding eigen-values associated with Pauli monomials and atoms
hJaffaliColibritd Mar 9, 2025
e9ec5f1
chore: Files formated
github-actions[bot] Mar 9, 2025
a65b777
fix: fix error introduced in multi-observable execution
hJaffaliColibritd Mar 10, 2025
c85ac49
Merge remote-tracking branch 'origin/feat-multi-observable' into feat…
hJaffaliColibritd Mar 10, 2025
4ff31fe
fix: problem with myqlm and s_dagger solved
hJaffaliColibritd Mar 10, 2025
efc22df
fix: fixed multi observable tests
hJaffaliColibritd Mar 10, 2025
1942d78
chore: update is_diagonal
MoHermes Mar 10, 2025
f549099
fix: type errors
MoHermes Mar 10, 2025
0b7ebd3
doc: adding examples for is_diagonal
hJaffaliColibritd Mar 11, 2025
1a6ccc0
doc: pauli atom
hJaffaliColibritd Mar 11, 2025
013938d
chore: clean up
MoHermes Mar 11, 2025
a42e62d
Merge branch 'feat-multi-observable' of github.com:ColibrITD-SAS/mpqp…
MoHermes Mar 11, 2025
af205e9
chore: update expectation_value, add matrix validation checks
MoHermes Mar 11, 2025
4414820
doc: add get_pauli_grouping docstring
MoHermes Mar 11, 2025
cec03b0
doc: update docs, clean up
MoHermes Mar 12, 2025
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
20 changes: 20 additions & 0 deletions examples/notebooks/3_Expectation_value_of_observables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,26 @@
")\n",
"print(results)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad9fed49",
"metadata": {},
"outputs": [],
"source": [
"#TODO: show examples with multi observable expectation value\n",
"\n",
"#TODO: maybe show also the set of commuting pauli string when those observables are decomposed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a6f5f27c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
3 changes: 2 additions & 1 deletion examples/scripts/aws_execution_trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
circuit.add(SWAP(2, 0))
circuit.add(CNOT(0, 2))
circuit.add(Ry(3.14 / 2, 2))
circuit.add(S(1))
circuit.add(S(0))
circuit.add(S_dagger(1))
circuit.add(H(3))
circuit.add(CNOT(1, 2))
circuit.add(Rx(3.14, 1))
Expand Down
3 changes: 2 additions & 1 deletion examples/scripts/circuit_to_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
circuit.add(SWAP(2, 0))
circuit.add(CNOT(0, 2))
circuit.add(Ry(3.14 / 2, 2))
circuit.add(S(1))
circuit.add(S(0))
circuit.add(S_dagger(1))
circuit.add(H(3))
circuit.add(CNOT(1, 2))
circuit.add(Rx(3.14, 1))
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/native_gates_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Declaration of the circuit with the right size
circuit = QCircuit(3, label="Test native gates")
# Constructing the circuit by adding gates and measurements
circuit.add([H(0), X(1), Y(2), Z(0), S(1), T(0)])
circuit.add([H(0), X(1), Y(2), Z(0), S(0), S_dagger(1), T(0)])
circuit.add([Rx(1.2324, 2), Ry(-2.43, 0), Rz(1.04, 1), Rk(-1, 1), P(-323, 2)])
circuit.add(U(1.2, 2.3, 3.4, 2))
circuit.add(SWAP(2, 0))
Expand Down
2 changes: 2 additions & 0 deletions examples/scripts/observable_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@
],
)
print(results)

# TODO: show examples of multi observable run
1 change: 1 addition & 0 deletions mpqp/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
Ry,
Rz,
S,
S_dagger,
T,
U,
UnitaryMatrix,
Expand Down
14 changes: 7 additions & 7 deletions mpqp/core/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,29 +760,29 @@ def inverse(self) -> QCircuit:
The inverse circuit.

Examples:
>>> c1 = QCircuit([S(0), CZ(0,1), H(1), Ry(4.56, 1)])
>>> c1 = QCircuit([T(0), CZ(0,1), H(1), Ry(4.56, 1)])
>>> print(c1) # doctest: +NORMALIZE_WHITESPACE
┌───┐
q_0: ┤ S ├─■──────────────────
q_0: ┤ T ├─■──────────────────
└───┘ │ ┌───┐┌──────────┐
q_1: ──────■─┤ H ├┤ Ry(4.56) ├
└───┘└──────────┘
>>> print(c1.inverse()) # doctest: +NORMALIZE_WHITESPACE
┌────┐
q_0: ───────────────────■─┤ S† ├
q_0: ───────────────────■─┤ T† ├
┌───────────┐┌───┐ │ └────┘
q_1: ┤ Ry(-4.56) ├┤ H ├─■───────
└───────────┘└───┘
>>> c2 = QCircuit([S(0), CRk(2, 0, 1), Barrier(), H(1), Ry(4.56, 1)])
>>> c2 = QCircuit([T(0), CRk(2, 0, 1), Barrier(), H(1), Ry(4.56, 1)])
>>> print(c2) # doctest: +NORMALIZE_WHITESPACE
┌───┐ ░
q_0: ┤ S ├─■────────░──────────────────
q_0: ┤ T ├─■────────░──────────────────
└───┘ │P(π/2) ░ ┌───┐┌──────────┐
q_1: ──────■────────░─┤ H ├┤ Ry(4.56) ├
░ └───┘└──────────┘
>>> print(c2.inverse()) # doctest: +NORMALIZE_WHITESPACE
░ ┌────┐
q_0: ───────────────────░──■────────┤ S† ├
q_0: ───────────────────░──■────────┤ T† ├
┌───────────┐┌───┐ ░ │P(-π/2) └────┘
q_1: ┤ Ry(-4.56) ├┤ H ├─░──■──────────────
└───────────┘└───┘ ░
Expand Down Expand Up @@ -906,7 +906,7 @@ def measurements(self) -> list[Measure]:
... ])
>>> circuit.measurements # doctest: +NORMALIZE_WHITESPACE
[BasisMeasure(shots=1000),
ExpectationMeasure(Observable(array([[1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j]], dtype=complex64)), [1], shots=1000)]
ExpectationMeasure([Observable(array([[1.+0.j, 0.+0.j], [0.+0.j, 1.+0.j]], dtype=complex64))], [1], shots=1000)]

"""
return [inst for inst in self.instructions if isinstance(inst, Measure)]
Expand Down
1 change: 1 addition & 0 deletions mpqp/core/instruction/gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Ry,
Rz,
S,
S_dagger,
T,
U,
X,
Expand Down
56 changes: 54 additions & 2 deletions mpqp/core/instruction/gates/native_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ class OneQubitNoParamGate(SingleQubitGate, NoParameterGate, SimpleClassReprABC):
target: Index referring to the qubits on which the gate will be applied.
"""

def __init__(self, target: int):
SingleQubitGate.__init__(self, target, type(self).__name__)
def __init__(self, target: int, label: Optional[str] = None):
SingleQubitGate.__init__(
self, target, type(self).__name__ if label is None else label
)


class Id(OneQubitNoParamGate, InvolutionGate):
Expand Down Expand Up @@ -767,6 +769,56 @@ def __init__(self, target: int):
super().__init__(target)
self.matrix = np.array([[1, 0], [0, 1j]])

def inverse(self) -> Gate:
return S_dagger(self.targets[0])


class S_dagger(OneQubitNoParamGate):
r"""One qubit S adjoint gate. It's equivalent to ``P(-pi/2)``.

`\begin{pmatrix}1&0\\0&-i\end{pmatrix}`

Args:
target: Index referring to the qubit on which the gate will be applied.

Example:
>>> pprint(S_dagger(0).to_matrix())
[[1, 0 ],
[0, -1j]]

"""

@classproperty
def braket_gate(cls):
from braket.circuits import gates

return gates.Si

@classproperty
def qiskit_gate(cls):
from qiskit.circuit.library import SdgGate

return SdgGate

@classproperty
def cirq_gate(cls):
from cirq.ops.common_gates import ZPowGate

return ZPowGate(exponent=-1 / 2)

qlm_aqasm_keyword = "DAG(S)"
qiskit_string = "sdg"

def __init__(self, target: int):
super().__init__(target, "S†")
self.matrix = np.array([[1, 0], [0, -1j]])

def __repr__(self):
return f"{type(self).__name__}({self.targets[0]})"

def inverse(self) -> Gate:
return S(self.targets[0])


class T(OneQubitNoParamGate):
r"""One qubit T gate. It is also referred to as the `\pi/4` gate because it
Expand Down
Loading
Loading