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 db jobs and results #118

Open
wants to merge 47 commits into
base: dev
Choose a base branch
from
Open

Feat db jobs and results #118

wants to merge 47 commits into from

Conversation

JulienCalistoTD
Copy link
Collaborator

No description provided.

@JulienCalistoTD JulienCalistoTD marked this pull request as draft November 27, 2024 16:09
@JulienCalistoTD JulienCalistoTD marked this pull request as ready for review December 4, 2024 13:53
@@ -0,0 +1,939 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this file differently: the goal is not to have a DB per say, but to be able to save and load results. I have to checkout this file, but this could even be part of another notebook

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand by that, with the Result integration, I would even have just a small mention in one of the first notebooks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we can rename it "Result management"

Copy link
Collaborator Author

@JulienCalistoTD JulienCalistoTD Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to "7_result_local_storage" 00c0a42

def __eq__(self, value: object) -> bool:
if not isinstance(value, self.__class__):
return False
if self.to_dict() != value.to_dict():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: 8f058e0

dict: A dictionary representation of the gate.
"""
result = {}
for attr_name in dir(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be improved and factorized but as we discussed this can be done in another branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Comment on lines +116 to +131
if isinstance(val1, list) and isinstance(val2, list):
try:
from sympy import N

val1_numeric = np.array(
[[N(el) for el in row] for row in val1], dtype=complex
)
val2_numeric = np.array(
[[N(el) for el in row] for row in val2], dtype=complex
)
if not np.allclose(val1_numeric, val2_numeric, atol=1e-7):
return False
except:
if val1 != val2:
return False
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be just a matrix_eq ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it can wait to be factored into another branch.

@@ -207,4 +259,4 @@ def caster(v: Expr | Complex) -> Expr | Complex:
)

def __repr__(self) -> str:
return f"UnitaryMatrix({one_lined_repr(getattr(self, 'matrix', ''))})"
return f"UnitaryMatrix({one_lined_repr(self.matrix)})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we initially did this because not all gate definitions had the matrix attribute, but I think I remember it is now the case so you change should be fine. Did you make sure it was ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes a UnitaryMatrix always have a matrix

args.append(f"symbols={self.symbols}")
if self.basis_vectors_labels is not None:
args.append(f"basis_vectors_labels={self.basis_vectors_labels}")
return f"{type(self).__name__}({', '.join(args)})"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loc seem to be the same for all reps, it could be factorized, on the other hand, since it's a single line, it would probably not improve that much the clarity or efficiency of the code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is not the factorizer code, but I think it's better for understanding

else:
coef = f"{self.coef}"
return f"{coef}*{'@'.join(map(str,self.atoms))}"
coef = f"{self.coef}*" if coef != 0 else ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be 1 instead of 0 ? (0 would mean I don't display the string at all or I just display "0", while 1 may mean I skip the coeff)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 5f36f46

@@ -123,7 +123,7 @@ def remove_results_with_results_db(results: Optional[list[DictDB] | DictDB]):

Example:
>>> results = fetch_results_with_id(1)
>>> remove_results_with_results_db(results)
>>> remove_results_with_results_local_storage(results)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I didn't mind the dbin the function names, I just didn't really want to have it in the doc, but it's fine like this too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I am not convinced about putting different names everywhere. I think it's better to use only one

@@ -240,7 +256,7 @@ def __init__(
self.check_dimension()

def check_dimension(self):
if 0 < len(self.targets) < self.dimension:
if len(self.targets) != 0 and len(self.targets) < self.dimension:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse 5f36f46

rng.uniform(0, 2 * np.pi),
rng.uniform(0, 2 * np.pi),
rng.uniform(0, 2 * np.pi),
np.round(rng.uniform(0, 2 * np.pi), 5),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we round ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for simplification in test

),
],
)
def test_cbits_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_cbits_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int):
def test_cbits_undersized_static_circuit(circuit: QCircuit, expected_cbits: int):

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 5f36f46

),
],
)
def test_cbits_dynamic_to_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_cbits_dynamic_to_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int):
def test_cbits_dynamic_toggled_off_undersized_circuit(circuit: QCircuit, expected_cbits: int):

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 5f36f46

from mpqp.all import *


def generate_qcircuits():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

espèce de bourin x)x)x)x)x)

if db_version != DATABASE_VERSION:
raise RuntimeError(
f"Database version {db_version} is outdated. Expected {DATABASE_VERSION}. "
"Please upgrade the database schema."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this done ? a user friendly way to migrate should be provided

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have only one version of db_version, so we don't need it, and I don't want to delay this branches.

@@ -78,7 +78,7 @@ def running_observable_job_ibm_simulated_devices(
assert True


if "--long-local" in sys.argv:
if "--long-local" in sys.argv or "--long" in sys.argv:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this long thing about ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we forget to add this, we want to run this test on both --long

return self.to_dict() == other.to_dict()

def to_dict(self):
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how manual of you ^^

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can wait to be factored.

Copy link
Contributor

@Henri-ColibrITD Henri-ColibrITD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc to polish, mostly to make sure it generates fine, and to include in the official doc + notebook to polish. A few remarks. Apart from that the coding part of the PR is almost done

Henri-ColibrITD and others added 10 commits March 11, 2025 15:30
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants