Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/compas-compile-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ jobs:
echo "Running pytest suite..."
cd ${GITHUB_WORKSPACE}
export COMPAS_ROOT_DIR=${GITHUB_WORKSPACE}

if command -v jupyter-kernelspec &> /dev/null; then
echo "Available Jupyter kernels:"
jupyter-kernelspec list
fi

pytest --cov=compas_python_utils/ py_tests/ -m 'not webtest'
pytest --cov=compas_python_utils/ --cov-append py_tests/ -m webtest

echo "Test artifacts:"
ls py_tests/test_artifacts/ 2>/dev/null || echo "No test artifacts found"

coverage html
coverage-badge -o coverage_badge.svg -f
echo "All tests completed successfully!"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerhub-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
ghcr.io/${{ env.REPO_LC }}:${{ env.COMPAS_VERSION }}
ghcr.io/${{ env.REPO_LC }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: '\.(md|bib)$'

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ ENV COMPAS_ROOT_DIR /app/COMPAS
RUN cd src && make DOCKER_BUILD=1 -j $(nproc)

# Run COMPAS
# CMD [ "python", "src/pythonSubmitDefault.py" ]
# CMD [ "python", "src/pythonSubmitDefault.py" ]
12 changes: 6 additions & 6 deletions compas_matlab_utils/BSEDetailedOutput.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function BSEDetailedOutput(file)
% Carries out some basic analysis and makes plots for a single BSE run
%
% USAGE:
% USAGE:
% BSEDetailedOutput(file)
%
% INPUTS:
% file: name of detailed output file in COMPAS h5 format
%
% examples:
% examples:
% BSEDetailedOutput('~/Work/COMPAS/src/COMPAS_Output/Detailed_Output/BSE_Detailed_Output_0.h5')
%
%

time=h5read(file,'/Time');
MThistory=h5read(file,'/MT_History');
Expand Down Expand Up @@ -46,8 +46,8 @@ function BSEDetailedOutput(file)
' ', num2str(mass2(1)), ' ', num2str(type2(1)), ' ', num2str(a(1)), ' ', num2str(e(1))]);
for(i=2:length(time)),
if(rec(i)==4), %only print records at end of timestep
prev=find(rec(1:i-1)==4, 1, 'last'); %previous timestep index
if(MThistory(i)~=0),% & MThistory(i)~=MThistory(i-1)),
prev=find(rec(1:i-1)==4, 1, 'last'); %previous timestep index
if(MThistory(i)~=0),% & MThistory(i)~=MThistory(i-1)),
switch (MThistory(i)), case 1, MTstring='Stable MT from 1 TO 2'; case 2, MTstring='Stable MT from 2 TO 1';...
case 3, MTstring='CE from 1 to 2'; case 4, MTstring='CE from 2 to 1'; case 5, MTstring='CE Double Core'; ...
case 6, MTstring='CE merger'; end;
Expand All @@ -67,7 +67,7 @@ function BSEDetailedOutput(file)
end;
end;
if((type1(i)==13 || type1(i)==14) && (type2(i)==13 || type2(i)==14) ),
Msunkg=1.98892e30; c=299792458; G=6.67428e-11; Rsun = 695500000;
Msunkg=1.98892e30; c=299792458; G=6.67428e-11; Rsun = 695500000;
beta=64/5*G^3*mass1(i)*mass2(i)*(mass1(i)+mass2(i))*Msunkg^3/c^5; T0=(a(i)*Rsun)^4/4/beta;
Tdelay=T0*(1-e(i)^2).^(7/2).*(1+0.27*e(i)^10 + 0.33*e(i)^20 + 0.2*e(i)^1000)/3.15e7/1e6;
disp([num2str(time(i)+Tdelay), ' GW merger in ', num2str(Tdelay,'%.0f'), ' Myr ', num2str(mass1(i)), ' ', num2str(type1(i)),...
Expand Down
67 changes: 32 additions & 35 deletions compas_matlab_utils/ComparisonPlots.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function ComparisonPlots(filename1, name1, filename2, name2)
% Carries out some basic analysis and makes plots comparing two COMPAS runs
%
% USAGE:
% USAGE:
% ComparisonPlots(filename1, name1, filename2, name2)
%
% INPUTS:
% filename1: name of population synthesis input file 1 in COMPAS h5 format
% name1: name of data set 1 for plot legends
% filename2: name of population synthesis input file 2 in COMPAS h5 format
% name2: name of data set 2 for plot legends
%
% the last two arguments are optional; as single output can be plotted
%
% the last two arguments are optional; as single output can be plotted
% by running ComparisonPlots(filename1, name1)
%
% example:
% example:
% ComparisonPlots('~/Work/COMPASresults/runs/Zsolaralpha1-031803.h5', 'Default', ...
% '~/Work/COMPASresults/runs/Zsolar2stage-031803.h5', '2 stage')
%
% Warning: --switch-log must be used for all runs to be analysed
% It is recommended, but not required, to use the same random seed for the
% It is recommended, but not required, to use the same random seed for the
% runs being compared in order to compare individual binary evolution


Expand All @@ -31,7 +31,7 @@ function ComparisonPlots(filename1, name1, filename2, name2)
%Plot DCO mass distribution, BNS P-e distribution, chirp mass vs period
%at DCO formation, BH mass vs secondary core mass for 2->1 CEs leading
%to merging BBH formation
figure(1); clf(1); figure(2); clf(2); figure(3); clf(3); figure(4); clf(4); figure(5); clf(5);
figure(1); clf(1); figure(2); clf(2); figure(3); clf(3); figure(4); clf(4); figure(5); clf(5);
[BNS,NSBH,BBH,BNSCE,NSBHCE,BBHCE,CEBBH1]=DCOplot(filename1, name1, 1, 'r', 40);
fprintf('\nDCOs:\t\t#Merging DNS\t#Merging NSBH\t#Merging BBH\t%% BNS via CE\t%% NSBH via CE\t%% BBH via CE\t%% BBH via CE with BH primary\n');
fprintf('%s:\t%d\t\t%d\t\t%d\t\t%.0f\t\t%.0f\t\t%.0f\t\t%.0f\n', ...
Expand All @@ -42,16 +42,16 @@ function ComparisonPlots(filename1, name1, filename2, name2)
name2, BNS, NSBH, BBH, BNSCE/BNS*100, NSBHCE/NSBH*100, BBHCE/BBH*100, CEBBH1/BBH*100);
end;
figure(1), hold off; figure(2), hold off; figure(3), hold off; figure(4), hold off;
figure(1), set(gca,'FontSize',20), xlabel('$M_1$ (M$_\odot$)', 'Interpreter', 'latex'),
figure(1), set(gca,'FontSize',20), xlabel('$M_1$ (M$_\odot$)', 'Interpreter', 'latex'),
ylabel('$M_2$ (M$_\odot$)', 'Interpreter', 'latex'), title('Merging DCO masses'); legend;
figure(2), set(gca,'FontSize',20), xlabel('$\log_{10}$ (Orbital period/hr)', 'Interpreter', 'latex');
ylabel('Eccentricity'), title('DNS at formation'); legend;
figure(3), set(gca,'FontSize',20), xlabel('Chirp Mass (M$_\odot$)', 'Interpreter', 'latex'),
figure(3), set(gca,'FontSize',20), xlabel('Chirp Mass (M$_\odot$)', 'Interpreter', 'latex'),
ylabel('$\log_{10} (P_\mathrm{orb}/\mathrm{d})$', 'Interpreter', 'latex'), title('Merging BBH at formation'); legend;
figure(4), set(gca,'FontSize',20); xlabel('$M_1$ (M$_\odot$)', 'Interpreter', 'latex'),
figure(4), set(gca,'FontSize',20); xlabel('$M_1$ (M$_\odot$)', 'Interpreter', 'latex'),
ylabel('$M_{\textrm{core},2}$ (M$_\odot$)', 'Interpreter', 'latex'), title('CE from 2->1 en route to merging BBH'), legend;
figure(5), set(gca,'FontSize',20); xlabel('$q \equiv M_2/M_1$', 'Interpreter', 'latex'),
ylabel('CDF'), title('CDF of merging BBH'), legend;
figure(5), set(gca,'FontSize',20); xlabel('$q \equiv M_2/M_1$', 'Interpreter', 'latex'),
ylabel('CDF'), title('CDF of merging BBH'), legend;
fignumber=6;

%Plot BH HMXBs
Expand Down Expand Up @@ -85,7 +85,7 @@ function ComparisonPlots(filename1, name1, filename2, name2)
fprintf('%s:\t%d\t\t%d\t\t%f\n', name2, LMXBcount, NSLMXBcount, meanduration);
end;
figure(fignumber), hold off; set(gca,'FontSize', 20); legend; title('LMXB on first MT onto CO');
xlabel('Compact object mass (M$_\odot$)', 'Interpreter', 'latex'), ylabel('Companion mass (M$_\odot$)', 'Interpreter', 'latex');
xlabel('Compact object mass (M$_\odot$)', 'Interpreter', 'latex'), ylabel('Companion mass (M$_\odot$)', 'Interpreter', 'latex');
fignumber=fignumber+1;

%Plot DWDs (just as a sanity check)
Expand All @@ -95,7 +95,7 @@ function ComparisonPlots(filename1, name1, filename2, name2)
DWDplot(filename2, name2, fignumber, 'b', 'g', 5);
end;
figure(fignumber); hold off; axis([-3 5 -3 5]); set(gca,'FontSize',20); title('Double White Dwarfs'); legend;
xlabel('$log_{10}(M*a) [M_\odot * R_\odot]$ @ ZAMS', 'Interpreter', 'latex');
xlabel('$log_{10}(M*a) [M_\odot * R_\odot]$ @ ZAMS', 'Interpreter', 'latex');
ylabel('$log_{10}(M*a) [M_\odot * R_\odot]$ @ end', 'Interpreter', 'latex');


Expand Down Expand Up @@ -154,7 +154,7 @@ function ComparisonPlots(filename1, name1, filename2, name2)
fprintf('Of these, stripped by winds, no RLOF:\t%d\t\t%d\n', strippedwindscount1, strippedwindscount2);
fprintf('Of these, # stripped by RLOF:\t\t%d\t\t%d\n', strippedRLOFcount1, strippedRLOFcount2);
fprintf('Of these, previous CE:\t\t\t%d\t\t%d\n', strippedCEcount1, strippedCEcount2);
fprintf('Or double-core CE simultaneous with SN:\t%d\t\t%d\n', CESNcount1, CESNcount2);
fprintf('Or double-core CE simultaneous with SN:\t%d\t\t%d\n', CESNcount1, CESNcount2);
end;

end %end of ComparisonPlots
Expand Down Expand Up @@ -200,18 +200,18 @@ function ComparisonPlots(filename1, name1, filename2, name2)
%Merging DCO mass distribution
figure(fignumber), hold on;
scatter(mass1(mergingDCO & isCE & OKCE), mass2(mergingDCO & isCE & OKCE), point, ...
'filled', colour, 'DisplayName', ['CE, ', name]);
'filled', colour, 'DisplayName', ['CE, ', name]);
scatter(mass1(mergingDCO & ~isCE), mass2(mergingDCO & ~isCE), point, colour, 'DisplayName', ['Stable, ', name]);
%P-e of Galactic DNS at formation
P=2*pi*(a*AU).^(3/2)./sqrt(G*Msunkg*(mass1+mass2))/3600; %orbital period at DCO, in hours
figure(fignumber+1), hold on;
figure(fignumber+1), hold on;
scatter(log10(P(BNS & isCE & OKCE)), e(BNS & isCE & OKCE), point, 'filled', colour, ...
'DisplayName', ['CE, ', name]); hold on;
scatter(log10(P(BNS & ~isCE)), e(BNS & ~isCE), point, colour, 'DisplayName', ['Stable, ', name]);
%Chirp mass vs period at BBH formation
figure(fignumber+2), hold on;
scatter(chirpmass(mergingDCO & isCE & OKCE), log10(P(mergingDCO & isCE & OKCE)/24), point, ...
'filled', colour, 'DisplayName', ['CE, ', name]);
'filled', colour, 'DisplayName', ['CE, ', name]);
scatter(chirpmass(mergingDCO & ~isCE), log10(P(mergingDCO & ~isCE)/24), point, colour, 'DisplayName', ['Stable, ', name]);
%Masses at the time of CE
figure(fignumber+3), hold on;
Expand Down Expand Up @@ -241,11 +241,11 @@ function HMXBplot(file, name, fignumberHMXB, colour, point)
%if this is zero (no such systems), can ignore this possibility, focus on the other one
if(sum(relevantbinaryFrom1)>0) fprintf('Number of HMXBs with second-born BH is non-zero (%d), please check\n', sum(relevantbinaryFrom1)); end;
relevantbinaryFrom2=(isinRLOF2RLOF & ~wasinRLOF1RLOF & ~wasinRLOF2RLOF & star2RLOF==1 & M2RLOF>15 & star1RLOF==14);
MBH=[M1RLOF(relevantbinaryFrom2); M2RLOF(relevantbinaryFrom1)];
MBH=[M1RLOF(relevantbinaryFrom2); M2RLOF(relevantbinaryFrom1)];
MO=[M2RLOF(relevantbinaryFrom2); M1RLOF(relevantbinaryFrom1)];
%this misses binaries in which the companion overflows its RL shortly after
%evolving onto the HG;
%Now check the binaries at the time of the switch onto the HG, are they
%this misses binaries in which the companion overflows its RL shortly after
%evolving onto the HG;
%Now check the binaries at the time of the switch onto the HG, are they
%at least 80% RL filling at that point, if so, include them
M1Switch=h5read(file,'/BSE_Switch_Log/Mass(1)');
M2Switch=h5read(file,'/BSE_Switch_Log/Mass(2)');
Expand Down Expand Up @@ -283,9 +283,9 @@ function BeXRBplot(file, name, fignumberBeXRB, colour, point)
seedCE=h5read(file,'/BSE_Common_Envelopes/SEED');
timeCE=h5read(file,'/BSE_Common_Envelopes/Time');
[experiencedRLOF,indexRLOF]=ismember(seedSN,seedRLOF);
precededbyRLOF=false(size(indexRLOF));
precededbyRLOF=false(size(indexRLOF));
for(i=1:length(indexRLOF)), if(experiencedRLOF(i)), precededbyRLOF(i)=(timeRLOF(indexRLOF(i))<timeSN(i)); end; end;
[isCE,indexCE]=ismember(seedSN,seedCE);
[isCE,indexCE]=ismember(seedSN,seedCE);
for(i=1:length(isCE)), if(isCE(i)), isCE(i)=(timeCE(indexCE(i)) < timeSN(i)); end; end;
relevantbinary=starSNSN==13 & starCPSN==1 & MCPSN>3 & ~unboundSN & experiencedRLOF & precededbyRLOF; %haven't checked direction of RLOF
figure(fignumberBeXRB), scatter(MCPSN(relevantbinary & isCE), timeSN(relevantbinary & isCE), ...
Expand Down Expand Up @@ -326,11 +326,11 @@ function BeXRBplot(file, name, fignumberBeXRB, colour, point)
duration=timeRLOF(indexlistlast)-timeRLOF(indexlist);
meanduration=mean(duration);
[isCE,CEIndex]=ismember(uniqueseeds,seedCE); %doesn't check if CE happened before or after
precededbyCE=false(size(indexlist));
precededbyCE=false(size(indexlist));
for(i=1:length(indexlist)), if(isCE(i)), precededbyCE(i)=(timeCE(CEIndex(i)) < timeRLOF(indexlist(i))); end; end;
figure(fignumberLMXB), hold on;
scatter(MCO(precededbyCE), Mcomp(precededbyCE), point, 'filled', colour, 'DisplayName', ['CE, ', name]);
scatter(MCO(~precededbyCE), Mcomp(~precededbyCE), point, colour, 'DisplayName', ['Stable, ', name]);
scatter(MCO(~precededbyCE), Mcomp(~precededbyCE), point, colour, 'DisplayName', ['Stable, ', name]);
end %end of LMXBplot


Expand Down Expand Up @@ -386,18 +386,18 @@ function DWDplot(file, name, fignumberDWD, colourNMT, colourMT, point)
seedCE=h5read(file,'/BSE_Common_Envelopes/SEED');
timeCE=h5read(file,'/BSE_Common_Envelopes/Time');
seedAll=h5read(file, '/BSE_System_Parameters/SEED');
[isCE,indexCE]=ismember(seedSN,seedCE);
[isCE,indexCE]=ismember(seedSN,seedCE);
[isCE,lastindexCE]=ismember(seedSN,seedCE,'legacy'); %last index of CE seed matching given SN seed (for binaries with 2+ CE events)
simultaneouswithCE = false(size(indexCE));
simultaneouswithCE(isCE) = (timeCE(indexCE(isCE)) == timeSN(isCE)) | (timeCE(lastindexCE(isCE)) == timeSN(isCE));
simultaneouswithCE = false(size(indexCE));
simultaneouswithCE(isCE) = (timeCE(indexCE(isCE)) == timeSN(isCE)) | (timeCE(lastindexCE(isCE)) == timeSN(isCE));
%Note: could (very rarely) miss a coincidence if >2 CE events and only intermediate CE matches SN in time
precedingCE = false(size(indexCE));
precedingCE(isCE) = (timeCE(indexCE(isCE)) < timeSN(isCE));
precedingCE = false(size(indexCE));
precedingCE(isCE) = (timeCE(indexCE(isCE)) < timeSN(isCE));
[experiencedRLOF,indexRLOF]=ismember(seedSN,seedRLOF);
[experiencedRLOF,lastindexRLOF]=ismember(seedSN,seedRLOF, 'legacy');
simultaneouswithRLOF = false(size(indexRLOF));
simultaneouswithRLOF = false(size(indexRLOF));
simultaneouswithRLOF(experiencedRLOF) = (timeRLOF(indexRLOF(experiencedRLOF)) == timeSN(experiencedRLOF) ...
| timeRLOF(lastindexRLOF(experiencedRLOF)) == timeSN(experiencedRLOF));
| timeRLOF(lastindexRLOF(experiencedRLOF)) == timeSN(experiencedRLOF));
%Note: could miss a coincidence if >2 RLOF events and only intermediate RLOF matches SN in time
binariescount=length(seedAll);
SNcount=length(seedSN);
Expand All @@ -422,6 +422,3 @@ function DWDplot(file, name, fignumberDWD, colourNMT, colourMT, point)
strippedCEcount=sum(IsStrippedSN & HadRLOFSN & precedingCE & SNtypeSN~=2 & SNtypeSN~=32);
CESNcount=sum(IsStrippedSN & HadRLOFSN & simultaneouswithCE & SNtypeSN~=2 & SNtypeSN~=32);
end %end of SNstats



Loading