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

Draft
wants to merge 27 commits into
base: dev
Choose a base branch
from
Draft

Feat db jobs and results #118

wants to merge 27 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"

@@ -165,7 +164,17 @@ def __init__(
self.add(deepcopy(data))

def __eq__(self, value: object) -> bool:
return dumps(self) == dumps(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you provide me with an example where this didn't work (for my culture)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem came from somewhere else but I had kept the change. I discard the change and all the tests passed.

Copy link
Contributor

Choose a reason for hiding this comment

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

the change was not discarded though ?

@@ -198,7 +209,7 @@ def set_size(self, nb_qubits: int):
pass

def __repr__(self) -> str:
return f"{type(self).__name__}()"
return f"{type(self).__name__}({self.nb_qubits})"
Copy link
Contributor

Choose a reason for hiding this comment

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

we should check if the basis is dynamic or not and put or not the number of
qubits depending on that

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

Copy link
Contributor

Choose a reason for hiding this comment

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

did you just revert the change ? I don't see the modif anymore ?



@ensure_db
def fetch_results_with_result(result: Result | BatchResult | list[Result]):
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 the difference with fetch_results_with_result_and_job ?

Copy link
Contributor

Choose a reason for hiding this comment

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

removed ?

>>> jobs = get_all_jobs()
>>> for job in jobs:
... print(job)
Job(JobType.SAMPLE, QCircuit([H(0), CNOT(0, 1), BasisMeasure([0, 1], c_targets=[0, 1], basis=ComputationalBasis(2))], nb_qubits=2, nb_cbits=2, label="H CX BM"), IBMDevice.AER_SIMULATOR, BasisMeasure([0, 1], c_targets=[0, 1], basis=ComputationalBasis(2)))
Copy link
Contributor

Choose a reason for hiding this comment

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

ellipsis

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

>>> jobs = get_jobs_with_id([1, 2, 3])
>>> for job in jobs:
... print(job)
Job(JobType.SAMPLE, QCircuit([H(0), CNOT(0, 1), BasisMeasure([0, 1], c_targets=[0, 1], basis=ComputationalBasis(2))], nb_qubits=2, nb_cbits=2, label="H CX BM"), IBMDevice.AER_SIMULATOR, BasisMeasure([0, 1], c_targets=[0, 1], basis=ComputationalBasis(2)))
Copy link
Contributor

Choose a reason for hiding this comment

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

ellipsis

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

job: Job(s) to search for.

Returns:
Matching job(s).
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 the matching criterion ?

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

Copy link
Contributor

Choose a reason for hiding this comment

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

did you check the doc generates properly here ?

@@ -19,4 +19,7 @@ def test_basis_measure_init_fails_duplicate_c_targets():
def test_basis_measure_repr():
measure = BasisMeasure([0, 1], shots=1025)
representation = repr(measure)
assert representation == "BasisMeasure([0, 1], shots=1025)"
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 that's wrong

Copy link
Collaborator Author

@JulienCalistoTD JulienCalistoTD Dec 18, 2024

Choose a reason for hiding this comment

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

Outdated, changes discarded.

Copy link
Contributor

Choose a reason for hiding this comment

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

are they ?

@@ -189,7 +189,7 @@ def test_count(circuit: QCircuit, filter: tuple[type[Gate]], count: int):
),
]
),
"[BasisMeasure([0, 1], shots=1000), ExpectationMeasure("
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong again

Copy link
Collaborator Author

@JulienCalistoTD JulienCalistoTD Dec 18, 2024

Choose a reason for hiding this comment

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

Outdated, changes discarded.

Copy link
Contributor

Choose a reason for hiding this comment

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

are they ?

@@ -49,8 +49,8 @@
H(0),
H(1),
CNOT(0, 1),
BasisMeasure([0]),
BasisMeasure([1]),
BasisMeasure([0], [0]),
Copy link
Contributor

Choose a reason for hiding this comment

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

wonrg

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, because we are checking the BasisMeasure repr but as it is not associated with a circuit, is not dynamic. So we need to specify the c_targets.

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.

see comments

@hJaffaliColibritd hJaffaliColibritd self-requested a review December 18, 2024 13:04
>>> jobs = fetch_jobs_with_job(job)
>>> for job in jobs:
... print("job_id:", job['id'])

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't the example be more speaking with actual results printed ?

Copy link
Contributor

@hJaffaliColibritd hJaffaliColibritd left a comment

Choose a reason for hiding this comment

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

I stopped the review at expectation_value.py

@@ -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 agree, we can rename it "Result management"

def to_dict(self) -> dict[str, int | str | list[str] | float | None]:
"""
Serialize the quantum circuit to a dictionary.
Returns:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can include a small example for this method in the docstring?

@@ -104,7 +104,7 @@ def __str__(self) -> str:
from mpqp.core.circuit import QCircuit

connection = self.connections()
circuit_size = max(connection) + 1 if connection else 1
circuit_size = max(connection) + 1 if len(connection) == 0 else 1
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean if len(connection) != 0 here ? Otherwise it doesn't make sense

@@ -163,6 +163,17 @@ def to_computational(self):
]
)

def __eq__(self, other: object) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you take into account here that we can call __eq__ to compare a Basis and VariableSizeBasis ?

@JulienCalistoTD JulienCalistoTD marked this pull request as draft February 18, 2025 10:42
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