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 custom basis #101

Merged
merged 105 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
780b39e
basis measure implementation start
Henri-ColibrITD Feb 27, 2024
e68b109
solved the problem of nullable qubits numbers
Henri-ColibrITD Feb 28, 2024
21c1f61
details
Henri-ColibrITD Feb 28, 2024
bf2c777
removed circular dependencies
Henri-ColibrITD Feb 28, 2024
1fa0318
feat: mpqp to qasm
JulienCalistoTD Sep 12, 2024
b6b5136
doc: mpqp_to_qasm2
JulienCalistoTD Sep 18, 2024
bf9585c
chore: Files formated
github-actions[bot] Sep 18, 2024
f5db2e6
Merge branch 'dev' into feat-mpqp-to-qasm
JulienCalistoTD Sep 26, 2024
304e9d4
test: random circuit for mpqp_to_qasm
JulienCalistoTD Sep 26, 2024
d79082f
chore: Files formated
github-actions[bot] Sep 26, 2024
dae6b43
fix: add CustomGate and replace to_qasm2
JulienCalistoTD Sep 26, 2024
0fcfa52
chore: add Language QASM2 and QASM3
JulienCalistoTD Sep 30, 2024
d6da0d6
doc: refinements
Henri-ColibrITD Oct 2, 2024
0cb2b68
Merge branch 'feat-mpqp-to-qasm' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Oct 2, 2024
2dc4bb3
chore: add QASM2 to_other_language for instruction
JulienCalistoTD Oct 2, 2024
737b727
test: fix test_mpqp_to_qasm
JulienCalistoTD Oct 2, 2024
9da0f9e
chore: typechecks
JulienCalistoTD Oct 2, 2024
3e9eafc
chore: remove qcircuit to_qasm2 and 3
JulienCalistoTD Oct 2, 2024
576a8df
chore: Files formated
github-actions[bot] Oct 2, 2024
ba88279
Merge branch 'dev' into feat-mpqp-to-qasm
JulienCalistoTD Oct 21, 2024
7b6a4f8
Merge branch 'feat-mpqp-to-qasm' of https://github.com/ColibrITD-SAS/…
JulienCalistoTD Oct 21, 2024
67032f5
Merge remote-tracking branch 'origin/dev' into feat-custom-basis
hJaffaliColibritd Oct 21, 2024
168d420
chore: formatting
Henri-ColibrITD Oct 28, 2024
0666403
Merge branch 'feat-mpqp-to-qasm' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Oct 28, 2024
8693c41
chore: `if` denesting
Henri-ColibrITD Oct 29, 2024
a60fcaa
chore: update to_other_language, review basis condition
MoHermes Oct 29, 2024
d820162
fix: BasisMeasure class support custom basis
MoHermes Oct 29, 2024
8de5261
fix: handle custom basis in generate_job
MoHermes Oct 29, 2024
fdd86ae
fix: pass Breakpoint and ExpectationMeasure to QASM2
JulienCalistoTD Oct 29, 2024
17f3a87
fix: handle \n in circuit
JulienCalistoTD Oct 29, 2024
f0acef7
chore: details
Henri-ColibrITD Oct 30, 2024
b5abe8c
Merge branch 'dev' into feat-custom-basis
Henri-ColibrITD Oct 30, 2024
ee29c65
feat: basis are now dynamic
Henri-ColibrITD Oct 30, 2024
24e64f7
chore: specify custom symbols in basis state representations/printed …
MoHermes Oct 30, 2024
bb92906
Merge branch 'feat-custom-basis' of github.com:ColibrITD-SAS/mpqp int…
MoHermes Oct 30, 2024
6cf84cb
fix: problem with the Hadamard basis, WIP
Henri-ColibrITD Oct 30, 2024
9c1e273
Merge branch 'feat-custom-basis' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Oct 30, 2024
a46298f
fix: dynamic hadamard basis now works
Henri-ColibrITD Oct 30, 2024
5941511
fix: handle simplify BasisMeasure, add test, and chore
JulienCalistoTD Oct 29, 2024
690baee
merge
JulienCalistoTD Oct 30, 2024
982cf13
chore: type-checker
JulienCalistoTD Oct 30, 2024
c2ae312
fix: test failing because of new condition added in result.__str__
Henri-ColibrITD Oct 30, 2024
1703a72
test: to_other_language is implemented for qiskit
MoHermes Oct 30, 2024
78f9cae
chore: Files formated
github-actions[bot] Oct 30, 2024
550528d
fix: correct assignment of 'symbols'
MoHermes Oct 30, 2024
eca0925
Merge branch 'feat-custom-basis' of github.com:ColibrITD-SAS/mpqp int…
MoHermes Oct 30, 2024
ef89022
doc: update documentation for 'Basis' class methods
MoHermes Oct 31, 2024
1cf90d0
doc: update documentation for 'VariableSizeBasis' class
MoHermes Oct 31, 2024
4bc491d
chore: clean up tests, removing unneeded cases
MoHermes Oct 31, 2024
9a25608
test: add a test case for custom basis execution
MoHermes Oct 31, 2024
c5016e9
chore: enhance overall test readability
MoHermes Nov 4, 2024
3069965
chore: change self.parameter to k
JulienCalistoTD Nov 4, 2024
9df59e0
Merge branch 'dev' into feat-mpqp-to-qasm
JulienCalistoTD Nov 4, 2024
3910756
chore: Files formated
github-actions[bot] Nov 4, 2024
3b62931
Merge branch 'dev' into feat-mpqp-to-qasm
hJaffaliColibritd Nov 4, 2024
49e0c44
chore: deleted temp file
Henri-ColibrITD Nov 4, 2024
ee4d43a
Merge branch 'feat-custom-basis' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Nov 4, 2024
47f1f1e
test: custom base test made more generic to help making other
Henri-ColibrITD Nov 4, 2024
e44eb22
Merge branch 'dev' into feat-custom-basis
Henri-ColibrITD Nov 4, 2024
995f5c0
fix: merge issue
Henri-ColibrITD Nov 4, 2024
268226e
doc: example detail
Henri-ColibrITD Nov 4, 2024
dad8458
fix: repr
Henri-ColibrITD Nov 4, 2024
ccabd60
doc: add examples demonstrating basis with custom symbols
MoHermes Nov 5, 2024
701126a
test: run with different circuit and basis vectors
MoHermes Nov 5, 2024
aba71e2
chore: moving attributes and properties at the top of U class
hJaffaliColibritd Nov 5, 2024
d02b997
chore: format
JulienCalistoTD Nov 5, 2024
ab71090
fix: remove OpenQASMTranslationWarning for non user
JulienCalistoTD Nov 5, 2024
161e757
test: add custom gate test
JulienCalistoTD Nov 6, 2024
cee7d2b
fix: basis measure at the end of circuit + chore
JulienCalistoTD Nov 7, 2024
88c7b23
chore: remove qcircuit arg
JulienCalistoTD Nov 7, 2024
5a4d0c2
fix: hardcode test, + repr barrier and rotation gate
JulienCalistoTD Nov 7, 2024
60dcdc8
Merge remote-tracking branch 'origin/dev' into feat-custom-basis
hJaffaliColibritd Nov 8, 2024
b670855
add: test for CustomGate and U
JulienCalistoTD Nov 12, 2024
d470414
chore: Files formated
github-actions[bot] Nov 12, 2024
c26400f
test: basis tests on SV instead of samples
Henri-ColibrITD Nov 12, 2024
488f083
feat: custom basis doesn't need the target anymore
Henri-ColibrITD Nov 14, 2024
fed330e
fix: handle all basis
MoHermes Nov 14, 2024
05580d8
Merge branch 'feat-custom-basis' of github.com:ColibrITD-SAS/mpqp int…
MoHermes Nov 14, 2024
5eed848
fix: BasisMeasure with 0 shots on cirq now works properly
Henri-ColibrITD Nov 14, 2024
b622b91
Merge branch 'feat-custom-basis' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Nov 14, 2024
da6d0a0
fix: handle all basis, successful run on google-cirq
MoHermes Nov 14, 2024
2433cb9
Merge branch 'feat-custom-basis' of github.com:ColibrITD-SAS/mpqp int…
MoHermes Nov 14, 2024
0601282
doc: update doc of _update_targets_components
hJaffaliColibritd Nov 15, 2024
0a9f749
chore: Files formated
github-actions[bot] Nov 15, 2024
11d5a2a
test: adding some tests for statevector and sampling jobs with custom…
hJaffaliColibritd Nov 15, 2024
abd8fd3
chore: adding a fixme
hJaffaliColibritd Nov 15, 2024
a4860ef
chore: Files formated
github-actions[bot] Nov 15, 2024
bb17fef
fix: orthogonal basis detection for complex vectors
Henri-ColibrITD Nov 15, 2024
359c0c4
doc: forgotten word
Henri-ColibrITD Nov 15, 2024
b30b039
chore: 'Basis' class support basis_vectors_labels
MoHermes Nov 15, 2024
65d8c2f
Merge branch 'feat-custom-basis' of github.com:ColibrITD-SAS/mpqp int…
MoHermes Nov 15, 2024
f14861a
fix: trivial error
Henri-ColibrITD Nov 15, 2024
fbacf8c
Merge branch 'feat-custom-basis' of https://github.com/ColibrITD-SAS/…
Henri-ColibrITD Nov 15, 2024
2ac0bc3
fix: tests should now pass
Henri-ColibrITD Nov 15, 2024
f349667
Merge branch 'dev' into feat-custom-basis
Henri-ColibrITD Nov 15, 2024
45ec19c
test: test made more generic
Henri-ColibrITD Nov 15, 2024
5ceb7ba
chore: algebraic mistakes and other details
Henri-ColibrITD Nov 18, 2024
2929050
Merge branch 'feat-custom-basis' into feat-mpqp-to-qasm
JulienCalistoTD Nov 18, 2024
36a3add
chore: Files formated
github-actions[bot] Nov 18, 2024
dae3caa
chore: reverted wrong modifications
Henri-ColibrITD Nov 18, 2024
2acd489
doc: job.circuit clarification
Henri-ColibrITD Nov 18, 2024
ab443cd
fix: basisMeasure for qasm
JulienCalistoTD Nov 19, 2024
8292ad5
Merge branch 'feat-mpqp-to-qasm' of https://github.com/ColibrITD-SAS/…
JulienCalistoTD Nov 19, 2024
9151c66
chore: typecheck + clean
JulienCalistoTD Nov 19, 2024
9ef338e
Merge remote-tracking branch 'origin/feat-mpqp-to-qasm' into feat-cus…
Henri-ColibrITD Nov 19, 2024
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
274 changes: 123 additions & 151 deletions mpqp/core/circuit.py

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions mpqp/core/instruction/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ def to_other_language(
from qiskit.circuit.library import Barrier as QiskitBarrier

return QiskitBarrier(self.size)
elif language == Language.QASM2:
qubits = ",".join([f"q[{j}]" for j in self.targets])
return "barrier " + qubits + ";"

def __repr__(self):
return f"{type(self).__name__}({self.size})"
11 changes: 11 additions & 0 deletions mpqp/core/instruction/breakpoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations
from typing import Optional

from qiskit.circuit import Parameter

from mpqp.core.instruction import Instruction
from mpqp.core.languages import Language


class Breakpoint(Instruction):
Expand Down Expand Up @@ -30,3 +34,10 @@ def __repr__(self) -> str:
f"Breakpoint(targets={self.targets}, draw_circuit={self.draw_circuit},"
f" enabled={self.enabled}, label={self.label})"
)

def to_other_language(
self,
language: Language = Language.QISKIT,
qiskit_parameters: Optional[set["Parameter"]] = None,
) -> str:
raise NotImplementedError(f"Error: {language} is not supported")
46 changes: 42 additions & 4 deletions mpqp/core/instruction/gates/custom_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,49 @@ def to_other_language(
language: Language = Language.QISKIT,
qiskit_parameters: Optional[set["Parameter"]] = None,
):
from qiskit.quantum_info.operators import Operator as QiskitOperator
if language == Language.QISKIT:
from qiskit.quantum_info.operators import Operator as QiskitOperator

if qiskit_parameters is None:
qiskit_parameters = set()
return QiskitOperator(self.matrix)
elif language == Language.QASM2:
from mpqp.tools.circuit import replace_custom_gate
from qiskit import QuantumCircuit, qasm2

nb_qubits = max(self.targets) + 1

qiskit_circ = QuantumCircuit(nb_qubits)
instr = self.to_other_language(Language.QISKIT)
if TYPE_CHECKING:
from qiskit.quantum_info.operators import Operator as QiskitOperator

assert isinstance(instr, QiskitOperator)
qiskit_circ.unitary(
instr,
list(reversed(self.targets)), # dang qiskit qubits order
self.label,
)

if qiskit_parameters is None:
qiskit_parameters = set()
return QiskitOperator(self.matrix)
circuit, gphase = replace_custom_gate(qiskit_circ.data[0], nb_qubits)

qasm_str = qasm2.dumps(circuit)
qasm_lines = qasm_str.splitlines()

instructions_only = [
line
for line in qasm_lines
if not (
line.startswith("qreg")
or line.startswith("include")
or line.startswith("creg")
or line.startswith("OPENQASM")
)
]

return "\n".join(instructions_only), gphase
else:
raise NotImplementedError(f"Error: {language} is not supported")

def __repr__(self) -> str:
label = ", " + self.label if self.label else ""
Expand Down
Loading